prop/.forgejo/workflows/build-base.yaml
Graham McIntire 8ea31e4317
ci: add prop-base image build pipeline
Pre-builds the runtime base (wgrib2 + g2c + cdo + gdal-bin + locale +
runtime apt deps) into git.mcintire.me/graham/prop-base. The base
workflow is path-filtered to fire only on Dockerfile.base /
build-base.yaml changes, so version bumps stay deterministic and
explicit.

Tag convention: `wgrib2-<v>-g2c-<v>-<unixts>` for traceability +
rollback, plus `:latest` for everyday consumption.

This commit only adds the new files — the app Dockerfile + build.yaml
still build wgrib2 from source. A follow-up will swap the app
Dockerfile to FROM prop-base:latest once this image lands in the
registry.
2026-05-03 11:40:50 -05:00

129 lines
4.3 KiB
YAML

name: Build base image
# Path-filtered so this only fires when the base Dockerfile (or this
# workflow) changes — typically a wgrib2 / g2c version bump or apt-dep
# tweak. `workflow_dispatch` lets us rebuild on demand without touching
# the file (e.g. to refresh CVE patches in the apt layer).
on:
push:
branches:
- main
paths:
- 'Dockerfile.base'
- '.forgejo/workflows/build-base.yaml'
workflow_dispatch:
env:
REGISTRY: git.mcintire.me
IMAGE_NAME: graham/prop-base
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build-and-push:
name: Build and push base image
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: https://github.com/actions/checkout@v4
# Static docker + buildx download — same dance as build.yaml /
# build-grid-rs.yaml. The runner image's bookworm apt repos have
# broken GPG signatures, so we bypass apt entirely.
- name: Install Docker CLI and buildx
run: |
curl -fsSL -o /tmp/docker.tgz \
https://download.docker.com/linux/static/stable/x86_64/docker-27.5.1.tgz
tar xzf /tmp/docker.tgz -C /tmp
install -m 0755 /tmp/docker/docker /usr/local/bin/docker
rm -rf /tmp/docker /tmp/docker.tgz
mkdir -p /usr/libexec/docker/cli-plugins
curl -fsSL -o /usr/libexec/docker/cli-plugins/docker-buildx \
https://github.com/docker/buildx/releases/download/v0.19.3/buildx-v0.19.3.linux-amd64
chmod +x /usr/libexec/docker/cli-plugins/docker-buildx
docker --version
docker buildx version
- name: Wait for Docker daemon
run: |
sock="${DOCKER_HOST:-unix:///var/run/docker.sock}"
echo "Using DOCKER_HOST=${sock}"
for i in $(seq 1 30); do
if docker info >/dev/null 2>&1; then
echo "Docker daemon reachable after ${i}s"
exit 0
fi
echo "Waiting for Docker daemon... ($i/30)"
sleep 1
done
echo "Docker daemon never became reachable — diagnostics:" >&2
ls -l /var/run/docker.sock 2>&1 || true
env | grep -i docker 2>&1 || true
docker info 2>&1 || true
exit 1
- name: Generate image tag
id: tag
run: |
# Embed the wgrib2 + g2c versions in the tag so prior bases
# remain pullable for hotfix rollbacks if a version bump
# regresses something at runtime.
WGRIB2=$(grep -E '^ARG WGRIB2_VERSION=' Dockerfile.base | head -1 | cut -d= -f2)
G2C=$(grep -E '^ARG G2C_VERSION=' Dockerfile.base | head -1 | cut -d= -f2)
TIMESTAMP=$(date +%s)
TAG="wgrib2-${WGRIB2}-g2c-${G2C}-${TIMESTAMP}"
echo "tag=${TAG}" >> $GITHUB_OUTPUT
- name: Log in to container registry
run: |
attempt=1
max_attempts=3
while : ; do
if echo "${{ secrets.REGISTRY_PASSWORD }}" | \
docker login "${{ secrets.REGISTRY_URL }}" \
-u "${{ secrets.REGISTRY_USER }}" \
--password-stdin; then
exit 0
fi
if [ "$attempt" -ge "$max_attempts" ]; then
echo "docker login failed after $attempt attempts" >&2
exit 1
fi
delay=$((2 ** attempt))
echo "docker login attempt $attempt failed; retrying in ${delay}s"
sleep "$delay"
attempt=$((attempt + 1))
done
- name: Build and push base image
run: |
IMAGE="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}"
TAG="${{ steps.tag.outputs.tag }}"
attempt=1
max_attempts=3
while : ; do
if docker buildx build \
-f Dockerfile.base \
-t "${IMAGE}:${TAG}" \
-t "${IMAGE}:latest" \
--push \
.; then
exit 0
fi
if [ "$attempt" -ge "$max_attempts" ]; then
echo "docker buildx build failed after $attempt attempts" >&2
exit 1
fi
delay=$((2 ** attempt))
echo "docker buildx build attempt $attempt failed; retrying in ${delay}s"
sleep "$delay"
attempt=$((attempt + 1))
done