publish-image #743
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: publish-image | |
| concurrency: | |
| group: publish-image-${{ github.event.workflow_run.head_branch || github.ref_name || 'manual' }} | |
| cancel-in-progress: true | |
| on: | |
| workflow_dispatch: | |
| # Dockerfile builds again but does not run tests so we only | |
| # run this workflow after successful Go build-test | |
| workflow_run: | |
| workflows: ['build-test'] | |
| types: [completed] | |
| branches: ['main'] | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME: ${{ github.repository }} | |
| jobs: | |
| build-image: | |
| if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }} | |
| name: Build ${{ matrix.module }} (${{ matrix.os }}/${{ matrix.arch }}) | |
| runs-on: ${{ matrix.runner }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - module: broker | |
| dockerfile: ./broker/Dockerfile | |
| image: ghcr.io/${{ github.repository }}-broker | |
| title: CrossLink Broker | |
| description: ISO18626 transaction broker for CrossLink | |
| licenses: AGPL-3.0-only | |
| os: linux | |
| arch: amd64 | |
| runner: ubuntu-24.04 | |
| - module: broker | |
| dockerfile: ./broker/Dockerfile | |
| image: ghcr.io/${{ github.repository }}-broker | |
| title: CrossLink Broker | |
| description: ISO18626 transaction broker for CrossLink | |
| licenses: AGPL-3.0-only | |
| os: linux | |
| arch: arm64 | |
| runner: ubuntu-24.04-arm | |
| - module: illmock | |
| dockerfile: ./illmock/Dockerfile | |
| image: ghcr.io/${{ github.repository }}-illmock | |
| title: CrossLink ILL Mock | |
| description: ISO18626 and SRU mocking service for CrossLink | |
| licenses: AGPL-3.0-only | |
| os: linux | |
| arch: amd64 | |
| runner: ubuntu-24.04 | |
| - module: illmock | |
| dockerfile: ./illmock/Dockerfile | |
| image: ghcr.io/${{ github.repository }}-illmock | |
| title: CrossLink ILL Mock | |
| description: ISO18626 and SRU mocking service for CrossLink | |
| licenses: AGPL-3.0-only | |
| os: linux | |
| arch: arm64 | |
| runner: ubuntu-24.04-arm | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v7 | |
| with: | |
| # For workflow_run, build exactly the commit that completed build-test. | |
| ref: ${{ github.event.workflow_run.head_sha || github.sha }} | |
| - name: Load tool versions | |
| run: cat .github/tool-versions.env >> "$GITHUB_ENV" | |
| - name: Set up Go | |
| uses: actions/setup-go@v6 | |
| with: | |
| go-version: ${{ env.GO_VERSION }} | |
| cache-dependency-path: | | |
| go.work.sum | |
| ${{ matrix.module }}/go.sum | |
| - uses: awalsh128/cache-apt-pkgs-action@latest | |
| with: | |
| packages: xsltproc | |
| version: 1.0 | |
| - name: Generate sources | |
| run: make generate | |
| - name: Resolve source revision | |
| id: source | |
| run: | | |
| sha="${{ github.event.workflow_run.head_sha || github.sha }}" | |
| echo "sha=$sha" >> "$GITHUB_OUTPUT" | |
| echo "short-sha=${sha:0:7}" >> "$GITHUB_OUTPUT" | |
| echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> "$GITHUB_OUTPUT" | |
| - name: Log in to the Container registry | |
| uses: docker/login-action@v4 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata (tags, labels) for Docker | |
| id: meta | |
| uses: docker/metadata-action@v6 | |
| with: | |
| images: ${{ matrix.image }} | |
| tags: | | |
| type=ref,event=branch | |
| type=ref,event=tag | |
| type=raw,value=sha-${{ steps.source.outputs.short-sha }} | |
| labels: | | |
| org.opencontainers.image.title=${{ matrix.title }} | |
| org.opencontainers.image.description=${{ matrix.description }} | |
| org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }} | |
| org.opencontainers.image.licenses=${{ matrix.licenses }} | |
| org.opencontainers.image.url=${{ github.server_url }}/${{ github.repository }} | |
| org.opencontainers.image.documentation=${{ github.server_url }}/${{ github.repository }}/blob/${{ steps.source.outputs.sha }}/${{ matrix.module }}/README.md | |
| org.opencontainers.image.revision=${{ steps.source.outputs.sha }} | |
| org.opencontainers.image.created=${{ steps.source.outputs.created }} | |
| org.opencontainers.image.vendor=Index Data ApS | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v4 | |
| - name: Build and push Docker image by digest | |
| id: build | |
| uses: docker/build-push-action@v7 | |
| with: | |
| context: . | |
| file: ${{ matrix.dockerfile }} | |
| platforms: ${{ matrix.os }}/${{ matrix.arch }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| outputs: type=image,name=${{ matrix.image }},push-by-digest=true,name-canonical=true,push=true | |
| cache-from: type=gha,scope=${{ matrix.module }}-${{ matrix.os }}-${{ matrix.arch }} | |
| cache-to: type=gha,mode=max,scope=${{ matrix.module }}-${{ matrix.os }}-${{ matrix.arch }} | |
| - name: Export digest | |
| run: | | |
| mkdir -p /tmp/digests | |
| digest="${{ steps.build.outputs.digest }}" | |
| touch "/tmp/digests/${digest#sha256:}" | |
| - name: Upload digest | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| name: digests-${{ matrix.module }}-${{ matrix.os }}-${{ matrix.arch }} | |
| path: /tmp/digests/* | |
| if-no-files-found: error | |
| retention-days: 1 | |
| merge-image: | |
| if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }} | |
| name: Merge ${{ matrix.module }} image manifests | |
| runs-on: ubuntu-24.04 | |
| needs: | |
| - build-image | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - module: broker | |
| image: ghcr.io/${{ github.repository }}-broker | |
| description: ISO18626 transaction broker for CrossLink | |
| licenses: AGPL-3.0-only | |
| - module: illmock | |
| image: ghcr.io/${{ github.repository }}-illmock | |
| description: ISO18626 and SRU mocking service for CrossLink | |
| licenses: AGPL-3.0-only | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Download digests | |
| uses: actions/download-artifact@v8 | |
| with: | |
| path: /tmp/digests | |
| pattern: digests-${{ matrix.module }}-* | |
| merge-multiple: true | |
| - name: Log in to the Container registry | |
| uses: docker/login-action@v4 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Resolve source revision | |
| id: source | |
| run: | | |
| sha="${{ github.event.workflow_run.head_sha || github.sha }}" | |
| echo "sha=$sha" >> "$GITHUB_OUTPUT" | |
| echo "short-sha=${sha:0:7}" >> "$GITHUB_OUTPUT" | |
| echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> "$GITHUB_OUTPUT" | |
| - name: Extract metadata (tags, annotations) for Docker | |
| id: meta | |
| uses: docker/metadata-action@v6 | |
| with: | |
| images: ${{ matrix.image }} | |
| tags: | | |
| type=ref,event=branch | |
| type=ref,event=tag | |
| type=raw,value=sha-${{ steps.source.outputs.short-sha }} | |
| annotations: | | |
| org.opencontainers.image.description=${{ matrix.description }} | |
| org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }} | |
| org.opencontainers.image.licenses=${{ matrix.licenses }} | |
| env: | |
| DOCKER_METADATA_ANNOTATIONS_LEVELS: index | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v4 | |
| - name: Create manifest list and push | |
| working-directory: /tmp/digests | |
| run: | | |
| tags=() | |
| while IFS= read -r tag; do | |
| tags+=("-t" "$tag") | |
| done < <(jq -r '.tags[]' <<< "$DOCKER_METADATA_OUTPUT_JSON") | |
| annotations=() | |
| while IFS= read -r annotation; do | |
| annotations+=("--annotation" "$annotation") | |
| done < <(jq -r '.annotations[]' <<< "$DOCKER_METADATA_OUTPUT_JSON") | |
| refs=() | |
| for digest in *; do | |
| refs+=("${{ matrix.image }}@sha256:${digest}") | |
| done | |
| docker buildx imagetools create "${tags[@]}" "${annotations[@]}" "${refs[@]}" | |
| - name: Inspect image | |
| run: docker buildx imagetools inspect ${{ matrix.image }}:${{ steps.meta.outputs.version }} |