From 03e1a7a10bbc7f33f581da43329dc1234fb036ff 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 | 14 +++++++++ .github/workflows/image-push-master.yml | 30 ++++++++++++++++++++ .github/workflows/image-push-release.yml | 36 ++++++++++++++++++++++++ 3 files changed, 80 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..a8210e8 100644 --- a/.github/workflows/build-test-lint.yml +++ b/.github/workflows/build-test-lint.yml @@ -24,6 +24,20 @@ jobs: GOOS: ${{ matrix.goos }} run: make build + build-image: + runs-on: ubuntu-22.04 + steps: + - name: Check out the repo + uses: actions/checkout@v4 + + - name: Build and push container image + uses: docker/build-push-action@v5 + 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..33d844b --- /dev/null +++ b/.github/workflows/image-push-master.yml @@ -0,0 +1,30 @@ +name: "Push images on merge to master" +on: + push: + branches: + - master +jobs: + build-and-push-image: + runs-on: ubuntu-22.04 + env: + IMAGE_NAME: ghcr.io/${{ github.repository }} + steps: + - name: Check out the repo + uses: actions/checkout@v4 + + - name: Login to Docker + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push container image + uses: docker/build-push-action@v5 + 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..93218ac --- /dev/null +++ b/.github/workflows/image-push-release.yml @@ -0,0 +1,36 @@ +name: "Push images on release" +on: + push: + tags: + - v* +jobs: + build-and-push-image: + runs-on: ubuntu-22.04 + env: + IMAGE_NAME: ghcr.io/${{ github.repository }} + steps: + - name: Check out the repo + uses: actions/checkout@v2 + + - name: Login to Docker + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Docker meta + id: docker_meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.IMAGE_NAME }} + tag-latest: false + + - name: Build and push container image + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: | + ${{ steps.docker_meta.outputs.tags }} + file: ./Dockerfile