name: CI Image
on:
push:
branches: [main]
paths:
- ".github/ci/**"
- "rust-toolchain.toml"
- ".github/workflows/ci-image.yml"
pull_request:
paths:
- ".github/ci/**"
- "rust-toolchain.toml"
- ".github/workflows/ci-image.yml"
workflow_dispatch:
concurrency:
group: ci-image-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
env:
IMAGE: eccr.ecmwf.int/aviso/server-ci
jobs:
require-version-bump:
name: require VERSION bump
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Image-input changes must bump .github/ci/VERSION
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
set -euo pipefail
mapfile -t changed < <(git diff --name-only "$BASE_SHA" "$HEAD_SHA")
version_bumped=false
content_changed=false
for f in "${changed[@]}"; do
case "$f" in
.github/ci/VERSION) version_bumped=true ;;
.github/ci/*|rust-toolchain.toml) content_changed=true ;;
esac
done
if $content_changed && ! $version_bumped; then
echo "::error::CI image inputs changed without bumping .github/ci/VERSION"
exit 1
fi
echo "ok: image inputs and VERSION are consistent"
build-and-push:
name: Build CI image
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
runs-on: [self-hosted, Linux, platform-builder-docker-xl, platform-builder-Ubuntu-22.04]
steps:
- uses: actions/checkout@v5
- name: Read version and pinned toolchain
id: version
run: |
VERSION=$(tr -d '[:space:]' < .github/ci/VERSION)
# Drive the image's Rust from rust-toolchain.toml so a channel
# bump (which triggers this workflow) actually rebakes the
# toolchain instead of silently reusing the Dockerfile default.
RUST=$(grep -oP 'channel\s*=\s*"\K[^"]+' rust-toolchain.toml)
{
echo "full=$VERSION"
echo "major=$(echo "$VERSION" | cut -d. -f1)"
echo "minor=$(echo "$VERSION" | cut -d. -f1-2)"
echo "rust=$RUST"
} >> "$GITHUB_OUTPUT"
- uses: docker/setup-buildx-action@v4
- name: Login to ECCR
if: github.event_name != 'pull_request'
uses: docker/login-action@v4
with:
registry: eccr.ecmwf.int
username: ${{ secrets.ECMWF_DOCKER_REGISTRY_USERNAME }}
password: ${{ secrets.ECMWF_DOCKER_REGISTRY_ACCESS_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v7
with:
context: .github/ci/
build-args: |
RUST_VERSION=${{ steps.version.outputs.rust }}
push: ${{ github.event_name != 'pull_request' }}
tags: |
${{ env.IMAGE }}:${{ steps.version.outputs.full }}
${{ env.IMAGE }}:${{ steps.version.outputs.minor }}
${{ env.IMAGE }}:${{ steps.version.outputs.major }}
${{ env.IMAGE }}:latest
cache-from: type=gha
cache-to: type=gha,mode=max