From 725d19e2a9a679a5113efdbfb65066ea844ff28a Mon Sep 17 00:00:00 2001 From: Andrea Panattoni Date: Tue, 12 Mar 2024 14:58:44 +0100 Subject: [PATCH] Publish container images Configure GitHub actions to build and publish container images. Signed-off-by: Andrea Panattoni --- .github/workflows/build-test-lint.yml | 17 +++++++++++ .github/workflows/image-push-master.yml | 33 ++++++++++++++++++++ .github/workflows/image-push-release.yml | 39 ++++++++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 .github/workflows/image-push-master.yml create mode 100644 .github/workflows/image-push-release.yml diff --git a/.github/workflows/build-test-lint.yml b/.github/workflows/build-test-lint.yml index ebded02..fbeb090 100644 --- a/.github/workflows/build-test-lint.yml +++ b/.github/workflows/build-test-lint.yml @@ -24,6 +24,23 @@ jobs: GOOS: ${{ matrix.goos }} run: make build + build-image: + runs-on: ubuntu-20.04 + steps: + - name: Check out the repo + uses: actions/checkout@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Build and push container image + uses: docker/build-push-action@v2 + with: + context: . + push: false + file: ./Dockerfile + + test: runs-on: ubuntu-latest needs: build diff --git a/.github/workflows/image-push-master.yml b/.github/workflows/image-push-master.yml new file mode 100644 index 0000000..23ffbe7 --- /dev/null +++ b/.github/workflows/image-push-master.yml @@ -0,0 +1,33 @@ +name: "Push images on merge to master" +on: + push: + branches: + - master +jobs: + build-and-push-image: + runs-on: ubuntu-20.04 + env: + IMAGE_NAME: ghcr.io/${{ github.repository }} + steps: + - name: Check out the repo + uses: actions/checkout@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to Docker + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push container image + uses: docker/build-push-action@v2 + with: + context: . + push: true + tags: | + ${{ env.IMAGE_NAME }}:latest + ${{ env.IMAGE_NAME }}:${{ github.sha }} + file: ./Dockerfile diff --git a/.github/workflows/image-push-release.yml b/.github/workflows/image-push-release.yml new file mode 100644 index 0000000..ebab6a3 --- /dev/null +++ b/.github/workflows/image-push-release.yml @@ -0,0 +1,39 @@ +name: "Push images on release" +on: + push: + tags: + - v* +jobs: + build-and-push-image: + runs-on: ubuntu-20.04 + env: + IMAGE_NAME: ghcr.io/${{ github.repository }} + steps: + - name: Check out the repo + uses: actions/checkout@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to Docker + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Docker meta + id: docker_meta + uses: crazy-max/ghaction-docker-meta@v1 + with: + images: ${{ env.IMAGE_NAME }} + tag-latest: false + + - name: Build and push container image + uses: docker/build-push-action@v2 + with: + context: . + push: true + tags: | + ${{ steps.docker_meta.outputs.tags }} + file: ./Dockerfile