Skip to content
90 changes: 73 additions & 17 deletions .github/workflows/build-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,101 @@ name: Build Image

on:
push:
branches: [ master ]
branches: [master, main]
paths:
- 'build-image/**'
- '.github/workflows/build-image.yml'
pull_request:
branches: [ master ]
branches: [master, main]
paths:
- 'build-image/**'
- '.github/workflows/build-image.yml'
workflow_dispatch:

permissions:
permissions:
contents: read
packages: write

env:
REGISTRY: quay.io
IMAGE_NAME: cortexproject/build-image

jobs:
build:
runs-on: ubuntu-24.04
runs-on: ubuntu-latest
outputs:
image-digest: ${{ steps.build.outputs.digest }}
image-tag: ${{ steps.meta.outputs.tags }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
name: Checkout
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up QEMU
uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@18ce135bb5112fa8ce4ed6c17ab05699d7f3a5e0 # v3.11.0
uses: docker/setup-buildx-action@v3

- name: Save image
run: make save-multiarch-build-image
- name: Login to Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.QUAY_REGISTRY_USER }}
password: ${{ secrets.QUAY_REGISTRY_PASSWORD }}

- name: Upload Docker Images Artifacts
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
name: build-image
path: |
./build-image-amd64.tar
./build-image-arm64.tar
if-no-files-found: error
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=sha,enable={{is_default_branch}},prefix={{branch}}-
type=raw,value=latest,enable={{is_default_branch}}

- name: Build and push
id: build
uses: docker/build-push-action@v6
with:
context: ./build-image
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
# Security features
provenance: true
sbom: true

- name: Generate attestation
if: github.event_name != 'pull_request'
uses: actions/attest-build-provenance@v1
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
subject-digest: ${{ steps.build.outputs.digest }}
push-to-registry: true

# Test the build image
test:
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'pull_request'
steps:
- uses: actions/checkout@v4

- name: Test build image functionality
run: |
# Test that the build image contains expected tools
docker run --rm ${{ needs.build.outputs.image-tag }} which go
docker run --rm ${{ needs.build.outputs.image-tag }} which make
docker run --rm ${{ needs.build.outputs.image-tag }} which git

# Test Go version
docker run --rm ${{ needs.build.outputs.image-tag }} go version

push:
needs: build
Expand Down
Loading
Loading