From 769f35780dd5e6cdf24846dabe8dfd928ed89e45 Mon Sep 17 00:00:00 2001 From: amrc-benmorrow Date: Wed, 12 Jul 2023 10:19:30 +0100 Subject: [PATCH] Add the build pipeline actions. (#2) --- .github/workflows/docker-publish.yml | 101 +++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 .github/workflows/docker-publish.yml diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..457bad7 --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,101 @@ +name: Build & Publish Docker Image + +env: + REGISTRY: ghcr.io + +on: + release: + types: [ published ] + # Trigger only when a release with tag v*.*.* is published + tags: + - 'v[0-9]+.[0-9]+.[0-9]+' + +jobs: + update-version: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Update version in package.json + run: | + CURRENT_TAG=${GITHUB_REF#refs/tags/} + echo "Current tag: $CURRENT_TAG" + VERSION="${CURRENT_TAG#v}" + echo "Updating version to: $VERSION" + jq ".version = \"$VERSION\"" package.json > package.json.tmp + mv package.json.tmp package.json + - name: Create Pull Request + uses: peter-evans/create-pull-request@v4 + with: + title: Update package.json version + branch: update-version + commit-message: Update package.json version + body: Update the version of `package.json` as part of release process + delete-branch: true + base: main + build: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + id-token: write + pull-requests: write + + steps: + - uses: actions/checkout@v3 + + # Install the cosign tool except on PR + # https://github.com/sigstore/cosign-installer + - name: Install cosign + if: github.event_name != 'pull_request' + uses: sigstore/cosign-installer@f3c664df7af409cb4873aa5068053ba9d61a57b6 #v2.6.0 + with: + cosign-release: 'v1.13.1' + + # Workaround: https://github.com/docker/build-push-action/issues/461 + - name: Setup Docker buildx + uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf + + # Login against a Docker registry except on PR + # https://github.com/docker/login-action + - name: Log into registry ${{ env.REGISTRY }} + if: github.event_name != 'pull_request' + uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # Extract metadata (tags, labels) for Docker + # https://github.com/docker/metadata-action + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 + with: + images: ${{ env.REGISTRY }}/${{ github.repository }} + + # Build and push Docker image with Buildx (don't push on PR) + # https://github.com/docker/build-push-action + - name: Build and push Docker image + id: build-and-push + uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + + + # Sign the resulting Docker image digest except on PRs. + # This will only write to the public Rekor transparency log when the Docker + # repository is public to avoid leaking data. If you would like to publish + # transparency data even for private images, pass --force to cosign below. + # https://github.com/sigstore/cosign + - name: Sign the published Docker image + if: ${{ github.event_name != 'pull_request' }} + env: + COSIGN_EXPERIMENTAL: "true" + # This step uses the identity token to provision an ephemeral certificate + # against the sigstore community Fulcio instance. + run: echo "${{ steps.meta.outputs.tags }}" | xargs -I {} cosign sign {}@${{ steps.build-and-push.outputs.digest }}