From b2db9ef0aa12d42bf1402f47e83092b31ba98c66 Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Thu, 20 Jan 2022 11:56:07 +0100 Subject: [PATCH] Build and push Docker image in GitHub Actions --- .github/workflows/docker.yaml | 73 +++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 .github/workflows/docker.yaml diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml new file mode 100644 index 0000000..e518ba4 --- /dev/null +++ b/.github/workflows/docker.yaml @@ -0,0 +1,73 @@ +name: Docker + +on: + push: + pull_request: + branches: [ master ] + +jobs: + build: + name: Build and push Docker image + runs-on: ubuntu-latest + env: + IMAGE: ghcr.io/${{ github.repository }} + + permissions: + packages: write + contents: read + + steps: + - name: Docker meta + id: meta + uses: docker/metadata-action@v3 + with: + images: "${{ env.IMAGE }}" + bake-target: docker-metadata-action + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=sha + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + with: + config-inline: | + [registry."docker.io"] + mirrors = ["mirror.gcr.io"] + + - name: Login to GitHub Container Registry + if: github.event_name != 'pull_request' + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build + uses: docker/build-push-action@v2 + if: github.event_name == 'pull_request' + with: + platforms: | + linux/amd64 + linux/arm64 + linux/arm + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=registry,ref=${{ env.IMAGE }}:buildcache + + - name: Build and push + uses: docker/build-push-action@v2 + if: github.event_name != 'pull_request' + with: + platforms: | + linux/amd64 + linux/arm64 + linux/arm + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + push: true + cache-from: type=registry,ref=${{ env.IMAGE }}:buildcache + cache-to: type=registry,ref=${{ env.IMAGE }}:buildcache,mode=max