Merge pull request 'Add matrixed gobuilder image build' (#1) from container-scaffold into main
ci/woodpecker/tag/docker Pipeline was successful
ci/woodpecker/tag/docker Pipeline was successful
Reviewed-on: #1
This commit was merged in pull request #1.
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v5.0.0
|
||||
hooks:
|
||||
- id: trailing-whitespace
|
||||
- id: end-of-file-fixer
|
||||
- id: check-yaml
|
||||
- id: check-merge-conflict
|
||||
- id: mixed-line-ending
|
||||
args: [--fix=lf]
|
||||
|
||||
- repo: https://github.com/AleksaC/hadolint-py
|
||||
rev: v2.15.1
|
||||
hooks:
|
||||
- id: hadolint
|
||||
|
||||
- repo: https://github.com/shellcheck-py/shellcheck-py
|
||||
rev: v0.11.0.1
|
||||
hooks:
|
||||
- id: shellcheck
|
||||
|
||||
# No upstream equivalent: a distro added under distros/ but left out of a
|
||||
# Woodpecker matrix silently never gets built.
|
||||
- repo: local
|
||||
hooks:
|
||||
- id: check-distros
|
||||
name: distros match the woodpecker matrices
|
||||
entry: ci/check-distros.sh
|
||||
language: system
|
||||
pass_filenames: false
|
||||
@@ -0,0 +1,35 @@
|
||||
when:
|
||||
- event: pull_request
|
||||
|
||||
matrix:
|
||||
include:
|
||||
# One entry per distro. Adding a distro: add distros/<name>/ and one entry here.
|
||||
- DISTRO: alma9
|
||||
BASE_IMAGE_NAME: almalinux9
|
||||
TAG_SUFFIX: alma9
|
||||
DEFAULT: "true"
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
image: "artifactapi.k8s.syd1.au.unkin.net/docker-internal/plugin-docker-buildx:latest"
|
||||
settings:
|
||||
# registry is what gets the internal CA into the buildkit container: the plugin
|
||||
# writes a buildkit.toml pointing at /etc/docker/certs.d/<registry>/ca.crt only
|
||||
# when it is set. The plugin has no buildkit_config setting.
|
||||
registry: artifactapi.k8s.syd1.au.unkin.net
|
||||
repo: "artifactapi.k8s.syd1.au.unkin.net/docker-internal/gobuilder"
|
||||
target: image
|
||||
dry_run: true
|
||||
build_args:
|
||||
BASE_IMAGE_NAME: "${BASE_IMAGE_NAME}"
|
||||
DISTRO: "${DISTRO}"
|
||||
backend_options:
|
||||
kubernetes:
|
||||
serviceAccountName: default
|
||||
resources:
|
||||
requests:
|
||||
memory: 1Gi
|
||||
cpu: 1
|
||||
limits:
|
||||
memory: 4Gi
|
||||
cpu: 2
|
||||
@@ -0,0 +1,63 @@
|
||||
when:
|
||||
- event: tag
|
||||
ref: refs/tags/v*
|
||||
|
||||
matrix:
|
||||
include:
|
||||
# One entry per distro. Adding a distro: add distros/<name>/ and one entry here.
|
||||
- DISTRO: alma9
|
||||
BASE_IMAGE_NAME: almalinux9
|
||||
TAG_SUFFIX: alma9
|
||||
DEFAULT: "true"
|
||||
|
||||
steps:
|
||||
- name: docker
|
||||
image: "artifactapi.k8s.syd1.au.unkin.net/docker-internal/plugin-docker-buildx:latest"
|
||||
settings:
|
||||
# registry is what gets the internal CA into the buildkit container: the plugin
|
||||
# writes a buildkit.toml pointing at /etc/docker/certs.d/<registry>/ca.crt only
|
||||
# when it is set. The plugin has no buildkit_config setting.
|
||||
registry: artifactapi.k8s.syd1.au.unkin.net
|
||||
repo: "artifactapi.k8s.syd1.au.unkin.net/docker-internal/gobuilder"
|
||||
target: image
|
||||
build_args:
|
||||
BASE_IMAGE_NAME: "${BASE_IMAGE_NAME}"
|
||||
DISTRO: "${DISTRO}"
|
||||
tags:
|
||||
- "${CI_COMMIT_TAG##v}-${TAG_SUFFIX}"
|
||||
backend_options:
|
||||
kubernetes:
|
||||
serviceAccountName: default
|
||||
resources:
|
||||
requests:
|
||||
memory: 1Gi
|
||||
cpu: 1
|
||||
limits:
|
||||
memory: 4Gi
|
||||
cpu: 2
|
||||
|
||||
# The default distro also carries the unsuffixed tags.
|
||||
- name: docker-default
|
||||
image: "artifactapi.k8s.syd1.au.unkin.net/docker-internal/plugin-docker-buildx:latest"
|
||||
when:
|
||||
- evaluate: 'DEFAULT == "true"'
|
||||
settings:
|
||||
registry: artifactapi.k8s.syd1.au.unkin.net
|
||||
repo: "artifactapi.k8s.syd1.au.unkin.net/docker-internal/gobuilder"
|
||||
target: image
|
||||
build_args:
|
||||
BASE_IMAGE_NAME: "${BASE_IMAGE_NAME}"
|
||||
DISTRO: "${DISTRO}"
|
||||
tags:
|
||||
- "${CI_COMMIT_TAG##v}"
|
||||
- latest
|
||||
backend_options:
|
||||
kubernetes:
|
||||
serviceAccountName: default
|
||||
resources:
|
||||
requests:
|
||||
memory: 1Gi
|
||||
cpu: 1
|
||||
limits:
|
||||
memory: 4Gi
|
||||
cpu: 2
|
||||
@@ -0,0 +1,18 @@
|
||||
when:
|
||||
- event: pull_request
|
||||
|
||||
steps:
|
||||
- name: pre-commit
|
||||
image: "git.unkin.net/unkin/almalinux9-gobuilder:20260606"
|
||||
commands:
|
||||
- uvx pre-commit run --all-files
|
||||
backend_options:
|
||||
kubernetes:
|
||||
serviceAccountName: default
|
||||
resources:
|
||||
requests:
|
||||
memory: 512Mi
|
||||
cpu: 1
|
||||
limits:
|
||||
memory: 2Gi
|
||||
cpu: 2
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
ARG REGISTRY=artifactapi.k8s.syd1.au.unkin.net/docker-internal
|
||||
# The container-base release this image is built on — the one place to bump it.
|
||||
ARG BASE_VERSION=0.1.0
|
||||
ARG BASE_IMAGE_NAME=almalinux9
|
||||
|
||||
FROM ${REGISTRY}/${BASE_IMAGE_NAME}:${BASE_VERSION} AS image
|
||||
ARG DISTRO=alma9
|
||||
ARG GO_CACHE_PLUGIN_VERSION=v0.1.0
|
||||
ARG GO_CACHE_PLUGIN_SHA256=0eb23d06a0dcf395559cb6447864579c220e60148fdcd6a6f841c2b17169b9b8
|
||||
COPY distros/${DISTRO}/ /tmp/distro/
|
||||
# DL3041: versions are pinned by the estate dnf repos, not here. SC2086: $PACKAGES is a
|
||||
# word list on purpose. DL4006: the only pipe ends in sha256sum, whose status is the
|
||||
# pipeline's, and set -e catches it.
|
||||
# hadolint ignore=DL3041,DL4006,SC2086
|
||||
RUN set -eux; \
|
||||
. /tmp/distro/distro.env; \
|
||||
dnf install -y $PACKAGES; \
|
||||
dnf clean all; \
|
||||
curl -fsSL -o /usr/local/bin/go-cache-plugin \
|
||||
"https://git.unkin.net/unkin/go-cache-plugin/releases/download/${GO_CACHE_PLUGIN_VERSION}/go-cache-plugin-linux-amd64"; \
|
||||
echo "$GO_CACHE_PLUGIN_SHA256 /usr/local/bin/go-cache-plugin" | sha256sum -c -; \
|
||||
chmod 0755 /usr/local/bin/go-cache-plugin; \
|
||||
rm -rf /var/cache/dnf /tmp/distro
|
||||
CMD ["/bin/bash"]
|
||||
@@ -0,0 +1,39 @@
|
||||
REGISTRY := artifactapi.k8s.syd1.au.unkin.net/docker-internal
|
||||
DISTROS := $(notdir $(wildcard distros/*))
|
||||
VERSION ?= $(patsubst v%,%,$(or $(shell git describe --tags --exact-match 2>/dev/null),0.1.0-dev))
|
||||
|
||||
.PHONY: build clean pre-commit patch minor major
|
||||
build: $(addprefix build-,$(DISTROS))
|
||||
clean: $(addprefix clean-,$(DISTROS))
|
||||
|
||||
pre-commit:
|
||||
@uvx pre-commit run --all-files
|
||||
|
||||
# Not .PHONY: GNU make skips implicit-rule search for phony targets.
|
||||
|
||||
build-%:
|
||||
@set -eu; . ./distros/$*/distro.env; \
|
||||
docker build --build-arg "BASE_IMAGE_NAME=$$BASE_IMAGE_NAME" --build-arg "DISTRO=$*" \
|
||||
-t "$(REGISTRY)/$$IMAGE:$(VERSION)-$$TAG_SUFFIX" .
|
||||
|
||||
clean-%:
|
||||
@set -eu; . ./distros/$*/distro.env; \
|
||||
docker rmi "$(REGISTRY)/$$IMAGE:$(VERSION)-$$TAG_SUFFIX" 2>/dev/null || true
|
||||
|
||||
_LATEST := $(shell git tag --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$$' | head -1)
|
||||
_BASE := $(if $(_LATEST),$(_LATEST),v0.0.0)
|
||||
_MAJ := $(shell echo $(_BASE) | sed 's/^v//' | cut -d. -f1)
|
||||
_MIN := $(shell echo $(_BASE) | sed 's/^v//' | cut -d. -f2)
|
||||
_PAT := $(shell echo $(_BASE) | sed 's/^v//' | cut -d. -f3)
|
||||
|
||||
patch:
|
||||
@NEW=v$(_MAJ).$(_MIN).$(shell expr $(_PAT) + 1); \
|
||||
git tag $$NEW && echo "Tagged $$NEW" && git push origin $$NEW
|
||||
|
||||
minor:
|
||||
@NEW=v$(_MAJ).$(shell expr $(_MIN) + 1).0; \
|
||||
git tag $$NEW && echo "Tagged $$NEW" && git push origin $$NEW
|
||||
|
||||
major:
|
||||
@NEW=v$(shell expr $(_MAJ) + 1).0.0; \
|
||||
git tag $$NEW && echo "Tagged $$NEW" && git push origin $$NEW
|
||||
@@ -1,3 +1,30 @@
|
||||
# container-gobuilder
|
||||
|
||||
Go toolchain builder container image, built on each supported container-base distro image, used by Woodpecker pipelines to compile Go projects.
|
||||
The estate's Go toolchain image, built on each `container-base` distro image.
|
||||
Published as `artifactapi.k8s.syd1.au.unkin.net/docker-internal/gobuilder:<version>-<suffix>`;
|
||||
the default distro also gets the unsuffixed `:<version>` and `:latest`.
|
||||
|
||||
| distro | from | tag suffix | default |
|
||||
| --- | --- | --- | --- |
|
||||
| `alma9` | `docker-internal/almalinux9:<base version>` | `alma9` | yes |
|
||||
|
||||
Adds `golang`, `gcc` and `nfpm`, and bakes in the `go-cache-plugin` binary on `PATH`
|
||||
so Go pipelines get the shared build cache with no download step. No credentials and no
|
||||
`GOCACHEPROG` value are baked in — consumers set those.
|
||||
|
||||
The `container-base` release this image builds on is `BASE_VERSION` in the `Dockerfile`.
|
||||
|
||||
## Adding a distro
|
||||
|
||||
1. `distros/<name>/distro.env` — `BASE_IMAGE_NAME`, `IMAGE`, `TAG_SUFFIX`, `DEFAULT`, `PACKAGES`, `GO_MIN`.
|
||||
2. One `include` entry in each of `.woodpecker/{build,docker}.yaml`.
|
||||
|
||||
The `check-distros` pre-commit hook fails if step 1 or 2 is incomplete, or if more than
|
||||
one distro claims `DEFAULT`.
|
||||
|
||||
## Make
|
||||
|
||||
make build # build every distro
|
||||
make pre-commit # uvx pre-commit run --all-files
|
||||
make build-alma9 # one distro
|
||||
make patch|minor|major
|
||||
|
||||
Executable
+43
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env bash
|
||||
# Every distros/<name>/ needs a complete distro.env and an entry in every Woodpecker
|
||||
# matrix, or a newly added distro silently never gets built.
|
||||
set -uo pipefail
|
||||
|
||||
KEYS="BASE_IMAGE_NAME IMAGE TAG_SUFFIX DEFAULT ESTATE_REPO PACKAGES GO_MIN"
|
||||
WORKFLOWS=(.woodpecker/build.yaml .woodpecker/docker.yaml)
|
||||
|
||||
fail=0
|
||||
for d in distros/*/; do
|
||||
n=$(basename "$d")
|
||||
for k in $KEYS; do
|
||||
grep -q "^${k}=" "${d}distro.env" || { echo "${d}distro.env: missing ${k}"; fail=1; }
|
||||
done
|
||||
for wf in "${WORKFLOWS[@]}"; do
|
||||
grep -q "DISTRO: ${n}\$" "$wf" || { echo "${wf}: distro ${n} missing from matrix"; fail=1; }
|
||||
|
||||
# A matrix entry that restates a distro.env key must not drift from it — a stale
|
||||
# BASE_IMAGE here silently overrides distro.env for every CI build.
|
||||
while IFS='=' read -r k v; do
|
||||
[ -n "$k" ] || continue
|
||||
grep -q "^${k}=" "${d}distro.env" || continue
|
||||
ev=$(sed -n "s/^${k}=//p" "${d}distro.env" | head -1 | sed 's/^"//;s/"$//')
|
||||
[ "$v" = "$ev" ] || { echo "${wf}: matrix ${k}=\"${v}\" for ${n} disagrees with ${d}distro.env (\"${ev}\")"; fail=1; }
|
||||
done <<EOF
|
||||
$(awk -v d="$n" '
|
||||
$0 ~ "^[[:space:]]*-[[:space:]]+DISTRO:[[:space:]]*"d"[[:space:]]*$" { inb=1; next }
|
||||
inb && /^[[:space:]]*-/ { inb=0 }
|
||||
inb && match($0, /^[[:space:]]+[A-Z_]+:/) {
|
||||
k=$1; sub(/:$/,"",k)
|
||||
v=$0; sub(/^[[:space:]]*[A-Z_]+:[[:space:]]*/,"",v); gsub(/^"|"$/,"",v)
|
||||
print k "=" v
|
||||
}
|
||||
' "$wf")
|
||||
EOF
|
||||
done
|
||||
done
|
||||
|
||||
# Exactly one distro owns the unsuffixed :<version> and :latest tags.
|
||||
defaults=$(grep -l 'DEFAULT="true"' distros/*/distro.env | wc -l)
|
||||
[ "$defaults" -eq 1 ] || { echo "expected exactly one distro with DEFAULT=\"true\", found ${defaults}"; fail=1; }
|
||||
|
||||
exit "$fail"
|
||||
@@ -0,0 +1,12 @@
|
||||
# alma9 — built on the container-base almalinux9 image
|
||||
BASE_IMAGE_NAME="almalinux9"
|
||||
IMAGE="gobuilder"
|
||||
TAG_SUFFIX="alma9"
|
||||
# The default distro also gets the unsuffixed :<version> and :latest tags.
|
||||
DEFAULT="true"
|
||||
|
||||
# Estate local repo used to prove inherited HTTPS trust.
|
||||
ESTATE_REPO="rpm-vendor-el9"
|
||||
|
||||
PACKAGES="golang gcc nfpm"
|
||||
GO_MIN="1.24"
|
||||
Reference in New Issue
Block a user