From 2ece80c10d232907647c1796bfe77d145763ea47 Mon Sep 17 00:00:00 2001 From: Esteban Borai Date: Sun, 4 Feb 2024 14:09:19 -0300 Subject: [PATCH] chore(docker): publish docker image --- .github/workflows/publish-docker.yml | 53 ++++++++++++++++++++++++++++ Dockerfile | 9 +++++ Justfile | 14 ++++++++ 3 files changed, 76 insertions(+) create mode 100644 .github/workflows/publish-docker.yml create mode 100644 Dockerfile diff --git a/.github/workflows/publish-docker.yml b/.github/workflows/publish-docker.yml new file mode 100644 index 0000000..b3d3e51 --- /dev/null +++ b/.github/workflows/publish-docker.yml @@ -0,0 +1,53 @@ +name: Publish Docker Image + +on: + push: + +concurrency: + group: "${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}" + cancel-in-progress: true + +env: + IMAGE_NAME: commune + GHCR_REGISTRY: ghcr.io/commune-os + OPENSSL_LIB_DIR: "/usr/lib/x86_64-linux-gnu" + OPENSSL_INCLUDE_DIR: "/usr/include/openssl" + +jobs: + publish_image: + name: Publish image + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + id-token: write + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Rust Toolchain + uses: dtolnay/rust-toolchain@stable + with: + toolchain: stable + targets: x86_64-unknown-linux-musl + + - name: Setup Rust Cache + uses: Swatinem/rust-cache@v2 + + - name: Setup Rust Target + run: rustup target add x86_64-unknown-linux-musl + + - name: Install Build Dependencies + run: sudo apt install librust-openssl-dev + + - 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 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 e8482e7..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 @@ -60,3 +63,14 @@ clear: stop # Runs all the tests from the `test` package. Optionally runs a single one if name pattern is provided e2e *args='': cargo test --package test -- --nocapture --test-threads=1 $1 + +# Builds the Server binary used in the Docker Image +docker_build_server: + cargo zigbuild --target {{target_release}} --release -p server + +# Builds the Docker image for the backend +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/ .