From ff31e6ab8f82bdad7b0f8a71fd5115ecde9bee16 Mon Sep 17 00:00:00 2001 From: Joshua Coles Date: Thu, 1 Aug 2024 23:03:11 +0100 Subject: [PATCH] Make simple docker containers from the build artefact --- .github/workflows/build.yml | 21 +++++++++++++++++++++ Dockerfile | 14 ++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 Dockerfile diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b641e74..d9b4eac 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -70,6 +70,27 @@ jobs: target/release/${{ github.event.repository.name }} target/aarch64-unknown-linux-gnu/release/${{ github.event.repository.name }} + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push multi-arch Docker image + uses: docker/build-push-action@v4 + with: + context: . + file: ./Dockerfile + platforms: linux/amd64,linux/arm64 + push: true + tags: git.joshuacoles.me/${{ github.repository }}:latest,git.joshuacoles.me/${{ github.repository }}:${{ github.sha }} + - uses: robiningelbrecht/ntfy-action@v1.0.0 name: Notify via ntfy.sh if: always() diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7356d67 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM --platform=$BUILDPLATFORM debian:buster-slim AS builder +ARG TARGETPLATFORM +WORKDIR /app +COPY . . +RUN case "$TARGETPLATFORM" in \ + "linux/amd64") BINARY_PATH="target/release/toggl-bridge" ;; \ + "linux/arm64") BINARY_PATH="target/aarch64-unknown-linux-gnu/release/toggl-bridge" ;; \ + *) exit 1 ;; \ + esac && \ + mv "$BINARY_PATH" /usr/local/bin/toggl-bridge + +FROM --platform=$TARGETPLATFORM debian:buster-slim +COPY --from=builder /usr/local/bin/toggl-bridge /usr/local/bin/ +CMD ["toggl-bridge"]