Skip to content

ci(docker): speed up the image build - #121

Merged
joe4dev merged 1 commit into
mainfrom
speed-up-docker-build
Nov 18, 2026
Merged

joe4dev merged 1 commit into
mainfrom
speed-up-docker-build

Conversation

@joe4dev

@joe4dev joe4dev commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Summary

Follow-up to #97. It cuts the Docker workflow time: main pushes took 35–46 min and PRs 5–27 min, almost all of it in the image build rather than the tests. The CI logs point to four causes, each fixed here.

Cause (from CI logs) Cost Fix
pip install aws-sam-cli snowflake-cli into one venv backtracks: snowflake-cli pins rich==14.0.0, aws-sam-cli needs rich>=14.3.3 100 s amd64, 1080 s arm64 under QEMU; resolves to SAM 1.142.1 and Snowflake CLI 3.16.0 SAM CLI from AWS's official Linux installer, pinned and SHA-256 checked against the release notes; Snowflake CLI alone in its own venv
cache-to: type=gha,mode=max export in smoke 5–19 min, even on runs where every layer was a cache hit Drop the GHA cache from both jobs
Builder stage (yarn install) runs once per platform under QEMU 210 s on arm64 FROM --platform=$BUILDPLATFORM for the builder; dist/ is plain JS
Final RUN printing tool versions comes after COPY dist, so it reruns every commit 63–92 s Each tool layer checks its own version; the final step only checks dist and dockerode
 Dockerfile
-  FROM node:22-bookworm-slim AS builder
+  FROM --platform=$BUILDPLATFORM node:22-bookworm-slim AS builder
-  /opt/venv: pip install aws-sam-cli snowflake-cli   (on PATH)
+  SAM CLI 1.172.1: official installer zip, sha256sum -c
+  /opt/snowflake-cli: pip install snowflake-cli==3.34.0, symlinked to /usr/local/bin/snow
   final RUN: version checks moved into each tool's layer
 docker.yml
-  cache-from: type=gha / cache-to: type=gha,mode=max   (smoke and push)

Snowflake's official .deb was tried first and rejected: it is a PyApp binary that unpacks about 400 MB of Python into $HOME on first run. That doubled the image, and every non-root session unpacked it again.

Evidence

Uncached local builds on an Apple Silicon Mac (Docker Desktop; amd64 is emulated):

main (after #97) This PR
Tool install step, amd64 (emulated) 217 s 45 s
Full build, amd64 (emulated) 307 s 124 s
Tool install step, arm64 (native) 72 s 46 s
Full build, arm64 (native) 106–121 s 117 s (download times dominate)
Image, uncompressed (arm64 / amd64) 865 / 853 MB 958 / 945 MB
Image, gzip of docker save (arm64 / amd64) 254 / 260 MB 320 / 325 MB
Versions SAM 1.142.1, Snowflake CLI 3.16.0 SAM 1.172.1, Snowflake CLI 3.34.0
snow --version 1.0 s 1.4 s

Same behaviour on both images:

  • sam build succeeds for a python3.11 function with a requests dependency and a nodejs22.x function with lodash. pip install --target is exempt from PEP 668, so dropping the shared venv from PATH changes nothing here.
  • snow --version works as root, as --user 1000, and with --read-only.
  • tests/docker/validate-image.mjs with the CI smoke settings: tools/list exposes all 15 tools.

Local Docker Desktop emulation is much faster than QEMU on GitHub runners, so the arm64 push job should gain more than the table shows. This PR's smoke job gives the real CI numbers; the multi-arch push job only runs on main.

Not run locally: the integration test with real Terraform and CDK deploys. This PR's smoke job runs it.

Merge Danger

Door: two-way

Blast Radius: Docker image users, CI

  • Image size: +66 MB compressed per pull, because SAM's installer bundles its own Python (about 200 MB uncompressed).
  • python3/pip in the image are now Debian's, not a venv's. Only people who extend the image with FROM and pip install into it notice. python3-venv stays installed.
  • No build cache: every run builds from scratch, which measured faster than exporting the cache. Fork PRs lose nothing; they could not write the cache anyway.
  • Snowflake CLI dependencies are unpinned beyond snowflake-cli==3.34.0, as before. A hashed lockfile is a possible follow-up.
  • Version bumps are manual. Dependabot does not read the SAM_CLI_* / SNOWFLAKE_CLI_VERSION ARGs. A Renovate regex manager or a bump script is a possible follow-up, as is building arm64 on native ubuntu-24.04-arm runners instead of QEMU.

🤖 Generated with Claude Code

@joe4dev
joe4dev changed the base branch from update-docker-image to main November 18, 2026 12:45
- Install SAM CLI from its official installer (pinned, SHA-256 checked) and
  Snowflake CLI into its own venv. Sharing one venv made pip backtrack over
  conflicting `rich` pins (100 s amd64, 18 min arm64 under QEMU) and pick
  SAM 1.142.1 and Snowflake CLI 3.16.0.
- Build the JS builder stage on $BUILDPLATFORM, so multi-arch builds compile
  dist/ once instead of once per platform under QEMU.
- Check each tool's version in its own layer instead of in a final step that
  reran on every commit.
- Drop the GHA build cache: exporting it took 5-19 min per smoke run, even
  when every layer was a cache hit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@joe4dev
joe4dev force-pushed the speed-up-docker-build branch from 6275a0b to 0dd5332 Compare November 18, 2026 12:46
@joe4dev
joe4dev marked this pull request as ready for review November 18, 2026 13:04
@joe4dev
joe4dev merged commit 9ec1847 into main Nov 18, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant