From 27d3dec1eb13d6eeb90f096b9c7ef1c2fd3a11d1 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 | 12 +++++++++--- Dockerfile | 9 +++++++++ Justfile | 15 ++++++++++----- 3 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 Dockerfile diff --git a/.github/workflows/publish-docker.yml b/.github/workflows/publish-docker.yml index d6d70e5..ea6ac2d 100644 --- a/.github/workflows/publish-docker.yml +++ b/.github/workflows/publish-docker.yml @@ -24,13 +24,19 @@ jobs: uses: actions/checkout@v4 - name: Setup Rust Toolchain - uses: dtolnay/rust-toolchain@master + uses: dtolnay/rust-toolchain@stable with: 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..a9309bb 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 --target {{target_release}} --release -p server # 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}}/release/server ./tmp/server + chmod +x ./tmp/server + docker build -t "commune:{{commit_sha}}-{{target_release}}" --build-arg ARCH=arm64v8/ .