Skip to content

Commit

Permalink
feat: build multi arch
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieu-keller committed Jan 15, 2025
1 parent a009105 commit 6d8f2e4
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
16 changes: 14 additions & 2 deletions .github/workflows/build_pr_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 16 additions & 3 deletions .github/workflows/build_release-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 12 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
FROM rust:1.84.0 as build-env
FROM --platform=$BUILDPLATFORM rust:1.84.0 as build-env
WORKDIR /app

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"

RUN apt update \
&& apt upgrade -y \
&& apt install -y protobuf-compiler libprotobuf-dev musl-tools \
&& rustup target add x86_64-unknown-linux-musl
&& rustup target add $RUST_TARGET

RUN cargo install --git https://github.com/ankitects/anki.git --tag 24.11 anki-sync-server --target x86_64-unknown-linux-musl
RUN 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
Expand Down

0 comments on commit 6d8f2e4

Please sign in to comment.