From 9974897db6c936fb4f68241146feaee4eaf39aa7 Mon Sep 17 00:00:00 2001 From: Esteban Borai Date: Sun, 4 Feb 2024 14:20:23 -0300 Subject: [PATCH] feat: use zigbuild --- .github/workflows/publish-docker.yml | 10 ++++++++-- Dockerfile | 9 +++++++++ Justfile | 15 ++++++++++----- 3 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 Dockerfile diff --git a/.github/workflows/publish-docker.yml b/.github/workflows/publish-docker.yml index d6d70e5..b59f9ff 100644 --- a/.github/workflows/publish-docker.yml +++ b/.github/workflows/publish-docker.yml @@ -29,8 +29,14 @@ jobs: toolchain: stable targets: x86_64-unknown-linux-musl + - name: Setup Zig + uses: goto-bus-stop/setup-zig@v2.2.0 + + - name: Install zigbuild + run: cargo install cargo-zigbuild + - name: Install Just uses: extractions/setup-just@v1 - - name: Build Server - run: just build_server + - name: Build Image + run: just docker_build_image diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ccffcd6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +ARG ARCH= + +FROM ${ARCH}alpine:3 + +COPY server /opt/commune + +WORKDIR app + +ENTRYPOINT ["/opt/commune"] diff --git a/Justfile b/Justfile index 41647fa..6111b1a 100644 --- a/Justfile +++ b/Justfile @@ -1,5 +1,8 @@ set positional-arguments +commit_sha := `git rev-parse --verify HEAD` +target_release := "x86_64-unknown-linux-musl" + # Lists all available commands default: just --list @@ -62,10 +65,12 @@ e2e *args='': cargo test --package test -- --nocapture --test-threads=1 $1 # Builds the Server binary used in the Docker Image -build_server: - cargo build --release -p server --target x86_64-unknown-linux-musl - ls ./target/x86_64-unknown-linux-musl/release +docker_build_server: + cargo zigbuild --release -p server --target {{target_release}} # Builds the Docker image for the backend -build_image *args='latest': build_server - docker build -t "commune:$1-aarch64-unknown-linux-musl" . +docker_build_image: docker_build_server + mkdir tmp/ + cp ./target/{{target_release}}/server ./tmp/server + chmod +x ./tmp/server + docker build -t "commune:{{commit_sha}}-{{target_release}}" --build-arg ARCH=arm64v8/ .