-
Notifications
You must be signed in to change notification settings - Fork 0
system - optimize docker image size #174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,3 +15,6 @@ uploads/ | |
| .git | ||
| .gitignore | ||
| Dockerfile | ||
| *.md | ||
| doc/ | ||
| plans/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| # ---- Base: shared setup ---- | ||
| # ---- Base: shared setup (used by dev + build) ---- | ||
| FROM python:3.12-slim AS base | ||
|
|
||
| COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ | ||
|
|
@@ -19,22 +19,30 @@ EXPOSE 8000 | |
| ENTRYPOINT ["/app/entrypoint.sh"] | ||
| CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"] | ||
|
|
||
| # ---- Prod: deps + source ---- | ||
| FROM base AS prod | ||
| # ---- Build: install deps + source (intermediate stage) ---- | ||
| FROM base AS build | ||
|
|
||
| COPY pyproject.toml uv.lock* ./ | ||
| RUN uv sync --frozen --no-dev --no-install-project | ||
|
|
||
| COPY . . | ||
|
|
||
| ARG APP_VERSION=dev | ||
| RUN echo "$APP_VERSION" > VERSION && uv sync --frozen --no-dev | ||
|
|
||
| # ---- Prod: clean runtime image without uv ---- | ||
| FROM python:3.12-slim AS prod | ||
|
|
||
| LABEL org.opencontainers.image.source="https://github.com/VEAF/website-2026" | ||
| LABEL org.opencontainers.image.description="VEAF Website 2026 - Backend API" | ||
|
|
||
| COPY pyproject.toml uv.lock* ./ | ||
| RUN uv sync --frozen --no-dev --no-install-project | ||
| RUN groupadd --gid 1000 worker && useradd --uid 1000 --gid worker --create-home worker | ||
|
|
||
| COPY . . | ||
| RUN echo "$APP_VERSION" > VERSION | ||
| RUN uv sync --frozen --no-dev | ||
| WORKDIR /app | ||
| ENV PATH="/app/.venv/bin:$PATH" | ||
|
|
||
| COPY --from=build --chown=worker:worker /app /app | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Copying the entire This Suggested implementation:
|
||
|
|
||
| RUN chown -R worker:worker /app | ||
| USER worker | ||
| EXPOSE 8000 | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,3 +5,4 @@ dist | |
| .git | ||
| .gitignore | ||
| Dockerfile | ||
| *.md | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): The prod stage no longer inherits ENTRYPOINT/CMD from
base, so the final image lacks a startup command.Since
prodnow usesFROM python:3.12-sliminstead ofFROM base, it no longer gets theENTRYPOINT ["/app/entrypoint.sh"]and uvicornCMD. The image will build but run without a default startup command, changing behavior from the previous setup.To preserve the prior behavior, either:
ENTRYPOINT/CMDin theprodstage, orprodinherit from it, keepinguvonly in the build stage.