feat(image): build a CI image with the lint and build tooling baked in #3
No files matched your search
@@ -1,7 +1,8 @@
|
|||||||
name: Molecule image
|
name: Molecule image
|
||||||
|
|
||||||
# Builds images/molecule-ubuntu2404 with kaniko (osscontainertools fork, v1.28.6) and
|
# Builds the images under images/ with kaniko (osscontainertools fork, v1.28.6) and
|
||||||
# pushes it to git.rkdr.net/mortis/molecule-ubuntu2404 (ADR 0004, Image distribution).
|
# pushes them to git.rkdr.net/mortis/<name> (ADR 0004, Image distribution): the molecule
|
||||||
|
# test target (molecule-ubuntu2404) and the lint/build tooling (ci).
|
||||||
#
|
#
|
||||||
# Never on pull_request: a workflow file comes from the PR head, so a fork PR could
|
# Never on pull_request: a workflow file comes from the PR head, so a fork PR could
|
||||||
# otherwise push to the registry. This workflow has no pull_request trigger, and the job
|
# otherwise push to the registry. This workflow has no pull_request trigger, and the job
|
||||||
@@ -30,7 +31,10 @@ on: # yamllint disable-line rule:truthy
|
|||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
paths:
|
paths:
|
||||||
- 'images/molecule-ubuntu2404/**'
|
- 'images/**'
|
||||||
|
# The ci image bakes these two files' contents in (images/ci/Dockerfile).
|
||||||
|
- 'requirements-dev.txt'
|
||||||
|
- '.pre-commit-config.yaml'
|
||||||
- '.gitea/workflows/image.yml'
|
- '.gitea/workflows/image.yml'
|
||||||
tags:
|
tags:
|
||||||
- 'v*'
|
- 'v*'
|
||||||
@@ -53,13 +57,26 @@ jobs:
|
|||||||
(github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
|
(github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
|
||||||
runs-on: kamino-docker
|
runs-on: kamino-docker
|
||||||
timeout-minutes: 45
|
timeout-minutes: 45
|
||||||
|
# One job at a time on the single-capacity runner. An empty subpath means the
|
||||||
|
# repository root is the build context.
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
max-parallel: 1
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- name: molecule-ubuntu2404
|
||||||
|
subpath: images/molecule-ubuntu2404
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
- name: ci
|
||||||
|
subpath: ""
|
||||||
|
dockerfile: images/ci/Dockerfile
|
||||||
container:
|
container:
|
||||||
image: ubuntu:24.04@sha256:68ee22004a9109b44973313b02ff7b1de250f1de0f5ecb628d73f579aaff33ac
|
image: ubuntu:24.04@sha256:68ee22004a9109b44973313b02ff7b1de250f1de0f5ecb628d73f579aaff33ac
|
||||||
# Keeps a runaway build from taking the whole 3 GB runner LXC down with it.
|
# Keeps a runaway build from taking the whole 3 GB runner LXC down with it.
|
||||||
options: --memory=2g --memory-swap=2g
|
options: --memory=2g --memory-swap=2g
|
||||||
env:
|
env:
|
||||||
DEBIAN_FRONTEND: noninteractive
|
DEBIAN_FRONTEND: noninteractive
|
||||||
IMAGE_PATH: mortis/molecule-ubuntu2404
|
IMAGE_PATH: mortis/${{ matrix.name }}
|
||||||
steps:
|
steps:
|
||||||
# A tag becomes the image tag. OCI tags cannot contain '+' (semver build metadata),
|
# A tag becomes the image tag. OCI tags cannot contain '+' (semver build metadata),
|
||||||
# and the trigger glob `v*` also matches names like `vfoo`: refuse both before
|
# and the trigger glob `v*` also matches names like `vfoo`: refuse both before
|
||||||
@@ -218,6 +235,8 @@ jobs:
|
|||||||
REF: ${{ github.ref }}
|
REF: ${{ github.ref }}
|
||||||
REF_NAME: ${{ github.ref_name }}
|
REF_NAME: ${{ github.ref_name }}
|
||||||
SHA: ${{ github.sha }}
|
SHA: ${{ github.sha }}
|
||||||
|
SUBPATH: ${{ matrix.subpath }}
|
||||||
|
DOCKERFILE: ${{ matrix.dockerfile }}
|
||||||
run: |
|
run: |
|
||||||
set +x
|
set +x
|
||||||
set -eu
|
set -eu
|
||||||
@@ -235,7 +254,10 @@ jobs:
|
|||||||
esac
|
esac
|
||||||
|
|
||||||
# Context: this commit of this repository, cloned by kaniko (#<ref>#<sha>:
|
# Context: this commit of this repository, cloned by kaniko (#<ref>#<sha>:
|
||||||
# clone <ref>, check out <sha>). The Dockerfile has no COPY, so only it is read.
|
# clone <ref>, check out <sha>). With a sub-path only that directory is the
|
||||||
|
# context (molecule image: its Dockerfile has no COPY).
|
||||||
|
ctx=(--dockerfile "$DOCKERFILE")
|
||||||
|
if [ -n "$SUBPATH" ]; then ctx+=(--context-sub-path "$SUBPATH"); fi
|
||||||
#
|
#
|
||||||
# When it finishes the executor has replaced the job container's filesystem with
|
# When it finishes the executor has replaced the job container's filesystem with
|
||||||
# the built image and removed /kaniko, so nothing written there (a --digest-file,
|
# the built image and removed /kaniko, so nothing written there (a --digest-file,
|
||||||
@@ -250,8 +272,7 @@ jobs:
|
|||||||
esac
|
esac
|
||||||
done < <(/kaniko/executor \
|
done < <(/kaniko/executor \
|
||||||
--context "git://${registry}/${REPO}.git#${REF}#${SHA}" \
|
--context "git://${registry}/${REPO}.git#${REF}#${SHA}" \
|
||||||
--context-sub-path images/molecule-ubuntu2404 \
|
"${ctx[@]}" \
|
||||||
--dockerfile Dockerfile \
|
|
||||||
"${dests[@]}" \
|
"${dests[@]}" \
|
||||||
--snapshot-mode=redo \
|
--snapshot-mode=redo \
|
||||||
--cache=false \
|
--cache=false \
|
||||||
@@ -267,7 +288,7 @@ jobs:
|
|||||||
echo "Pinned reference: ${image}@${digest}"
|
echo "Pinned reference: ${image}@${digest}"
|
||||||
if [ -n "${GITHUB_STEP_SUMMARY:-}" ]; then
|
if [ -n "${GITHUB_STEP_SUMMARY:-}" ]; then
|
||||||
{
|
{
|
||||||
echo "### molecule-ubuntu2404 pushed"
|
echo "### ${IMAGE_PATH} pushed"
|
||||||
echo
|
echo
|
||||||
echo "Pin it by digest: \`${image}@${digest}\`"
|
echo "Pin it by digest: \`${image}@${digest}\`"
|
||||||
} >> "$GITHUB_STEP_SUMMARY" || true
|
} >> "$GITHUB_STEP_SUMMARY" || true
|
||||||
|
|||||||
@@ -0,0 +1,107 @@
|
|||||||
|
# CI image for the Lint and Build workflows of this Collection: every tool they used
|
||||||
|
# to install on each run is baked in, so a job only checks out the code and runs.
|
||||||
|
#
|
||||||
|
# Built by .gitea/workflows/image.yml with kaniko (repository root as build context,
|
||||||
|
# because the pin files below are copied in) and pushed, never on pull requests, to
|
||||||
|
# git.rkdr.net/mortis/ci. Workflows reference it by digest:
|
||||||
|
#
|
||||||
|
# container:
|
||||||
|
# image: git.rkdr.net/mortis/ci@sha256:<digest>
|
||||||
|
#
|
||||||
|
# What is baked in, and from where:
|
||||||
|
# - OS packages: git, shellcheck (actionlint runs it over run: blocks), Python 3.12
|
||||||
|
# (the distribution's) and ca-certificates.
|
||||||
|
# - /opt/venv: requirements-dev.txt (ansible-core, ansible-lint, pre-commit,
|
||||||
|
# antsibull-changelog, galaxy-importer, reuse).
|
||||||
|
# - /opt/pre-commit: every hook environment of .pre-commit-config.yaml, installed by
|
||||||
|
# `pre-commit install-hooks` (gitleaks and actionlint are built from source by
|
||||||
|
# pre-commit, which downloads a Go toolchain: that is most of the time saved).
|
||||||
|
# - Python 3.11 and 3.13 as python3.11 / python3.13 on PATH, so that
|
||||||
|
# `ansible-test sanity` runs its compile test for them instead of skipping it.
|
||||||
|
# They come from python-build-standalone through uv, pinned by the uv version.
|
||||||
|
# - /opt/ci-pins.sha256: the checksums of requirements-dev.txt and
|
||||||
|
# .pre-commit-config.yaml this image was built from. A job runs
|
||||||
|
# `sha256sum -c /opt/ci-pins.sha256` in its checkout; when a pull request changes a
|
||||||
|
# pin the check fails and the job installs the tools as before, until the image
|
||||||
|
# is rebuilt from main.
|
||||||
|
#
|
||||||
|
# Layers: each COPY / RUN below is one layer, and a layer is pushed as one request,
|
||||||
|
# so it must stay below Cloudflare's 100 MB request-body limit on git.rkdr.net. The
|
||||||
|
# build stage prints the sizes it will copy; the first push is the real test.
|
||||||
|
# Base image: ubuntu:24.04 index digest as of 2026-10-24 (24.04.5), same as the
|
||||||
|
# molecule image.
|
||||||
|
|
||||||
|
FROM ubuntu:24.04@sha256:68ee22004a9109b44973313b02ff7b1de250f1de0f5ecb628d73f579aaff33ac AS os
|
||||||
|
|
||||||
|
ENV DEBIAN_FRONTEND=noninteractive
|
||||||
|
|
||||||
|
# No python3-pip: tools are installed with the venv's own pip. python3-venv brings
|
||||||
|
# ensurepip. apt lists are removed in the same layer.
|
||||||
|
RUN apt-get update \
|
||||||
|
&& apt-get install -y --no-install-recommends \
|
||||||
|
ca-certificates git python3 python3-venv shellcheck \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
|
||||||
|
FROM os AS build
|
||||||
|
|
||||||
|
ENV PIP_DISABLE_PIP_VERSION_CHECK=1 \
|
||||||
|
PIP_NO_CACHE_DIR=1 \
|
||||||
|
PRE_COMMIT_HOME=/opt/pre-commit \
|
||||||
|
UV_PYTHON_INSTALL_DIR=/opt/python \
|
||||||
|
UV_PYTHON_BIN_DIR=/opt/python-bin
|
||||||
|
|
||||||
|
WORKDIR /src
|
||||||
|
COPY requirements-dev.txt .pre-commit-config.yaml ./
|
||||||
|
|
||||||
|
RUN python3 -m venv /opt/venv \
|
||||||
|
&& /opt/venv/bin/pip install -r requirements-dev.txt
|
||||||
|
|
||||||
|
# uv only lives in the build stage (its own venv): the final image keeps the
|
||||||
|
# interpreters it downloaded, not the installer.
|
||||||
|
RUN python3 -m venv /opt/uv-venv \
|
||||||
|
&& /opt/uv-venv/bin/pip install uv==0.13.5 \
|
||||||
|
&& /opt/uv-venv/bin/uv python install 3.11 3.13
|
||||||
|
|
||||||
|
# pre-commit needs a git repository to resolve a config. The hook repositories are
|
||||||
|
# cloned and built into PRE_COMMIT_HOME, keyed by repository URL and revision, so
|
||||||
|
# the cache is found from any checkout. The yamllint run proves the cache is usable
|
||||||
|
# and complete (a missing environment would be rebuilt, which needs the network).
|
||||||
|
RUN git init -q /tmp/hooks \
|
||||||
|
&& cp .pre-commit-config.yaml /tmp/hooks/ \
|
||||||
|
&& cd /tmp/hooks \
|
||||||
|
&& /opt/venv/bin/pre-commit install-hooks \
|
||||||
|
&& printf -- '---\nkey: value\n' > ok.yaml \
|
||||||
|
&& git add ok.yaml \
|
||||||
|
&& /opt/venv/bin/pre-commit run yamllint --all-files \
|
||||||
|
&& rm -rf /root/.cache/go-build /tmp/hooks \
|
||||||
|
&& find /opt/pre-commit -maxdepth 1 -mindepth 1 -exec du -sh {} + | sort -h \
|
||||||
|
&& du -sh /opt/venv /opt/python /opt/pre-commit
|
||||||
|
|
||||||
|
|
||||||
|
FROM os AS final
|
||||||
|
|
||||||
|
LABEL org.opencontainers.image.title="ci" \
|
||||||
|
org.opencontainers.image.description="Lint and build tooling for mortis.kamino, baked in" \
|
||||||
|
org.opencontainers.image.source="https://git.rkdr.net/mortis/kamino" \
|
||||||
|
org.opencontainers.image.licenses="GPL-3.0-or-later"
|
||||||
|
|
||||||
|
ENV PIP_DISABLE_PIP_VERSION_CHECK=1 \
|
||||||
|
PRE_COMMIT_HOME=/opt/pre-commit \
|
||||||
|
PATH=/opt/venv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||||
|
|
||||||
|
COPY --from=build /opt/venv /opt/venv
|
||||||
|
COPY --from=build /opt/python /opt/python
|
||||||
|
COPY --from=build /opt/pre-commit /opt/pre-commit
|
||||||
|
|
||||||
|
# The target interpreters ansible-test looks for on PATH, and the pin record.
|
||||||
|
COPY --from=build /src/requirements-dev.txt /src/.pre-commit-config.yaml /opt/ci-pins/
|
||||||
|
RUN for v in 3.11 3.13; do \
|
||||||
|
ln -s "$(echo /opt/python/cpython-${v}.*/bin/python${v})" "/usr/local/bin/python${v}" \
|
||||||
|
&& "python${v}" --version; \
|
||||||
|
done \
|
||||||
|
&& cd /opt/ci-pins \
|
||||||
|
&& sha256sum requirements-dev.txt .pre-commit-config.yaml > /opt/ci-pins.sha256 \
|
||||||
|
&& ansible --version | head -n1 \
|
||||||
|
&& pre-commit --version \
|
||||||
|
&& shellcheck --version | sed -n 2p
|
||||||
Reference in new issue
Block a user