# SPDX-License-Identifier: AGPL-3.0-or-later name: build image (reusable) on: workflow_call: inputs: image: description: "Image name under ghcr.io// (for example fluxer-api)" type: string required: true dockerfile: description: "Path to the Dockerfile to build" type: string required: true context: description: "Docker build context" type: string required: false default: "." build-version: description: "Explicit Fluxer CalVer build version (YYYY.MDD.MICRO, UTC HHMMSS without leading zeroes) to use instead of automatic UTC clock allocation" type: string required: false default: "" moving-tags: description: "Comma-separated moving tags to repoint at this build" type: string required: false default: "v1,latest" extra-build-args: description: "Additional Docker build args, one KEY=VALUE entry per line" type: string required: false default: "" permissions: actions: read contents: write packages: write concurrency: group: publish-${{ inputs.image }} cancel-in-progress: false defaults: run: shell: bash env: GHCR_OWNER: ${{ github.repository_owner }} jobs: meta: name: resolve metadata runs-on: ubuntu-24.04 timeout-minutes: 5 permissions: contents: read outputs: build_version: ${{ steps.vars.outputs.build_version }} steps: - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 env: GIT_CONFIG_GLOBAL: ${{ runner.temp }}/gitconfig - name: Set up Rust toolchain (CI helpers) uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9 with: toolchain: "1.93.0" - name: Create token id: create-token uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 with: client-id: ${{ vars.FLUXER_CI_APP_ID }} private-key: ${{ secrets.FLUXER_CI_APP_KEY }} owner: fluxerapp repositories: fluxer permission-contents: read - name: set variables id: vars env: GH_TOKEN: ${{ steps.create-token.outputs.token }} FLUXER_BUILD_VERSION: ${{ inputs['build-version'] }} run: >- tools/ci/run.sh resolve-calver --github-output build: name: build ${{ matrix.platform }} needs: meta runs-on: ${{ matrix.runner }} timeout-minutes: 75 permissions: actions: read contents: read packages: write strategy: fail-fast: false matrix: include: - platform: amd64 runner: ubuntu-24.04 - platform: arm64 runner: ubuntu-24.04-arm steps: - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 env: GIT_CONFIG_GLOBAL: ${{ runner.temp }}/gitconfig - name: resolve source date id: source run: echo "date=$(TZ=UTC git log -1 --no-show-signature --pretty=%cd --date=format-local:%Y-%m-%dT%H:%M:%SZ)" >> "$GITHUB_OUTPUT" - uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 - uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee with: registry: ghcr.io username: ${{ github.actor }} password: ${{ github.token }} - uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf with: context: ${{ inputs.context }} file: ${{ inputs.dockerfile }} push: true provenance: mode=min platforms: linux/${{ matrix.platform }} tags: ghcr.io/${{ env.GHCR_OWNER }}/${{ inputs.image }}:${{ needs.meta.outputs.build_version }}-${{ matrix.platform }} build-args: | BUILD_VERSION=${{ needs.meta.outputs.build_version }} SOURCE_SHA=${{ github.sha }} SOURCE_DATE=${{ steps.source.outputs.date }} ${{ inputs.extra-build-args }} cache-from: type=registry,ref=ghcr.io/${{ env.GHCR_OWNER }}/${{ inputs.image }}:buildcache-${{ matrix.platform }} cache-to: type=registry,ref=ghcr.io/${{ env.GHCR_OWNER }}/${{ inputs.image }}:buildcache-${{ matrix.platform }},mode=max,image-manifest=true,oci-mediatypes=true,ignore-error=true env: DOCKER_BUILD_SUMMARY: false DOCKER_BUILD_RECORD_UPLOAD: false merge: name: merge multi-arch manifest needs: [meta, build] runs-on: ubuntu-24.04 timeout-minutes: 10 permissions: contents: write packages: write steps: - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 env: GIT_CONFIG_GLOBAL: ${{ runner.temp }}/gitconfig - name: Set up Rust toolchain (CI helpers) uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9 with: toolchain: "1.93.0" - uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 - uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee with: registry: ghcr.io username: ${{ github.actor }} password: ${{ github.token }} - name: create and push multi-arch manifest env: IMAGE: ghcr.io/${{ env.GHCR_OWNER }}/${{ inputs.image }} VERSION: ${{ needs.meta.outputs.build_version }} run: | set -euo pipefail docker buildx imagetools create -t "${IMAGE}:${VERSION}" \ "${IMAGE}:${VERSION}-amd64" \ "${IMAGE}:${VERSION}-arm64" docker buildx imagetools inspect "${IMAGE}:${VERSION}" - name: Create token id: create-token uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 with: client-id: ${{ vars.FLUXER_CI_APP_ID }} private-key: ${{ secrets.FLUXER_CI_APP_KEY }} owner: fluxerapp repositories: fluxer permission-contents: write - name: Publish GitHub release env: GH_TOKEN: ${{ steps.create-token.outputs.token }} SOURCE_SHA: ${{ github.sha }} VERSION: ${{ needs.meta.outputs.build_version }} RELEASE_BASELINE_SHA: ${{ vars.RELEASE_BASELINE_SHA }} run: >- tools/ci/run.sh release publish --component "${{ inputs.image }}" --build-version "${VERSION}" --source-sha "${SOURCE_SHA}" --previous-sha "${RELEASE_BASELINE_SHA}" - name: Advance moving image tags env: MOVING_TAGS: ${{ inputs.moving-tags }} VERSION: ${{ needs.meta.outputs.build_version }} run: >- tools/ci/run.sh image-set promote --component "${{ inputs.image }}" --build-version "${VERSION}" --registry "ghcr.io/${{ env.GHCR_OWNER }}" --moving-tags "${MOVING_TAGS}"