diff --git a/.github/workflows/docker-build-push-multiarch.md b/.github/workflows/docker-build-push-multiarch.md index 2b44b86ae..6f2c363f8 100644 --- a/.github/workflows/docker-build-push-multiarch.md +++ b/.github/workflows/docker-build-push-multiarch.md @@ -74,8 +74,11 @@ jobs: | `platforms` | string | List of platforms to build the image for. Passed to `docker/build-push-action`. | | `push` | string | Whether to push the image to the configured registries. Passed to `docker/build-push-action`. | | `registries` | string | CSV list of registries to build images for. Accepted registries are "gar" and "dockerhub". | +| `runner-type` | string | Setting this flag will dictate the default instance types to use. If runner-type-x64, runner-type-arm64, and runner-type-manifest are all set then this value is superseded because no defaults will be used. | +| `runner-type-arm64` | string | The instance type to use for arm64 builds. | +| `runner-type-manifest` | string | The instance type to use when building and pushing the manifest. | +| `runner-type-x64` | string | The instance type to use for x64 builds. | | `secrets` | string | Secrets to expose to the build. Only needed when authenticating to private repositories outside the repository in which the image is being built. Passed to `docker/build-push-action`. | -| `server-size` | string | Size of the Grafana self-hosted runner | | `ssh` | string | List of SSH agent socket or keys to expose to the build Passed to `docker/build-push-action`. | | `tags` | string | List of Docker tags to be pushed. Passed to `docker/build-push-action`. | | `target` | string | Sets the target stage to build. Passed to `docker/build-push-action`. | diff --git a/.github/workflows/docker-build-push-multiarch.yml b/.github/workflows/docker-build-push-multiarch.yml index 236e71af1..b4adaf9e9 100644 --- a/.github/workflows/docker-build-push-multiarch.yml +++ b/.github/workflows/docker-build-push-multiarch.yml @@ -5,10 +5,27 @@ on: inputs: # THE FOLLOWING INPUTS ARE UNIQUE TO THIS WORKFLOW # MULTIARCH CONFIGS - server-size: - description: "Size of the Grafana self-hosted runner" + runner-type: + description: | + Setting this flag will dictate the default instance types to use. + Allowed values are 'self-hosted' or 'github'. + required: false + default: "self-hosted" + type: string + runner-type-arm64: + description: | + The instance type to use for arm64 builds. + required: false + type: string + runner-type-manifest: + description: | + The instance type to use when building and pushing the manifest. + required: false + type: string + runner-type-x64: + description: | + The instance type to use for x64 builds. required: false - default: "small" type: string # The following inputs are identical to the inputs @@ -190,18 +207,21 @@ on: version: description: "Generated Docker image version (from docker/metadata-action)" value: ${{ jobs.build-and-push.outputs.version }} - runner_arches: + runner-arches: description: "The list of OS used to build images (for mapping to self hosted runners)" - value: ${{ jobs.prepare-matrix.outputs.runner_arches }} + value: ${{ jobs.prepare-matrix.outputs.runner-arches }} env: ARCH_TO_PLATFORM_MAP: '{"arm64": "linux/arm64", "x64": "linux/amd64"}' jobs: prepare-matrix: - runs-on: ubuntu-arm64-small + runs-on: ${{ inputs.runner-type == 'self-hosted' && 'ubuntu-x64-small' || 'ubuntu-latest' }} outputs: - runner_arches: ${{ steps.matrix.outputs.runner_arches }} + runner-arches: ${{ steps.matrix.outputs.runner-arches }} + runner-type-x64: ${{ steps.runners.outputs.runner-type-x64 }} + runner-type-arm64: ${{ steps.runners.outputs.runner-type-arm64 }} + runner-type-manifest: ${{ steps.runners.outputs.runner-type-manifest }} steps: - id: matrix shell: bash @@ -232,15 +252,54 @@ jobs: MATRIX=$(echo "$PS" | jq -R -c 'split(",")') # Export as GitHub Action output - echo "runner_arches=$MATRIX" | tee -a "${GITHUB_OUTPUT}" + echo "runner-arches=$MATRIX" | tee -a "${GITHUB_OUTPUT}" + - id: runners + shell: bash + env: + RUNNER_TYPE: ${{ inputs.runner-type }} + X64_TYPE: ${{ inputs.runner-type-x64 }} + ARM64_TYPE: ${{ inputs.runner-type-arm64 }} + MANIFEST_TYPE: ${{ inputs.runner-type-manifest }} + run: | + ############################################################# + # This step sets up the runner types for the remaining jobs + ############################################################# + + # Set default runner types based on RUNNER_TYPE + case "$RUNNER_TYPE" in + self-hosted) + DEFAULT_X64="ubuntu-x64-small" + DEFAULT_ARM64="ubuntu-arm64-small" + DEFAULT_MANIFEST="ubuntu-arm64-small" + ;; + github) + DEFAULT_X64="ubuntu-24.04" + DEFAULT_ARM64="ubuntu-24.04-arm" + DEFAULT_MANIFEST="ubuntu-24.04-arm" + ;; + *) + echo "Unknown RUNNER_TYPE: $RUNNER_TYPE" >&2 + exit 1 + ;; + esac + + # Use user-provided overrides if they exist, otherwise use defaults + X64_OUT="${X64_TYPE:-$DEFAULT_X64}" + ARM64_OUT="${ARM64_TYPE:-$DEFAULT_ARM64}" + MANIFEST_OUT="${MANIFEST_TYPE:-$DEFAULT_MANIFEST}" + + # Export to GitHub Actions outputs + echo "runner-type-x64=$X64_OUT" | tee -a "${GITHUB_OUTPUT}" + echo "runner-type-arm64=$ARM64_OUT" | tee -a "${GITHUB_OUTPUT}" + echo "runner-type-manifest=$MANIFEST_OUT" | tee -a "${GITHUB_OUTPUT}" build-and-push: needs: prepare-matrix strategy: fail-fast: false matrix: - arch: ${{ fromJson(needs.prepare-matrix.outputs.runner_arches) }} - runs-on: ubuntu-${{ matrix.arch }}-${{ inputs.server-size }} + arch: ${{ fromJson(needs.prepare-matrix.outputs.runner-arches) }} + runs-on: ${{ matrix.arch == 'x64' && needs.prepare-matrix.outputs.runner-type-x64 || needs.prepare-matrix.outputs.runner-type-arm64 }} outputs: annotations: ${{ steps.build.outputs.annotations }} digest: ${{ steps.build.outputs.digest }} @@ -312,8 +371,8 @@ jobs: platform: ${{ env.PLATFORM }} merge-digest: - runs-on: ubuntu-arm64-small - needs: build-and-push + runs-on: ${{ needs.prepare-matrix.outputs.runner-type-manifest }} + needs: [prepare-matrix, build-and-push] permissions: contents: read id-token: write