Merged
Conversation
Copilot
AI
changed the title
[WIP] Optimize Dockerfile to reduce layer invalidation
Optimize Dockerfile: 12 → 8 layers, fix dep-cache invalidation on code changes
Mar 21, 2026
7246587 to
dc9d571
Compare
3 tasks
Co-authored-by: jancwe <83763512+jancwe@users.noreply.github.com> Agent-Logs-Url: https://github.com/jancwe/formflow/sessions/a94ea3cc-dddb-49e3-9406-c7281ad56654
4e2677e to
c5e918e
Compare
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.
Every source/HTML change was busting the
pip installlayer (~200 MB, 60–90s) becauseCOPY src/appeared beforeRUN pip install. Separately, threeLABELinstructions and two trailingRUNcommands added unnecessary layers.Changes
LABELinstructions into one multi-line statement (−2 layers)pyproject.toml, create a minimal dummysrc/formflow/__init__.py, runpip installto cache deps, then delete the dummy — so the heavy install layer is only invalidated whenpyproject.tomlactually changesCOPY src/ src/, runpip install --no-cache-dir --no-deps .to install the package itself without re-downloading dependenciesCOPY . .withCOPY app.py ./COPY forms/ forms/— eliminates double-copying ofsrc/andpyproject.tomland removes unpredictable build-context behavior/datadir creation into one instruction (−1 layer)Cache impact for a typical HTML/code change: ~60–90 s → ~5–10 s.
Original prompt
Problem
Das aktuelle Dockerfile erzeugt 12 Layer/Blobs. Selbst kleine HTML-Änderungen invalidieren mehrere Layer, einschließlich des teuren
pip install-Layers (~200+ MB, 30–60 Sek.), weil die Layer-Reihenfolge nicht optimal ist.Aktuelles Dockerfile (12 Layer)
Identifizierte Probleme
LABEL-Anweisungen → 3 Layer statt 1COPY src/ src/VORpip install: Jede Code-Änderung insrc/invalidiert den pip-install-Cache, obwohl sich die Dependencies nicht geändert haben. Das ist das Hauptproblem – eine HTML-Template-Änderung erzwingt einen komplettenpip installRebuild.COPY . .nach selektiven COPYs: Kopiertpyproject.tomlundsrc/doppelt und macht den Build-Context unvorhersehbar.RUN-Befehle am Ende (static-Dateien kopieren + /data-Verzeichnisse erstellen) → können kombiniert werden.Gewünschte Änderungen
Das Dockerfile soll wie folgt optimiert werden:
Erwartete Verbesserungen
COPY src/betroffen; pip install deps gecached (~5-10 Sek.)COPY . .kopiertsrc/undpyproject.tomlnochmalCOPY-Befehle, keine DopplungWichtige Hinweise
.github/workflows/ci.yml) nutzt bereitsdocker/build-push-actionmit GHA-Cache (cache-from: type=gha), profitiert also direkt von der besseren Layer-Struktur.Dockerfilemuss geändert werden. Keine Änderungen an.dockerignore,docker-compose.yml, etc.The following is the prior conversation context from the user's chat exploration (may be truncated):
User: Mir ist aufgefallen, dass wir mit 12 "blobs" sehr viele docker layer haben und selbst die kleine HTML Änderung hat Änderungen an gleich mehreren layern verursacht. Analysiere die docker layer Situation und schreibe einen Bericht ob wir sie optimieren sollten.
Assistant:
Ich werde zunächst das Dockerfile ...
This pull request was created from Copilot chat.
💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.