name: Publish Docker images # Images are published from a *published release*, never from a bare tag push. # A tag that is later deleted (the versioning rule consolidates unreleased tags) # would otherwise leave its image tags behind in GHCR forever, and dependency # bots read those as a newer version. See issue #87. # # Tags follow the GitLab registry so both say the same thing: a release publishes # `X.Y.Z`, `X.Y` and `latest`; a push to main publishes only `edge`. (`latest` used # to follow main here, and a release run overwrote it as well, so thirteen releases # published at once left it pointing at whichever finished last.) Re-running the # workflow by hand on a `vX.Y.Z` ref republishes exactly that version's tags. on: push: branches: [main] # A docs, website or workflow-only change ships the same images: 181 edge # builds in three months, many of them for a README line. Anything that ends up in an image # still builds (api/, web/, frontend/, catalogue media through the web build). paths-ignore: - '*.md' - 'docs/**' - 'website/**' # (a change to this workflow alone: run it by hand) - '.github/**' - 'helm/**' - 'kubernetes/**' - 'contrib/**' - 'frontend/ios/**' - 'frontend/android/**' release: types: [published] workflow_dispatch: permissions: contents: read packages: write # A newer push to main makes an unfinished `edge` build pointless; a release build is never # cancelled (each release has its own group). concurrency: group: docker-${{ github.event_name == 'release' && github.ref || 'edge' }} cancel-in-progress: ${{ github.event_name == 'push' }} jobs: build: runs-on: ubuntu-latest timeout-minutes: 60 strategy: matrix: include: - image: api context: ./api file: ./api/Dockerfile - image: web context: . file: ./web/Dockerfile # The optional MCP-over-HTTPS container (docker-compose.yml profile `mcp`). - image: mcp context: . file: ./mcp/Dockerfile steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Versions agree with the release tag if: github.event_name == 'release' run: node scripts/ci/release-check.mjs "$GITHUB_REF_NAME" - name: Lowercase owner (registry names must be lowercase) id: repo run: echo "owner=$(echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_OUTPUT" - name: Set version metadata id: version_meta run: | # On a release the ref is refs/tags/vX.Y.Z; on a main push it is a branch ref, # which would otherwise label the image "refs/heads/main". case "$GITHUB_REF" in refs/tags/*) VERSION="${GITHUB_REF#refs/tags/}" ;; *) VERSION="main-${GITHUB_SHA::7}" ;; esac echo "VERSION=$VERSION" >> $GITHUB_OUTPUT echo "VCS_REF=${GITHUB_SHA}" >> $GITHUB_OUTPUT echo "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT - uses: docker/setup-qemu-action@99012661954931238ded8c8b007157a8430204e1 # v4.4.0 - uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1 - uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.0 id: meta with: images: ghcr.io/${{ steps.repo.outputs.owner }}/opengym-${{ matrix.image }} tags: | type=raw,value=edge,enable=${{ github.ref == 'refs/heads/main' }} type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/') }} type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} - uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0 with: pull: true context: ${{ matrix.context }} file: ${{ matrix.file }} platforms: linux/amd64,linux/arm64 build-args: | VERSION=${{ steps.version_meta.outputs.VERSION }} VCS_REF=${{ steps.version_meta.outputs.VCS_REF }} BUILD_DATE=${{ steps.version_meta.outputs.BUILD_DATE }} push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha,scope=${{ matrix.image }} cache-to: type=gha,mode=max,scope=${{ matrix.image }}