Repository navigation
ci: support multiple organizations in central maintenance #921
Workflow file for this run
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
| --- | |
| # This workflow is intended to work with all our organization Docker projects. A readme named `DOCKER_README.md` | |
| # will be used to update the description on Docker hub. | |
| # Repositories can define their build graph in `docker-bake.hcl`. When present, | |
| # the `default` group is built, and targets in an optional `artifacts` group | |
| # export files from `/artifacts`. A target's `dev.lizardbyte.image.variant` label | |
| # supplies its image tag suffix and job name. Without that label, the resolved | |
| # Dockerfile name is used. Each platform is dispatched to an allowlisted native | |
| # runner. | |
| # Repositories without a Bake definition emit a warning and skip Docker builds. | |
| # `CI_PR` is set for Bake files that use a reduced pull-request platform list. | |
| # Targets with `no-cache = true` do not import or export the GitHub Actions cache. | |
| # See https://docs.docker.com/build/bake/ for the standard file format. | |
| name: Docker (called) | |
| permissions: {} | |
| on: | |
| pull_request: | |
| workflow_call: | |
| inputs: | |
| image_namespace: | |
| description: 'Existing namespace for Docker Hub and GHCR images.' | |
| required: false | |
| default: 'LizardByte' | |
| type: string | |
| docker_hub_username: | |
| description: 'Docker Hub username to use for the workflow.' | |
| required: false | |
| type: string | |
| gh_bot_name: | |
| description: 'GitHub bot name to use for the workflow.' | |
| required: false | |
| type: string | |
| maximize_build_space: | |
| description: 'Maximize build space.' | |
| required: false | |
| type: boolean | |
| default: false | |
| publish_release: | |
| required: true | |
| type: string | |
| release_commit: | |
| required: true | |
| type: string | |
| release_tag: | |
| required: true | |
| type: string | |
| release_version: | |
| required: true | |
| type: string | |
| secrets: | |
| DOCKER_HUB_PASSWORD: | |
| description: 'Docker Hub password to use for the workflow.' | |
| required: false | |
| DOCKER_HUB_ACCESS_TOKEN: | |
| description: 'Docker Hub access token to use for the workflow.' | |
| required: false | |
| GH_BOT_TOKEN: | |
| description: 'GitHub bot token to use for the workflow.' | |
| required: false | |
| GH_TOKEN: | |
| description: 'GitHub token to use for the workflow.' | |
| required: false | |
| jobs: | |
| organization: | |
| uses: ./.github/workflows/__call-organization.yml | |
| check_dockerfiles: | |
| needs: organization | |
| name: Plan Docker builds | |
| permissions: | |
| contents: read | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| - name: Resolve Docker builds | |
| id: find | |
| env: | |
| CI_PR: ${{ github.event_name == 'pull_request' }} | |
| shell: bash | |
| run: | | |
| if [[ ! -f docker-bake.hcl ]]; then | |
| echo "::warning::No docker-bake.hcl file was found; skipping Docker builds." | |
| echo "has_bake=false" >> "${GITHUB_OUTPUT}" | |
| exit 0 | |
| fi | |
| echo "has_bake=true" >> "${GITHUB_OUTPUT}" | |
| definition_file=$(mktemp) | |
| CI_PR="${CI_PR}" docker buildx bake \ | |
| --file docker-bake.hcl \ | |
| --print \ | |
| default > "${definition_file}" | |
| artifacts_file=$(mktemp) | |
| if CI_PR="${CI_PR}" docker buildx bake \ | |
| --file docker-bake.hcl \ | |
| --print \ | |
| artifacts > "${artifacts_file}" 2>/dev/null; then | |
| artifact_targets=$(jq -c '.group.artifacts.targets // []' "${artifacts_file}") | |
| else | |
| artifact_targets='[]' | |
| fi | |
| matrix_data=$(jq -c --argjson artifact_targets "${artifact_targets}" ' | |
| def dockerfile_name($dockerfile): | |
| ($dockerfile | split("/") | last) as $filename | |
| | if ($filename | ascii_downcase) == "dockerfile" then | |
| "" | |
| elif ($filename | ascii_downcase | endswith(".dockerfile")) then | |
| $filename[0:-11] | |
| else | |
| error("Dockerfile names must be Dockerfile or end in .dockerfile: " + $dockerfile) | |
| end; | |
| def image_name($definition; $target; $dockerfile): | |
| ( | |
| $definition.target[$target].labels["dev.lizardbyte.image.variant"] | |
| // dockerfile_name($dockerfile) | |
| ) as $name | |
| | if ($name | test("^[A-Za-z0-9_.-]*$")) then | |
| $name | |
| else | |
| error("Invalid image variant for Bake target " + $target + ": " + $name) | |
| end; | |
| def runner($platform): | |
| if $platform == "linux/amd64" then | |
| "ubuntu-24.04" | |
| elif $platform == "linux/arm64" or ($platform | startswith("linux/arm64/")) then | |
| "ubuntu-24.04-arm" | |
| else | |
| error("No native runner is configured for Bake platform " + $platform) | |
| end; | |
| . as $definition | |
| | [ | |
| $definition.group.default.targets[] as $target | |
| | ($definition.target[$target].dockerfile // "Dockerfile") as $dockerfile | |
| | image_name($definition; $target; $dockerfile) as $name | |
| | ($definition.target[$target].platforms // ["linux/amd64"])[] as $platform | |
| | { | |
| target: $target, | |
| platform: $platform, | |
| platform_pair: ( | |
| $platform | |
| | gsub("[^A-Za-z0-9]+"; "-") | |
| | sub("^-"; "") | |
| | sub("-$"; "") | |
| ), | |
| runner: runner($platform), | |
| artifacts: (($artifact_targets | index($target)) != null), | |
| cache: (($definition.target[$target]["no-cache"] // false) == false), | |
| name: $name, | |
| tag: (if $name == "" then "" else "-" + $name end) | |
| } | |
| ] as $builds | |
| | [ | |
| $definition.group.default.targets[] as $target | |
| | ($definition.target[$target].dockerfile // "Dockerfile") as $dockerfile | |
| | image_name($definition; $target; $dockerfile) as $name | |
| | { | |
| target: $target, | |
| platform_count: (($definition.target[$target].platforms // ["linux/amd64"]) | length), | |
| name: $name, | |
| tag: (if $name == "" then "" else "-" + $name end) | |
| } | |
| ] as $targets | |
| | { | |
| builds: {include: $builds}, | |
| targets: {include: $targets} | |
| } | |
| ' "${definition_file}") | |
| echo "Bake build matrix:" | |
| jq '.builds' <<< "${matrix_data}" | |
| echo "bake_build_matrix=$(jq -c '.builds' <<< "${matrix_data}")" >> "${GITHUB_OUTPUT}" | |
| echo "bake_target_matrix=$(jq -c '.targets' <<< "${matrix_data}")" >> "${GITHUB_OUTPUT}" | |
| - name: Set image name | |
| id: additional_outputs | |
| if: steps.find.outputs.has_bake == 'true' | |
| env: | |
| IMAGE_NAMESPACE: ${{ inputs.image_namespace || 'LizardByte' }} | |
| REPOSITORY_NAME: ${{ github.event.repository.name }} | |
| run: | | |
| # set outputs for later jobs | |
| BASE_TAG=$(printf '%s/%s' "${IMAGE_NAMESPACE}" "${REPOSITORY_NAME}" | tr '[:upper:]' '[:lower:]') | |
| echo "base_tag=${BASE_TAG}" >> "${GITHUB_OUTPUT}" | |
| outputs: | |
| publish_release: ${{ needs.organization.outputs.allowed == 'true' && inputs.publish_release == 'true' }} | |
| bake_build_matrix: ${{ steps.find.outputs.bake_build_matrix }} | |
| bake_target_matrix: ${{ steps.find.outputs.bake_target_matrix }} | |
| base_tag: ${{ steps.additional_outputs.outputs.base_tag }} | |
| has_bake: ${{ steps.find.outputs.has_bake }} | |
| docker_bake: | |
| name: ${{ matrix.name && format('{0} ({1})', matrix.name, matrix.platform) || matrix.platform }} | |
| if: needs.check_dockerfiles.outputs.has_bake == 'true' | |
| needs: | |
| - check_dockerfiles | |
| permissions: | |
| contents: read | |
| packages: write | |
| runs-on: ${{ matrix.runner }} | |
| environment: | |
| name: >- | |
| ${{ | |
| needs.check_dockerfiles.outputs.publish_release == 'true' && | |
| format('docker{0}', matrix.tag) || | |
| null | |
| }} | |
| url: >- | |
| ${{ | |
| needs.check_dockerfiles.outputs.publish_release == 'true' && | |
| format('https://hub.docker.com/r/{0}/tags?name={1}', | |
| needs.check_dockerfiles.outputs.base_tag, matrix.tag) || | |
| null | |
| }} | |
| strategy: | |
| fail-fast: false | |
| matrix: ${{ fromJson(needs.check_dockerfiles.outputs.bake_build_matrix) }} | |
| steps: | |
| - name: More space | |
| if: inputs.maximize_build_space | |
| uses: LizardByte/actions/actions/more_space@0528b495e6af82b4d698ec6c907a9b1842622068 # v2026.1029.234422 | |
| with: | |
| analyze-space-savings: true | |
| clean-all: true | |
| - name: Checkout | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| submodules: recursive | |
| - name: Prepare Bake overrides | |
| id: prepare | |
| env: | |
| BRANCH: ${{ github.ref }} | |
| COMMIT: ${{ inputs.release_commit }} | |
| GH_EVENT_REPOSITORY_CLONE_URL: ${{ github.event.repository.clone_url }} | |
| PUBLISH_RELEASE: ${{ needs.check_dockerfiles.outputs.publish_release }} | |
| RELEASE_VERSION: ${{ inputs.release_version }} | |
| USE_CACHE: ${{ matrix.cache }} | |
| shell: bash | |
| run: | | |
| branch="${BRANCH:-master}" | |
| commit="${COMMIT:-${GITHUB_SHA}}" | |
| if [[ "${GITHUB_EVENT_NAME}" == "push" ]]; then | |
| branch="${GITHUB_REF_NAME}" | |
| fi | |
| target="${{ matrix.target }}" | |
| cache_scope="docker-${target}-${{ matrix.platform_pair }}" | |
| base_tag="${{ needs.check_dockerfiles.outputs.base_tag }}" | |
| { | |
| echo "set<<EOF" | |
| echo "${target}.platform=${{ matrix.platform }}" | |
| echo "${target}.args.BRANCH=${branch}" | |
| echo "${target}.args.BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" | |
| echo "${target}.args.BUILD_VERSION=${RELEASE_VERSION}" | |
| echo "${target}.args.COMMIT=${commit}" | |
| echo "${target}.args.CLONE_URL=${GH_EVENT_REPOSITORY_CLONE_URL}" | |
| echo "${target}.args.RELEASE=${PUBLISH_RELEASE}" | |
| if [[ "${USE_CACHE}" == "true" ]]; then | |
| echo "${target}.cache-from=type=gha,scope=${cache_scope}" | |
| echo "${target}.cache-to=type=gha,mode=max,scope=${cache_scope}" | |
| fi | |
| if [[ "${PUBLISH_RELEASE}" == "true" ]]; then | |
| image_output="${target}.output=type=image,\"name=${base_tag},ghcr.io/${base_tag}\"" | |
| image_output+=",push-by-digest=true,name-canonical=true,push=true" | |
| echo "${image_output}" | |
| if [[ "${{ matrix.artifacts }}" == "true" ]]; then | |
| echo "${target}.output+=type=local,dest=image" | |
| fi | |
| elif [[ "${{ matrix.artifacts }}" == "true" ]]; then | |
| echo "${target}.output=type=local,dest=image" | |
| else | |
| echo "${target}.output=type=cacheonly" | |
| fi | |
| echo "EOF" | |
| } >> "${GITHUB_OUTPUT}" | |
| - name: Set up Docker Buildx | |
| id: buildx | |
| uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1 | |
| - name: Log in to Docker Hub | |
| if: needs.check_dockerfiles.outputs.publish_release == 'true' # PRs do not have access to secrets | |
| uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4.8.0 | |
| with: | |
| username: ${{ inputs.docker_hub_username }} | |
| password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | |
| - name: Log in to the Container registry | |
| if: needs.check_dockerfiles.outputs.publish_release == 'true' # PRs do not have access to secrets | |
| uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4.8.0 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ inputs.gh_bot_name }} | |
| password: ${{ secrets.GH_BOT_TOKEN }} | |
| - name: Add problem matcher | |
| shell: bash | |
| run: | | |
| if [ -f "${{ github.workspace }}/.github/matchers/docker.json" ]; then | |
| echo "::add-matcher::${{ github.workspace }}/.github/matchers/docker.json" | |
| fi | |
| - name: Build and push by digest | |
| id: build | |
| uses: docker/bake-action@59cb1203cd42bcefd40a1b6d73b589e48c86040e # v7.5.0 | |
| with: | |
| builder: ${{ steps.buildx.outputs.name }} | |
| files: ./docker-bake.hcl | |
| source: . | |
| targets: ${{ matrix.target }} | |
| set: ${{ steps.prepare.outputs.set }} | |
| - name: Arrange Artifacts | |
| if: matrix.artifacts | |
| shell: bash | |
| run: | | |
| mkdir -p artifacts | |
| echo "::group::Moving artifacts" | |
| find \ | |
| ./image \ | |
| -mindepth 1 \ | |
| -maxdepth 3 \ | |
| -type d \ | |
| -name 'artifacts' \ | |
| -exec bash -c 'cp -rv "$1"/* ./artifacts/' _ {} \; | |
| echo "::endgroup::" | |
| echo "::group::Artifacts" | |
| ls -la ./artifacts/ | |
| echo "::endgroup::" | |
| - name: Upload Artifacts | |
| if: matrix.artifacts | |
| uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 | |
| with: | |
| name: build-Docker${{ matrix.tag }}-${{ matrix.platform_pair }} | |
| path: artifacts/ | |
| if-no-files-found: error | |
| - name: Export digest | |
| if: needs.check_dockerfiles.outputs.publish_release == 'true' | |
| env: | |
| BUILD_METADATA: ${{ steps.build.outputs.metadata }} | |
| shell: bash | |
| run: | | |
| digest=$(jq -r --arg target "${{ matrix.target }}" \ | |
| '.[$target]["containerimage.digest"] // empty' <<< "${BUILD_METADATA}") | |
| if [[ ! "${digest}" =~ ^sha256:[0-9a-f]{64}$ ]]; then | |
| echo "Unable to find a valid image digest for ${{ matrix.target }}" >&2 | |
| exit 1 | |
| fi | |
| mkdir -p digests | |
| touch "digests/${digest#sha256:}" | |
| - name: Upload digest | |
| if: needs.check_dockerfiles.outputs.publish_release == 'true' | |
| uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 | |
| with: | |
| name: docker-digests-${{ matrix.target }}-${{ matrix.platform_pair }} | |
| path: digests/* | |
| if-no-files-found: error | |
| retention-days: 1 | |
| docker_bake_manifest: | |
| name: Manifest | |
| if: needs.check_dockerfiles.outputs.publish_release == 'true' | |
| needs: | |
| - check_dockerfiles | |
| - docker_bake | |
| permissions: | |
| contents: read | |
| packages: write | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: ${{ fromJson(needs.check_dockerfiles.outputs.bake_target_matrix) }} | |
| steps: | |
| - name: Download digests | |
| uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 | |
| with: | |
| pattern: docker-digests-${{ matrix.target }}-* | |
| path: digests | |
| merge-multiple: true | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1 | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4.8.0 | |
| with: | |
| username: ${{ inputs.docker_hub_username }} | |
| password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | |
| - name: Log in to the Container registry | |
| uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4.8.0 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ inputs.gh_bot_name }} | |
| password: ${{ secrets.GH_BOT_TOKEN }} | |
| - name: Create manifests | |
| env: | |
| BASE_TAG: ${{ needs.check_dockerfiles.outputs.base_tag }} | |
| COMMIT: ${{ inputs.release_commit }} | |
| EXPECTED_PLATFORMS: ${{ matrix.platform_count }} | |
| NEW_TAG: ${{ inputs.release_tag }} | |
| TAG_SUFFIX: ${{ matrix.tag }} | |
| shell: bash | |
| run: | | |
| mapfile -t digests < <(find digests -maxdepth 1 -type f -printf '%f\n' | sort) | |
| if [[ "${#digests[@]}" -ne "${EXPECTED_PLATFORMS}" ]]; then | |
| echo "Expected ${EXPECTED_PLATFORMS} digests, found ${#digests[@]}" >&2 | |
| exit 1 | |
| fi | |
| commit="${COMMIT:-${GITHUB_SHA}}" | |
| tags=("${commit:0:7}${TAG_SUFFIX}") | |
| if [[ "${GITHUB_EVENT_NAME}" == "push" ]]; then | |
| tags+=("latest${TAG_SUFFIX}" "master${TAG_SUFFIX}") | |
| else | |
| tags+=("test${TAG_SUFFIX}") | |
| fi | |
| if [[ -n "${NEW_TAG}" ]]; then | |
| tags+=("${NEW_TAG}${TAG_SUFFIX}") | |
| fi | |
| docker_sources=() | |
| ghcr_sources=() | |
| for digest in "${digests[@]}"; do | |
| docker_sources+=("${BASE_TAG}@sha256:${digest}") | |
| ghcr_sources+=("ghcr.io/${BASE_TAG}@sha256:${digest}") | |
| done | |
| docker_tags=() | |
| ghcr_tags=() | |
| for tag in "${tags[@]}"; do | |
| docker_tags+=(--tag "${BASE_TAG}:${tag}") | |
| ghcr_tags+=(--tag "ghcr.io/${BASE_TAG}:${tag}") | |
| done | |
| docker buildx imagetools create "${docker_tags[@]}" "${docker_sources[@]}" | |
| docker buildx imagetools create "${ghcr_tags[@]}" "${ghcr_sources[@]}" | |
| docker_complete: | |
| name: Conclusion | |
| if: >- | |
| always() && | |
| needs.check_dockerfiles.outputs.has_bake == 'true' | |
| needs: | |
| - check_dockerfiles | |
| - docker_bake | |
| - docker_bake_manifest | |
| permissions: {} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check Docker jobs | |
| env: | |
| BAKE_RESULT: ${{ needs.docker_bake.result }} | |
| MANIFEST_RESULT: ${{ needs.docker_bake_manifest.result }} | |
| shell: bash | |
| run: | | |
| for result in "${BAKE_RESULT}" "${MANIFEST_RESULT}"; do | |
| if [[ "${result}" == "failure" || "${result}" == "cancelled" ]]; then | |
| exit 1 | |
| fi | |
| done | |
| release: | |
| name: Release | |
| if: > | |
| needs.check_dockerfiles.outputs.publish_release == 'true' && | |
| github.event_name == 'push' && | |
| github.ref == 'refs/heads/master' | |
| runs-on: ubuntu-latest | |
| needs: | |
| - check_dockerfiles | |
| - docker_complete | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| sparse-checkout: | | |
| DOCKER_README.md | |
| sparse-checkout-cone-mode: false | |
| - name: Update Docker Hub Description | |
| uses: peter-evans/dockerhub-description@1b9a80c056b620d92cedb9d9b5a223409c68ddfa # v5.0.0 | |
| with: | |
| username: ${{ inputs.docker_hub_username }} | |
| password: ${{ secrets.DOCKER_HUB_PASSWORD }} # token is not currently supported | |
| repository: ${{ needs.check_dockerfiles.outputs.base_tag }} | |
| short-description: ${{ github.event.repository.description }} | |
| readme-filepath: ./DOCKER_README.md |