From 34d24bdecccfa980b41635dc2a7eee28d33081cc Mon Sep 17 00:00:00 2001 From: Nikita Tokarchuk Date: Thu, 9 Dec 2021 23:36:17 +0100 Subject: [PATCH] Add github action to build and push image --- .github/workflows/image-make-and-publish.yml | 58 ++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 .github/workflows/image-make-and-publish.yml diff --git a/.github/workflows/image-make-and-publish.yml b/.github/workflows/image-make-and-publish.yml new file mode 100644 index 0000000..f9276d5 --- /dev/null +++ b/.github/workflows/image-make-and-publish.yml @@ -0,0 +1,58 @@ +name: Docker + +on: + push: + branches: [ master ] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build: + + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + id-token: write + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Install cosign + if: github.event_name != 'pull_request' + uses: sigstore/cosign-installer@main + + - name: Setup Docker buildx + uses: docker/setup-buildx-action@v1 + + - name: Log into registry ${{ env.REGISTRY }} + if: github.event_name != 'pull_request' + uses: docker/login-action@v1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v3 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + id: build-and-push + uses: docker/build-push-action@v2 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + - name: Sign the published Docker image + if: ${{ github.event_name != 'pull_request' && !github.event.repository.private }} + env: + COSIGN_EXPERIMENTAL: "true" + run: cosign sign ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.build-and-push.outputs.digest }}