diff --git a/.github/workflows/build_pr_image.yml b/.github/workflows/build_pr_image.yml index 10afd88..352cbfa 100644 --- a/.github/workflows/build_pr_image.yml +++ b/.github/workflows/build_pr_image.yml @@ -14,8 +14,20 @@ jobs: with: username: ${{ secrets.DOCKER_USER }} password: ${{ secrets.DOCKER_TOKEN }} - - name: build image - run: docker build -t afrima/anki-sync-server:24.11-rc -t afrima/anki-sync-server:latest-rc --build-arg NOW="$(date -u +"%Y-%m-%dT%H:%M:%SZ")" . + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Get Current Date + id: get_date + run: echo "::set-output name=now::$(date -u +"%Y-%m-%dT%H:%M:%SZ")" + - name: Build and push + uses: docker/build-push-action@v6 + with: + platforms: linux/amd64, linux/arm64 + tags: afrima/anki-sync-server:24.11-rc, afrima/anki-sync-server:latest-rc + build-args: | + NOW=${{ steps.get_date.outputs.now }} - name: Wait for healthchecks run: docker run -e SYNC_USER1=test_user_name:test_user_password -d afrima/anki-sync-server:latest-rc | timeout 60s sh -c 'until docker ps | grep afrima/anki-sync-server:latest-rc | grep -q healthy; do echo "Waiting for container to be healthy..."; sleep 2; done' - name: push image diff --git a/.github/workflows/build_release-image.yml b/.github/workflows/build_release-image.yml index d743931..40f8948 100644 --- a/.github/workflows/build_release-image.yml +++ b/.github/workflows/build_release-image.yml @@ -11,13 +11,26 @@ jobs: runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v4 - - name: Login to Docker Hub + - name: Log in to Docker Hub uses: docker/login-action@v3 with: username: ${{ secrets.DOCKER_USER }} password: ${{ secrets.DOCKER_TOKEN }} - - name: build image - run: docker build -t afrima/anki-sync-server:24.11 -t afrima/anki-sync-server:latest --build-arg NOW="$(date -u +"%Y-%m-%dT%H:%M:%SZ")" . + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Get Current Date + id: get_date + run: echo "::set-output name=now::$(date -u +"%Y-%m-%dT%H:%M:%SZ")" + - name: Build and push + uses: docker/build-push-action@v6 + with: + platforms: linux/amd64, linux/arm64 + push: false + tags: afrima/anki-sync-server:24.11, afrima/anki-sync-server:latest + build-args: | + NOW=${{ steps.get_date.outputs.now }} - name: Wait for healthchecks run: docker run -e SYNC_USER1=test_user_name:test_user_password -d afrima/anki-sync-server:latest | timeout 60s sh -c 'until docker ps | grep afrima/anki-sync-server:latest | grep -q healthy; do echo "Waiting for container to be healthy..."; sleep 2; done' - name: push image diff --git a/Dockerfile b/Dockerfile index 38af0be..d367562 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,19 @@ FROM rust:1.84.0 as build-env WORKDIR /app -RUN apt update \ +ARG TARGETPLATFORM +ARG TARGETARCH + +RUN echo "Building for TARGETPLATFORM: $TARGETPLATFORM, TARGETARCH: $TARGETARCH" \ + && if [ "$TARGETARCH" = "amd64" ]; then RUST_TARGET="x86_64-unknown-linux-musl"; \ + elif [ "$TARGETARCH" = "arm64" ]; then RUST_TARGET="aarch64-unknown-linux-musl"; \ + else echo "Unsupported architecture: $TARGETARCH" && exit 1; fi \ + && echo "Using RUST_TARGET: $RUST_TARGET" \ + && apt update \ && apt upgrade -y \ && apt install -y protobuf-compiler libprotobuf-dev musl-tools \ - && rustup target add x86_64-unknown-linux-musl - -RUN cargo install --git https://github.com/ankitects/anki.git --tag 24.11 anki-sync-server --target x86_64-unknown-linux-musl + && rustup target add $RUST_TARGET \ + && cargo install --git https://github.com/ankitects/anki.git --tag 24.11 anki-sync-server --target $RUST_TARGET FROM gcr.io/distroless/static-debian12:nonroot@sha256:6ec5aa99dc335666e79dc64e4a6c8b89c33a543a1967f20d360922a80dd21f02