Skip to content

🔒 Add .dockerignore: keep .env / .venv out of image layers; pin Python 3.13 - #2

Open
luiscosio wants to merge 1 commit into
mainfrom
chore/dockerignore-py313
Open

🔒 Add .dockerignore: keep .env / .venv out of image layers; pin Python 3.13#2
luiscosio wants to merge 1 commit into
mainfrom
chore/dockerignore-py313

Conversation

@luiscosio

Copy link
Copy Markdown
Contributor

Follow-up to #1, which merged before this landed on that branch.

Secret-leak fix

There was no .dockerignore, and both Dockerfiles run COPY . . (Dockerfile:50, Dockerfile.cpu:30). Docker does not read .gitignore, so the entire working directory enters the build context:

  • A real .env (holding HUGGINGFACE_HUB_TOKEN / API_KEY, per .env.example) would be baked into an image layer permanently — deleting it in a later layer does not remove it from layer history. docker-compose.yml already bind-mounts ./.env:/app/.env:ro at runtime for both services, so the build-time copy had no upside.
  • A local .venv (~1 GB with torch/whisperx installed) was also entering the context on every build, and could shadow the container's site-packages.

The new .dockerignore excludes .env, .venv, .git, __pycache__, input/*, output/*, and the generated transcript artifacts mirrored from .gitignore. *.txt is excluded with a !requirements.txt negation because both Dockerfiles COPY requirements.txt . before the main copy — getting that wrong breaks the build.

Measured effect: build context drops from ~1 GB to ~41 kB.

Runtime standardization (org: Python 3.13)

  • .python-version3.13 (uv picks it up for dev envs)
  • README prerequisites → Python 3.13
  • CUDA Dockerfile: comment documenting that the ubuntu22.04 base is correct — Python 3.13 is installed from deadsnakes and set as default via update-alternatives (the system 3.10 is unused), and the ubuntu24.04 base would ship 3.12, i.e. further from target. No functional change; whisperx caps at <3.14, making 3.13 the org-wide ceiling.

Verification

With a dummy .env (hf_dummy_not_real) and a populated 981 MB .venv deliberately present in the working directory:

Check Result
Probe image with the same COPY requirements.txt . + COPY . . against this context builds clean
/app/.env in image absent
/app/.venv in image absent
/app/requirements.txt in image present (negation works)
App files (secure_speech_to_text.py, utils/, best_effort_delete.py, compose, .env.example) all present

.dockerignore only affects what enters the build context, so a minimal probe image with identical COPY directives verifies the exclusion semantics without a full ~10-minute torch build. The full torch image was already built and functionally verified in #1; nothing in this PR changes what gets installed. Full CUDA-image behavior on a GPU host remains unverified here (no GPU on this machine, base image is amd64-oriented).

The dummy .env was deleted before commit; git status clean.

Both Dockerfiles COPY . . and Docker does not read .gitignore, so a
developer building with a real .env present would bake
HUGGINGFACE_HUB_TOKEN and API_KEY into an image layer permanently
(a later rm does not remove layer contents). docker-compose.yml already
bind-mounts ./.env:/app/.env:ro at runtime, so the build never needs it.
Also excludes .venv (~1 GB locally) and generated transcript artifacts;
build context drops from ~1 GB to ~41 kB.

*.txt is excluded with a !requirements.txt negation because both
Dockerfiles COPY requirements.txt before the main COPY.

Also: pin Python 3.13 via .python-version, update README prerequisites,
and document in the CUDA Dockerfile why the ubuntu22.04 base is correct
(Python 3.13 already comes from deadsnakes, not the system 3.10).

Verified with a dummy .env and a populated 981 MB .venv in the context:
probe image with the same COPY directives shows .env and .venv absent,
requirements.txt and all app files present.
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