-
Notifications
You must be signed in to change notification settings - Fork 18
feat: add multi-stage Dockerfile for building and running app #342
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 |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # Stage 1: Build | ||
| FROM python:3.12-slim-bookworm AS build | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| COPY requirements.txt . | ||
| RUN pip install --no-cache-dir -r requirements.txt | ||
|
|
||
| COPY . . | ||
|
|
||
| # Stage 2: Runtime | ||
| FROM python:3.12-slim-bookworm AS runtime | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| COPY requirements.txt . | ||
| RUN pip install --no-cache-dir -r requirements.txt | ||
|
|
||
|
Comment on lines
+11
to
+18
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. 🛠️ Refactor suggestion Avoid duplicating # In the build stage:
-COPY requirements.txt .
-RUN pip install --no-cache-dir -r requirements.txt
+COPY requirements.txt .
+RUN pip wheel --no-cache --no-deps -r requirements.txt -w /app/wheelhouse
# In the runtime stage:
-COPY requirements.txt .
-RUN pip install --no-cache-dir -r requirements.txt
+COPY requirements.txt .
+COPY --from=build /app/wheelhouse /app/wheelhouse
+RUN pip install --no-cache-dir --no-index --find-links /app/wheelhouse -r requirements.txt
Owner
Author
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. Open a follow-up GitHub issue for this discussion. 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. 🧩 Analysis chain@nanotaboada I've created a follow-up GitHub issue to track the Dockerfile optimization we discussed. The issue includes the detailed explanation of how to avoid duplicating The issue has been assigned to you for future implementation when you're ready to address it. 🏁 Script executed: Length of output: 1439 @nanotaboada Great! The issue has been successfully created as #345. You can access it directly at: #345 The issue includes all the details about optimizing the Dockerfile by avoiding duplication of the pip install step across stages, along with the code examples and benefits. 🐰✨ If you found this review helpful, would you consider giving us a shout-out on X? Thank you for using CodeRabbit! |
||
| COPY models ./models | ||
| COPY routes ./routes | ||
| COPY schemas ./schemas | ||
| COPY services ./services | ||
| COPY data ./data | ||
| COPY main.py . | ||
|
|
||
| # Add non-root 'fastapi' user (optional for hardening) | ||
| RUN adduser --disabled-password --gecos '' fastapi \ | ||
| && chown -R fastapi:fastapi /app | ||
| USER fastapi | ||
|
|
||
| EXPOSE 9000 | ||
| ENV PYTHONUNBUFFERED=1 | ||
|
|
||
| CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "9000"] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| // .commitlint.config.mjs | ||
| import conventional from '@commitlint/config-conventional'; | ||
|
|
||
| export default { | ||
| ...conventional, | ||
| rules: { | ||
| 'header-max-length': [2, 'always', 80], | ||
| 'body-max-line-length': [2, 'always', 80], | ||
| }, | ||
| ignores: [ | ||
| // skip any commit whose body contains the Dependabot signature | ||
| (message) => message.includes('Signed‑off‑by: dependabot[bot]'), | ||
| // skip any Dependabot‑style bump header | ||
| (message) => /^chore\(deps(-dev)?\): bump /.test(message), | ||
| ], | ||
| }; | ||
nanotaboada marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Uh oh!
There was an error while loading. Please reload this page.