From 377cb3e0e9c9421d9bc8e1e15ce81b2483628428 Mon Sep 17 00:00:00 2001 From: Kaan Yagci <9104546+kaanyagci@users.noreply.github.com> Date: Thu, 2 May 2024 17:22:32 +0200 Subject: [PATCH] chore(gha): add build & publish docker image workflow (#8) * chore(gha): add build docker image workflow Signed-off-by: Kaan Yagci * drop: temporary remove the path constraints Signed-off-by: Kaan Yagci * refactor(gha): rename GHA workflow Signed-off-by: Kaan Yagci * fix(gha): invalid tag Signed-off-by: Kaan Yagci * chore: update Dockerfile with DEBIAN_TAG Signed-off-by: Kaan Yagci * chore(gha): update build workflow Signed-off-by: Kaan Yagci * fix(gha): invalid image tag issue Signed-off-by: Kaan Yagci --------- Signed-off-by: Kaan Yagci --- .github/workflows/build.yaml | 57 ++++++++++++++++++++++++++++++++++++ Dockerfile | 3 +- 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/build.yaml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..37ec110 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,57 @@ +name: Build and Push Docker Image + +on: + release: + types: + - published + - edited + + pull_request: + branches: + - main + types: + - opened + - synchronize + - reopened + paths: + - core/** + - forward-proxy/** + - Dockerfile + - Makefile + +concurrency: + group: "${{ github.workflow }}-${{ github.ref_name }}-${{ github.event_name }}" + cancel-in-progress: true + +jobs: + build-and-push: + runs-on: ubuntu-latest + strategy: + matrix: + DEBIAN_TAG: ["trixie", "trixie-slim", "bullseye", "bullseye-slim", "buster", "buster-slim", "bookworm-slim", "bookworm"] + steps: + - name: Checkout Repo + uses: actions/checkout@v4.1.2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3.2.0 + + - name: Login to DockerHub + if: github.event_name == 'release' + uses: docker/login-action@v3.1.0 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + + - name: Build and Push Docker image + uses: docker/build-push-action@v5.3.0 + with: + context: . + file: Dockerfile + platforms: linux/amd64,linux/arm64/v8 + push: ${{ github.event_name == 'release' }} + tags: makepad/sfp:${{ (github.event_name == 'release' && github.event.release.tag_name) || github.sha }}-${{ matrix.DEBIAN_TAG }} + build-args: | + DEBIAN_TAG=${{ matrix.DEBIAN_TAG }} + cache-from: type=registry,ref=makepad/sfp:${{( github.event_name == 'release' && github.event.release.tag_name) || github.sha }}-${{ matrix.DEBIAN_TAG }} + cache-to: type=inline diff --git a/Dockerfile b/Dockerfile index ef52c81..976e9f9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,4 @@ +ARG DEBIAN_TAG FROM golang:1.22.2-bookworm as build WORKDIR /app @@ -11,7 +12,7 @@ COPY ./forward-proxy ./forward-proxy RUN make build-local -FROM debian:bookworm-slim +FROM debian:${DEBIAN_TAG} EXPOSE 9090 WORKDIR /app