Skip to content

Speed up backend Docker builds: defer src/ COPY to hosted, narrow scripts/ COPY, drop tests/#40

Merged
LukeMainwaring merged 1 commit into
mainfrom
docker-optimize
Apr 9, 2026
Merged

Speed up backend Docker builds: defer src/ COPY to hosted, narrow scripts/ COPY, drop tests/#40
LukeMainwaring merged 1 commit into
mainfrom
docker-optimize

Conversation

@LukeMainwaring

Copy link
Copy Markdown
Owner

Summary

  • Move COPY src/ out of the shared app base into the hosted stage only — local already gets src/ from the ./backend/src:/app/src bind mount in docker-compose.yml, so editing source files no longer invalidates the local image cache.
  • Replace COPY scripts/ /app/scripts/ with an explicit COPY scripts/run_local.sh scripts/run_hosted.sh ... — the other three *-docker.sh scripts are host-side wrappers around docker compose exec and don't belong in the image.
  • Drop COPY tests/ from the local stage entirely — tests run on the host via uv run --directory backend pytest (per DEVELOPMENT.md) and CI doesn't pytest in Docker either.

Approach is modeled on LukeMainwaring/cortexdj#10, which solved the same problem in a sister project, with a few samplespace-specific extras.

Changes

  • backend/Dockerfile: restructure the app/local/hosted stages so the only thing the shared base does is install system deps, copy the venv, and copy the two runtime entrypoint scripts. src/ now baked into hosted only.
  • backend/.dockerignore: add .DS_Store, tests/, and scripts/*-docker.sh as defense-in-depth (and to shrink the build context tarball).

Test Plan

  • docker compose build backend — initial build succeeds
  • Immediate rebuild → all layers CACHED
  • touch backend/src/samplespace/app.py && docker compose build backend → fully CACHED (the headline win — previously rebuilt the local image)
  • touch backend/scripts/migrate-docker.sh && docker compose build backend → fully CACHED
  • touch backend/tests/conftest.py && docker compose build backend → fully CACHED
  • docker compose up -d backend → container boots, /app/src/samplespace/app.py visible via bind mount, /app/scripts/ contains only run_local.sh + run_hosted.sh, /app/tests does not exist
  • docker build --target hosted backend/ — sanity-check the production stage still bundles src/ at /app/src (no bind mount in prod)
  • One CI run on this branch to confirm nothing downstream depends on the old layout

🤖 Generated with Claude Code

@LukeMainwaring LukeMainwaring merged commit 52119cb into main Apr 9, 2026
3 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