From 7915ba628456c5eee20c84c6a259a5e9ac13486c Mon Sep 17 00:00:00 2001 From: AlexMikhalev Date: Mon, 2 Oct 2023 18:36:23 +0100 Subject: [PATCH] Example of Earthly, needs fixes for node build paths Signed-off-by: AlexMikhalev --- Earthfile | 52 +++++++++++++++++++++++++++++++++++++++++++++++ browser/Earthfile | 22 ++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 Earthfile create mode 100644 browser/Earthfile diff --git a/Earthfile b/Earthfile new file mode 100644 index 000000000..7065b1513 --- /dev/null +++ b/Earthfile @@ -0,0 +1,52 @@ +VERSION 0.7 +PROJECT applied-knowledge-systems/atomic-server +# You can compile front end separately and copy dist folder +# IMPORT ./browser AS browser +FROM rust:latest +WORKDIR /code + +main-pipeline: + PIPELINE --push + TRIGGER push main + TRIGGER pr main + ARG tag=latest + BUILD +build --tag=$tag + +deps: + RUN curl -fsSL https://bun.sh/install | bash + RUN /root/.bun/bin/bun install -y pnpm + # COPY . . + COPY --dir server lib cli desktop Cargo.lock Cargo.toml . + # RUN mkdir src + # RUN touch src/main.rs # adding main.rs stub so cargo fetch works to prepare the cache + RUN cargo fetch + +test: + FROM +deps + RUN cargo test + +build: + FROM +deps + RUN rustup target add x86_64-unknown-linux-musl + RUN apt update && apt install -y musl-tools musl-dev + RUN update-ca-certificates + WORKDIR /app + # FIXME: Joep you need to fix this line and modify Earthfile inside browser + # COPY browser+build/dist ./public + COPY --dir server lib cli desktop Cargo.lock Cargo.toml . + RUN cargo build --release --bin atomic-server --config net.git-fetch-with-cli=true --target x86_64-unknown-linux-musl + RUN strip -s /app/target/x86_64-unknown-linux-musl/release/atomic-server + SAVE ARTIFACT /app/target/x86_64-unknown-linux-musl/release/atomic-server + +docker: + # We only need a small runtime for this step, but make sure glibc is installed + FROM scratch + COPY --chmod=0755 +build/atomic-server /atomic-server-bin + # For a complete list of possible ENV vars or available flags, run with `--help` + ENV ATOMIC_STORE_PATH="/atomic-storage/db" + ENV ATOMIC_CONFIG_PATH="/atomic-storage/config.toml" + ENV ATOMIC_PORT="80" + EXPOSE 80 + VOLUME /atomic-storage + ENTRYPOINT ["/atomic-server-bin"] + SAVE IMAGE --push ghcr.io/applied-knowledge-systems/atomic-server:edge diff --git a/browser/Earthfile b/browser/Earthfile new file mode 100644 index 000000000..1e7313b31 --- /dev/null +++ b/browser/Earthfile @@ -0,0 +1,22 @@ +VERSION 0.7 +PROJECT applied-knowledge-systems/atomic-server +FROM node:latest +WORKDIR browser + +main-pipeline: + PIPELINE --push + TRIGGER push main + TRIGGER pr main + ARG tag=latest + BUILD +build --tag=$tag + +deps: + RUN curl -f https://get.pnpm.io/v6.14.js | node - add --global pnpm + COPY . . + RUN pnpm install --no-frozen-lockfile + SAVE ARTIFACT node_modules /node_modules + +build: + FROM +deps + RUN pnpm run build + SAVE ARTIFACT dist /dist AS LOCAL dist \ No newline at end of file