Skip to content

Commit 51788be

Browse files
ericallamTrigger.dev RepoOps
authored andcommitted
chore(docker): rebuild the apt upgrade layers on every webapp image publish
chore(docker): rebuild the apt upgrade layers on every webapp image publish The webapp Dockerfile upgrades OS packages with `apt-get upgrade` in three stages, but those layers had no changing input, so the build cache reused them for months and the published image kept known-fixed CVEs. A new `APT_REFRESH` build arg, set by the publish workflow to the build timestamp, is referenced ahead of each upgrade so the layers rebuild on every publish. The layers below them (dependency install, the webapp build) still cache as before. Also pins the node base image to its multi-platform index digest instead of the architecture-oriented one. Same image content, no behaviour change. Mono-RevId: 156d96fdb686a73b5a8af56668344a64fdf7e7a6
1 parent f73ad96 commit 51788be

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

‎.github/workflows/publish-webapp.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ jobs:
131131
BUILD_GIT_REF_NAME=${{ steps.set_build_info.outputs.BUILD_GIT_REF_NAME }}
132132
BUILD_TIMESTAMP_SECONDS=${{ steps.set_build_info.outputs.BUILD_TIMESTAMP_SECONDS }}
133133
BUILD_TIMESTAMP_RFC3339=${{ steps.set_build_info.outputs.BUILD_TIMESTAMP_RFC3339 }}
134+
APT_REFRESH=${{ steps.set_build_info.outputs.BUILD_TIMESTAMP_RFC3339 }}
134135
SENTRY_RELEASE=${{ steps.set_build_info.outputs.BUILD_GIT_SHA }}
135136
SENTRY_ORG=triggerdev
136137
SENTRY_PROJECT=trigger-cloud

‎docker/Dockerfile‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
ARG NODE_IMAGE=node:24.18.0-bookworm-slim@sha256:39a4259b6f744868a8228742ad45aa3026f97302e5eec2fa4a38b30ca0a66e12
1+
ARG NODE_IMAGE=node:24.18.0-bookworm-slim@sha256:6f7b03f7c2c8e2e784dcf9295400527b9b1270fd37b7e9a7285cf83b6951452d
2+
# OS security patches come from apt, not from the node image, and the node image
3+
# rarely changes. Without a changing input the upgrade layers below stay cached
4+
# for months and ship known-fixed CVEs. Every workflow that publishes this image
5+
# sets this to the build timestamp so those layers rebuild on each publish. A
6+
# local `docker build` or compose build leaves it unset and caches as usual.
7+
ARG APT_REFRESH=unset
28

39
FROM golang:1.26-alpine AS goose_builder
410
RUN go install github.com/pressly/goose/v3/cmd/goose@v3.27.1
@@ -13,7 +19,8 @@ RUN find . -name "node_modules" -type d -prune -exec rm -rf '{}' +
1319

1420
# Base strategy to have layer caching
1521
FROM ${NODE_IMAGE} AS base
16-
RUN apt-get update && apt-get upgrade -y && apt-get install -y --no-install-recommends openssl dumb-init && rm -rf /var/lib/apt/lists/*
22+
ARG APT_REFRESH
23+
RUN echo "apt refresh ${APT_REFRESH}" && apt-get update && apt-get upgrade -y && apt-get install -y --no-install-recommends openssl dumb-init && rm -rf /var/lib/apt/lists/*
1724
WORKDIR /triggerdotdev
1825
COPY --chown=node:node .gitignore .gitignore
1926
COPY --from=pruner --chown=node:node /triggerdotdev/out/json/ .
@@ -45,7 +52,8 @@ RUN --mount=type=cache,id=pnpm,target=/root/.local/share/pnpm/store pnpm install
4552
## Builder (builds the webapp)
4653
FROM base AS builder
4754
# This is needed for the sentry-cli binary while building the webapp
48-
RUN apt-get update && apt-get upgrade -y && apt-get install -y --no-install-recommends openssl dumb-init ca-certificates && rm -rf /var/lib/apt/lists/*
55+
ARG APT_REFRESH
56+
RUN echo "apt refresh ${APT_REFRESH}" && apt-get update && apt-get upgrade -y && apt-get install -y --no-install-recommends openssl dumb-init ca-certificates && rm -rf /var/lib/apt/lists/*
4957
WORKDIR /triggerdotdev
5058
# Corepack is used to install pnpm with the exact version from packageManager
5159
RUN corepack enable && corepack prepare pnpm@10.33.2 --activate
@@ -79,7 +87,8 @@ RUN --mount=type=secret,id=sentry_auth_token \
7987

8088
# Runner
8189
FROM ${NODE_IMAGE} AS runner
82-
RUN apt-get update && apt-get upgrade -y && apt-get install -y --no-install-recommends openssl netcat-openbsd ca-certificates && rm -rf /var/lib/apt/lists/*
90+
ARG APT_REFRESH
91+
RUN echo "apt refresh ${APT_REFRESH}" && apt-get update && apt-get upgrade -y && apt-get install -y --no-install-recommends openssl netcat-openbsd ca-certificates && rm -rf /var/lib/apt/lists/*
8392
WORKDIR /triggerdotdev
8493
ENV NODE_ENV=production
8594

0 commit comments

Comments
 (0)