Skip to content

fix(infra): fix backend Docker build cache invalidation and missing .dockerignore - #259

Merged
parthrohit22 merged 2 commits into
Second-Origin:devfrom
parthrohit22:fix/258-docker-build-cache
Aug 7, 2026
Merged

fix(infra): fix backend Docker build cache invalidation and missing .dockerignore#259
parthrohit22 merged 2 commits into
Second-Origin:devfrom
parthrohit22:fix/258-docker-build-cache

Conversation

@parthrohit22

Copy link
Copy Markdown
Collaborator

Summary

`npm run partha` was slow on every run and could fail outright with `ENOSPC` under Colima. Root-caused to two fixable defects in `apps/backend/` (a third, unfixable-from-the-repo cause — the local Colima VM disk filling up — is documented in #258 but out of scope for a code change).

Linked issue

Closes #258

Roadmap alignment

This is infrastructure/developer-experience hygiene, not a product capability — it doesn't map onto a §23/§28 citation, same as #257 (the dependency-audit fix). Flagging honestly rather than forcing one.

  • Roadmap §23 workstream this advances: none directly.
  • §28 market-fit criterion this moves toward: not directly applicable.
  • Accepted evidence it is real: live timing evidence below, gathered on this machine's actual Colima/Docker setup, not simulated.

What changed

  • `apps/backend/Dockerfile`: dependency manifests (`pyproject.toml`, `requirements.txt`) are now copied and installed before `app/` is copied, so a source-only change no longer busts the dependency-install layer. Added a BuildKit `--mount=type=cache,target=/root/.cache/pip` cache mount and dropped `--no-cache-dir`, so even a genuine `requirements.txt` change reuses previously downloaded wheels instead of re-fetching everything. Split the final `pip install -e . --no-deps` into its own layer after the source copy (cheap: no network fetch, no compilation).
  • `apps/backend/.dockerignore` (new): excludes `.venv`, `pycache`/`.pytest_cache`/`.mypy_cache`/`.ruff_cache`, `.egg-info`, `.local`/`local`, `tests`, coverage artifacts, `.env`, `.git`, and the stray `$/` shell-expansion artifact already noted in `confidential/Memory.md`. None of these are referenced by any `COPY` instruction, but without this file they were still walked/transferred as build context on every build.

Acceptance criteria completed

  • Dependency install layer survives an `app/` source-only change
  • `.dockerignore` exists and excludes `.venv`/local caches/artifacts
  • `docker compose build api` and `docker compose build frontend` both succeed and produce a working stack

Testing performed

docker compose build api          (cold-ish, pip install layer legitimately reran)
  -> 31s total

# edited apps/backend/app/main.py with a real content change, rebuilt:
docker compose build api
  -> 3.8s total; build log shows:
     [stage-0 5/9] RUN ... pip install -r requirements.txt   CACHED
     [stage-0 6/9] COPY app ./app                            (reran, 0.0s)
     [stage-0 9/9] RUN ... pip install -e . --no-deps         (reran, 2.6s)
  -> reverted the test edit before committing

npm run partha (full stack)
  -> all 4 containers (postgres, redis, api, frontend) reported healthy;
     script printed "PARTHA is ready at http://localhost:5173"
  -> torn down cleanly with docker compose down afterward

Not run: `npm run docker:validate` (the deeper acceptance script) — the manual verification above already exercises build + full stack readiness, and this change touches only build-time caching behavior, not runtime application behavior.

Screenshots

Not applicable — Dockerfile/build-context change, no UI impact.

Security and data considerations

None. Build-cache and build-context scoping only; no change to what ships in the final image (the `.dockerignore`-excluded paths were never `COPY`'d into the image by this Dockerfile before or after this change), no new dependency, no credentials or secrets touched.

Dependencies and blocked work

None.

Scope changes or remaining work

Per #258: this does not fix the Colima VM disk sizing itself (a local machine/operator concern, not something this repo can control) or add automated cleanup for stale `partha-launcher-test-*`-style images left behind by `scripts/validate-compose.mjs` runs. Both are flagged as candidate follow-ups in #258, not folded into this fix.

Contributor checklist

  • This PR targets `dev`
  • I claimed the issue and had it assigned before starting substantial work (self-assigned chore(infra): backend Docker build is slow and fails under low disk (layer ordering, missing .dockerignore) #258; not commented per maintainer instruction)
  • The branch was created from an up-to-date `upstream/dev`
  • The branch is rebased on the latest `upstream/dev`
  • This PR addresses one clearly scoped issue
  • This PR advances a §23 workstream toward a §28 market-fit criterion — see honest Roadmap alignment note above; this is infra/DX hygiene, not a product change
  • Every acceptance criterion I claim as complete is actually complete
  • Relevant tests pass — no automated test suite covers Docker build caching; verified manually per Testing performed above
  • Documentation is updated for any user-visible change — none needed, no documented behavior changed
  • No secrets, credentials, local env files, or generated artifacts are included
  • No unrelated files were changed
  • Closing syntax (`Closes`) is used only because the issue is fully resolved
  • Dependencies and follow-up work are linked

parthrohit22 added a commit to parthrohit22/PARTHA that referenced this pull request Aug 7, 2026
Published after this PR was opened -- caught it re-blocking PR Second-Origin#259,
which branched from dev before this merged. Same pattern as the
other four: patched version (3.3.17) is within the major already in
use, no breaking change.
…n#258)

apps/backend/Dockerfile copied app/ before running pip install, so
Docker's content-addressed layer cache busted the dependency-install
layer on nearly every build -- not just when requirements.txt
changed. Reorder dependency install before source copy and add a
BuildKit pip cache mount so a genuine dependency change doesn't
re-fetch unchanged wheels either.

Add the missing apps/backend/.dockerignore (frontend already has
one) so the build context stops shipping .venv, caches, and
egg-info -- none of it referenced by any COPY instruction, but all
of it walked/transferred on every build without this.
Same fix as Second-Origin#257, plus nanoid (GHSA-2v37-7h3g-55p8, published after
so it inherited all five now-blocking advisories. Bumped via
overrides to the patched versions; all within the major version
already in use.
@parthrohit22
parthrohit22 force-pushed the fix/258-docker-build-cache branch from a0b5cd4 to 74cff1b Compare August 7, 2026 21:36
parthrohit22 added a commit to parthrohit22/PARTHA that referenced this pull request Aug 7, 2026
Branched from dev before Second-Origin#257 merged, so this inherited the same
still-open nanoid advisory blocking Second-Origin#259/Second-Origin#264's Frontend check. Same
fix: patched version 3.3.17 is within the major already in use.
parthrohit22 added a commit that referenced this pull request Aug 7, 2026
* security(deps): bump dompurify, js-yaml, brace-expansion, undici (#256)

Four advisories published since dev's last CI run made the live
npm-audit gate (scripts/dependency-audit.mjs) start blocking every
open PR: brace-expansion (GHSA-rgw5-rvv9-x895), dompurify
(GHSA-55q2-fjhq-7xh7, GHSA-c2j3-45gr-mqc4), js-yaml
(GHSA-52cp-r559-cp3m, GHSA-5p4m-2wfm-xmqj), and undici
(GHSA-4cwx-7wf7-3272 and others via jsdom). All four patches land
within the already-used major version, so no override needed a major
bump; undici is newly added to overrides since it was previously
unpinned.

* security(deps): also bump nanoid (GHSA-2v37-7h3g-55p8)

Published after this PR was opened -- caught it re-blocking PR #259,
which branched from dev before this merged. Same pattern as the
other four: patched version (3.3.17) is within the major already in
use, no breaking change.
@parthrohit22
parthrohit22 merged commit 7712c3d into Second-Origin:dev Aug 7, 2026
9 checks passed
parthrohit22 added a commit that referenced this pull request Aug 7, 2026
* chore(ci): add scheduled dependency-audit scan against dev (#263)

The Frontend job's live npm-audit gate blocks PRs on external
advisory timing, not code changes -- three unrelated PRs went red
today from newly published CVEs (#256, #258). This adds a daily
scheduled workflow that re-runs the same audit against dev
independent of any open PR, filing (or closing) a labelled issue so
dev stays caught up and a PR rarely gets blindsided. Does not change
ci.yml's existing per-PR gate at all -- same strictness, just an
earlier warning.

* security(deps): also bump nanoid (GHSA-2v37-7h3g-55p8)

Branched from dev before #257 merged, so this inherited the same
still-open nanoid advisory blocking #259/#264's Frontend check. Same
fix: patched version 3.3.17 is within the major already in use.
@parthrohit22
parthrohit22 deleted the fix/258-docker-build-cache branch August 7, 2026 23:40
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.

chore(infra): backend Docker build is slow and fails under low disk (layer ordering, missing .dockerignore)

1 participant