ci(container): rebuild the apt-get upgrade layer at least weekly
Secret Scan / scan (push) Successful in 4s
Build App (Preview) / compute-version (pull_request) Successful in 5s
Build STT Container / build-stt-container (pull_request) Failing after 4m10s
Secret Scan / scan (pull_request) Successful in 5s
Build App (Preview) / create-release (pull_request) Successful in 2s
Build App (Preview) / test (pull_request) Successful in 5m51s
Build App (Preview) / build-macos (pull_request) Successful in 3m17s
Build App (Preview) / build-windows (pull_request) Successful in 6m42s
Build App (Preview) / build-linux (pull_request) Failing after 9m8s
Build App (Preview) / prune-previews (pull_request) Skipped
Build Container / build-container (pull_request) Successful in 22m17s

CI builds with cache-from: type=gha, so the apt-get upgrade layer was
reused until the base digest or the layer text changed, and security
fixes published since then never reached the image. The RUN now uses an
APT_REFRESH build arg, which build.yml sets to the ISO week, and a weekly
schedule trigger rebuilds without a commit. Publishing is gated on
event_name != 'pull_request' so the scheduled run (always on main)
publishes and PR runs still only validate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shadowdaoandClaude Opus 5.5 committed 2026-11-02 10:49:43 -08:00
1 parent c3f62f96ef
commit 17f3863be3
3 files changed
+80 -5

No files matched your search

+16 -1
View File
@@ -11,6 +11,11 @@ on:
paths:
- "container/**"
- ".gitea/workflows/build.yml"
# Weekly rebuild with no commit needed, so OS security fixes published since
# the last push reach the image (see APT_REFRESH in container/Dockerfile).
# Scheduled runs use the default branch, i.e. main.
schedule:
- cron: "17 4 * * 1"
env:
REGISTRY: repo.anhonesthost.net
@@ -64,13 +69,23 @@ jobs:
username: shadowdao
password: ${{ secrets.GH_PAT }}
# Changes once a week, which invalidates the cached `apt-get upgrade`
# layer (container/Dockerfile) so later security fixes are picked up.
- name: Compute the apt refresh stamp
id: apt
run: echo "stamp=$(date -u +%G-W%V)" >> $GITHUB_OUTPUT
- name: Build and push container image
uses: docker/build-push-action@v5
with:
context: ./container
file: ./container/Dockerfile
platforms: linux/amd64,linux/arm64
push: ${{ gitea.event_name == 'push' }}
# Publish from main pushes and the weekly scheduled rebuild (which
# runs on main); a pull_request run only validates.
push: ${{ gitea.event_name != 'pull_request' }}
build-args: |
APT_REFRESH=${{ steps.apt.outputs.stamp }}
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ gitea.sha }}
+51
View File
@@ -339,3 +339,54 @@ mod tests {
assert_eq!(read(&dest.join("config.d/work")), "Host work");
}
}
#[cfg(test)]
mod apt_refresh_tests {
use super::DOCKERFILE;
const BUILD_WORKFLOW: &str = include_str!("../../../../.gitea/workflows/build.yml");
/// The `RUN` instruction (with its `\` continuations) that contains `needle`.
fn run_containing(needle: &str) -> String {
let mut run = String::new();
let mut current = String::new();
for line in DOCKERFILE.lines() {
if line.starts_with("RUN ") {
current.clear();
}
current.push_str(line);
current.push('\n');
if !line.trim_end().ends_with('\\') {
if current.contains(needle) && current.starts_with("RUN ") {
run = current.clone();
}
current.clear();
}
}
run
}
/// CI builds with `cache-from: type=gha`, so the `apt-get upgrade` layer is
/// only re-run when its cache key changes. An ARG changes a RUN's key only
/// where it is *used*, so the upgrade's RUN must reference it, after an
/// `ARG APT_REFRESH` declared in its stage.
#[test]
fn the_apt_upgrade_layer_is_keyed_on_apt_refresh() {
let arg = DOCKERFILE.find("\nARG APT_REFRESH").expect("ARG APT_REFRESH declared");
let run = run_containing("upgrade -y");
assert!(!run.is_empty(), "no RUN with apt-get upgrade");
assert!(DOCKERFILE.find(&run).unwrap() > arg, "ARG must come before the RUN");
assert!(run.contains("${APT_REFRESH"), "RUN must use APT_REFRESH: {run}");
}
/// …and CI must actually pass a value that changes at least weekly, and
/// rebuild on a schedule so a week with no commits still gets the fixes.
#[test]
fn ci_passes_a_weekly_apt_refresh_and_rebuilds_on_a_schedule() {
assert!(BUILD_WORKFLOW.contains("APT_REFRESH=${{ steps.apt.outputs.stamp }}"));
assert!(BUILD_WORKFLOW.contains("date -u +%G-W%V"));
assert!(BUILD_WORKFLOW.contains("schedule:"));
// A scheduled run must publish, a PR run must not.
assert!(BUILD_WORKFLOW.contains("push: ${{ gitea.event_name != 'pull_request' }}"));
}
}
+13 -4
View File
@@ -35,13 +35,20 @@ ENV DEBIAN_FRONTEND=noninteractive
# base tag stays out of this image until the next refresh. Packages the later
# layers install come straight from the archive, so this one upgrade is enough.
#
# Note CI builds with `cache-from: type=gha`, so this layer (and everything
# after it) only re-runs when the base digest or this layer's text changes.
# CI builds with `cache-from: type=gha`, so this layer (and everything after
# it) only re-runs when its cache key changes: the base digest, this layer's
# text, or `APT_REFRESH`. CI sets that to the ISO week (`2026-W45`) and also
# rebuilds weekly on a schedule, so a security fix published after the last
# commit is in the image within a week. An ARG only changes the key of a RUN
# that uses it, hence the `echo`. Local builds leave it empty.
#
# Scanned on 2026-11-02, the published image of 2026-10-16 carried
# libbrotli1 1.1.0-2build2 (CVE-2026-111497, HIGH) and zlib1g 1.3.dfsg-3.1ubuntu2.2
# (CVE-2026-85091), both with fixed versions in the archive, and pnpm's bundled
# undici 6.29.0 (three HIGH CVEs, fixed in the pnpm 12.16.1 a rebuild installs).
RUN for i in 1 2 3 4 5; do \
ARG APT_REFRESH=
RUN echo "apt refresh: ${APT_REFRESH:-unset}" \
&& for i in 1 2 3 4 5; do \
apt-get -o Acquire::Retries=3 update && break; \
echo "apt-get update failed (attempt $i), retrying in 10s..."; \
rm -rf /var/lib/apt/lists/*; \
@@ -288,7 +295,9 @@ RUN npx --yes playwright@latest --version \
&& rm -rf /var/lib/apt/lists/* /root/.npm
# ── Python 3 + pip + uv + ruff ──────────────────────────────────────────────
RUN for i in 1 2 3 4 5; do \
ARG APT_REFRESH=
RUN echo "apt refresh: ${APT_REFRESH:-unset}" \
&& for i in 1 2 3 4 5; do \
apt-get -o Acquire::Retries=3 update && break; \
echo "apt-get update failed (attempt $i), retrying in 10s..."; \
rm -rf /var/lib/apt/lists/*; \