46858 backend [ Configuration ] Add COPY instruction to backend Dockerfile for Railway deployment#216
Open
EBirkenfeld wants to merge 1 commit into
Conversation
pneumojoseph
approved these changes
May 26, 2026
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.
1. Problem
The backend
Dockerfilewas missing aCOPY . .command to copy application source code into the Docker image. Only poetry dependencies were installed — the actual application code was never included. As a result, Railway deployments failed withModuleNotFoundErrorbecause the image had no source files to run.Where it manifested: Railway deployment — backend, celery, and celery-beat services failed to start.
2. Context
Historically, the project ran exclusively via docker-compose with volume mounts (
./backend:/pneumatic_backend), which overlaid the container's filesystem with local source code. The missingCOPY . .went unnoticed. When deploying to Railway (no volume mounts), the built image was essentially "empty" — dependencies only, no application code.Additionally,
.dockerignoreonly had 3 entries. AddingCOPY . .without expanding it would have copied unwanted files into the image (.env,__pycache__,.venv, logs, credentials, etc.).3. Solution
COPY . .to the Dockerfile afterpoetry install— preserves optimal Docker layer caching (dependency layer only invalidates whenpyproject.toml/poetry.lockchange)..dockerignorefrom 3 to 55 entries to exclude dev artifacts, secrets, and build noise.COPYlayer in local development, preserving hot-reload.4. Implementation Details
backend/DockerfileCOPY . .(line 31) afterpoetry installwith explanatory commentsbackend/.dockerignore.dockerignoreexclusion categories: VCS (.git), IDE configs, Python caches, virtual environments, Docker files (avoid recursion), logs, secrets/env files (.env,google_api_credentials.json), build artifacts (staticfiles/,tmp/), database files.Intentionally unchanged: All three docker-compose files — volume mounts (
./backend:/pneumatic_backend) correctly overrideCOPYin local dev.5. Testing
5.1 Preconditions
5.2 Positive Scenarios
Production image build:
docker build -t pneumatic-backend-test ./backenddocker run --rm pneumatic-backend-test ls -la /pneumatic_backend/src/docker run --rm pneumatic-backend-test python manage.py --helpLocal dev via docker-compose:
docker-compose up backend.pyfile inbackend/COPY)Verify .dockerignore:
docker run --rm pneumatic-backend-test sh -c "ls -la .env 2>&1; ls -la .git 2>&1; ls -la __pycache__ 2>&1".dockerignoreentries are absent from image5.3 Negative Scenarios & Edge Cases
docker run --rm pneumatic-backend-test python -c "import src; print('OK')"→ should succeed.envandgoogle_api_credentials.jsonshould be absent5.4 Verification Points
src/,manage.py,pyproject.tomlpresent in/pneumatic_backend/.env,.git,__pycache__,.venv,*.logabsentModuleNotFoundError5.5 API Checks
Not applicable — infrastructure-only changes, no API impact.
5.6 What Was NOT Tested
docker buildonly)6. Affected Areas
The Dockerfile is used to build images for three services:
backend,celery,celery-beat. All usebuild: context: ./backendin docker-compose. Changes do not break local development — volume mounts override theCOPYlayer.7. Refactoring
.dockerignorewas essentially rewritten from scratch (3 → 55 lines). Test via image content verification (sections 5.2–5.3).8. Commits
dc9af484—46858 fix(docker): add source code copy to backend Dockerfile9. Release Notes
Docker: Fixed backend Docker image build — application source code is now properly included in the image, enabling successful deployments on Railway and other container platforms without volume mounts.
Note
Low Risk
Low risk infrastructure-only change; main risk is unintended build-context exclusions or slightly different image contents affecting deployments.
Overview
Fixes backend container builds for non-volume-mounted environments (e.g., Railway) by copying the application source into the image after dependency installation.
Expands
backend/.dockerignoreto exclude VCS/IDE files, Python caches, virtualenvs, logs, env/secrets (including Google credentials), build artifacts, and local DB files soCOPY . .doesn’t bake unnecessary or sensitive files into the image.Reviewed by Cursor Bugbot for commit dc9af48. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Add COPY instruction and expand .dockerignore in backend Dockerfile for Railway deployment
COPY . .step to Dockerfile after dependency installation, so the application source code is included in the built image under/pneumatic_backend.Macroscope summarized dc9af48.