feat(deploy): warn when the Docker build context is unexpectedly large#4943
Open
robgough wants to merge 1 commit into
Open
feat(deploy): warn when the Docker build context is unexpectedly large#4943robgough wants to merge 1 commit into
robgough wants to merge 1 commit into
Conversation
Large build contexts are uploaded to the builder on every deploy before the image build starts, so an accidental omission from .dockerignore (a cache or tooling directory) can silently make deploys much slower. flyctl already walks the working directory and applies .dockerignore to build the context, so this adds a cheap, stat-only pass over the same files that warns when the context exceeds a threshold and lists the largest paths. The threshold defaults to 100 MB and is tunable per build with --build-context-warn-size or globally with FLY_BUILD_CONTEXT_WARN_SIZE (0 disables). Best-effort: it never blocks a deploy. https://community.fly.io/t/feature-request-warn-or-require-an-override-when-the-docker-build-context-is-unexpectedly-large/28163
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
fly deploynow prints a warning when the Docker build context it is about toupload to the builder is unexpectedly large, and lists the largest paths so you
can spot anything that should be in
.dockerignore.Example:
Why
I recently had deploys that were mysteriously slow. The cause turned out to be a
.dockerignorethat was missing some large folders (Playwright browsers andassorted tool caches), so ~1.3 GB of context was being uploaded to the builder
on every deploy before the image build even started. Adding the missing entries
fixed it immediately.
flyctlalready walks the working directory and applies.dockerignoreto sendthe context, so it is well placed to gently point out when a context is far
larger than you probably intended — before you sit through the slow transfer.
Discussion: https://community.fly.io/t/feature-request-warn-or-require-an-override-when-the-docker-build-context-is-unexpectedly-large/28163
How
internal/build/imgsrc/context_size.gowalks the build context applyingthe same
.dockerignorerules used when building (including parent-dir matchesand negated re-includes, mirroring
docker/pkg/archive), and sums the largesttop-level paths. It only
stats files (never reads them) and prunes ignoreddirectories, so the cost is bounded by the context it is warning about.
Resolver.BuildImagecalls it once, up front, for Dockerfile builds.--build-context-warn-sizeflag (also settable viaFLY_BUILD_CONTEXT_WARN_SIZE) on every command that builds from a Dockerfile —deploy,launch,machine run,machine update,console— so the warningcan be tuned or turned off (
--build-context-warn-size 0). It follows theexisting
*-sizeflag convention (swap-size,rootfs-size, …): aStringparsed with
helpers.ParseSize, accepting a plain number (MB) or ahuman-readable size like
512mb/1gb.Design notes / things I'd love feedback on:
(unreadable dir, etc.) silently skips the check so a deploy is never blocked or
meaningfully slowed by it. The thread floated optionally requiring an
override — happy to add a stricter mode, but a warning felt like the right
default to start with.
--build-context-warn-sizeor globally withFLY_BUILD_CONTEXT_WARN_SIZE, anddisabled by setting either to
0. I'm genuinely unsure 100 MB is the rightnumber — I took it from the figure in the thread, but folks who've seen far
more app setups than I have will have a much better sense of what counts as
"normal" versus genuinely surprising. The main thing I want to avoid is the
warning firing so often on legitimately-sized contexts that people reflexively
set it to
0and forget about it — at which point it's worse than useless. SoI'd lean towards erring high if in doubt, and I'd really value your read on a
sensible default (or a smarter heuristic than a flat byte count).
.dockerignore-filtered context. Buildpacks/builtins/custom builders managetheir own context and are skipped. Could be extended later.
Testing
internal/build/imgsrc/context_size_test.gocover the sizetotals, largest-path ordering,
.dockerignoreexclusion, nested-directoryaggregation, negated re-includes, and flag/env threshold precedence.
go test ./internal/build/imgsrc/...andgolangci-lint runboth pass.