Docker #1725
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| name: Docker | |
| on: | |
| push: | |
| pull_request: | |
| schedule: | |
| - cron: "0 0 * * 0" | |
| workflow_dispatch: | |
| permissions: {} | |
| jobs: | |
| docker-build-push: | |
| if: ${{ ! startsWith(github.ref, 'refs/tags/') }} | |
| permissions: | |
| # Required to create a release | |
| contents: write | |
| # Required to sign the Docker image | |
| id-token: write | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Set IMAGE | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| IFS=$'\n\t' | |
| echo "IMAGE=${GITHUB_REPOSITORY#*/docker-}" >> "${GITHUB_ENV}" | |
| - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | |
| with: | |
| persist-credentials: false | |
| - name: Set SOURCE_DATE_EPOCH | |
| run: | | |
| set -euo pipefail | |
| IFS=$'\n\t' | |
| echo "SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct)" >> "${GITHUB_ENV}" | |
| - uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0 | |
| - uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1 | |
| - uses: docker/metadata-action@c1e51972afc2121e065aed6d45c65596fe445f3f # v5.8.0 | |
| id: meta | |
| with: | |
| images: ${{ github.repository_owner }}/${{ env.IMAGE }} | |
| tags: | | |
| type=schedule | |
| type=ref,event=branch | |
| type=ref,event=pr | |
| type=sha | |
| - name: Test the Docker image | |
| working-directory: ${{ env.IMAGE }} | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| IFS=$'\n\t' | |
| docker compose -f docker-compose.test.yml run sut | |
| - uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0 | |
| if: github.ref == 'refs/heads/main' | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0 | |
| id: build | |
| with: | |
| # zizmor: ignore[template-injection] no user input | |
| context: ${{ env.IMAGE }} | |
| platforms: linux/amd64,linux/arm64 | |
| pull: true | |
| push: ${{ github.ref == 'refs/heads/main' }} | |
| sbom: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| - name: Install cosign | |
| if: github.ref == 'refs/heads/main' | |
| uses: sigstore/cosign-installer@faadad0cce49287aee09b3a48701e75088a2c6ad # v4.0.0 | |
| - name: Sign the Docker image | |
| if: github.ref == 'refs/heads/main' | |
| working-directory: ${{ env.IMAGE }} | |
| env: | |
| DIGEST: ${{ steps.build.outputs.digest }} | |
| TAGS: ${{ steps.meta.outputs.tags }} | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| IFS=$'\n\t' | |
| images=() | |
| for tag in ${TAGS}; do | |
| images+=("${tag}@${DIGEST}") | |
| done | |
| cosign sign --recursive --yes "${images[@]}" | |
| - name: Set VERSION | |
| if: github.ref == 'refs/heads/main' | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| IFS=$'\n\t' | |
| VERSION="$(\grep "${IMAGE}/Dockerfile" -e '^FROM' | \head -n 1 | \sed -e 's/@.*$//; s/^.*://;')" | |
| if [[ "${VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]\-minimal$ ]] ; then | |
| echo "VERSION=${VERSION/\.[0-9]-minimal/}" >> "${GITHUB_ENV}" | |
| fi | |
| - name: Check if release already exists | |
| if: env.VERSION != '' | |
| uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 | |
| id: check-release | |
| with: | |
| script: | | |
| const { VERSION } = process.env | |
| return github.rest.repos.getReleaseByTag({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| tag: `v${VERSION}`, | |
| }).then(function(result) { | |
| core.debug(JSON.stringify(result)) | |
| core.info(`Release ${result.data.tag_name} found`) | |
| return result.data.tag_name | |
| }).catch(function(error) { | |
| if (error.status === 404) { | |
| core.info(`Release v${VERSION} not found`) | |
| return | |
| } else { | |
| throw error | |
| } | |
| }) | |
| result-encoding: string | |
| - name: Trigger Release | |
| if: env.VERSION != '' && steps.check-release.outputs.result == 'undefined' | |
| uses: actions/create-release@0cb9c9b65d5d1901c1f53e5e66eaf4afd303e70e # v1.1.4 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }} | |
| with: | |
| release_name: ${{ env.VERSION }} | |
| tag_name: v${{ env.VERSION }} |