-
Notifications
You must be signed in to change notification settings - Fork 2
Improve Docker build #23
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b0ebf88
Improve Docker build
Masterain98 26ca2aa
fix build
Masterain98 a684202
Update build config
Masterain98 6ad7c69
Update Dockerfile
Masterain98 20743a4
Update requirements.build.txt
Masterain98 b8f552a
Update Dockerfile
Masterain98 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| .git | ||
| .gitignore | ||
| __pycache__/ | ||
| *.pyc | ||
| *.pyo | ||
| *.pyd | ||
| .build/ | ||
| dist/ | ||
| .wheels/ | ||
| .cache/ | ||
| .env | ||
| *.log | ||
| .mypy_cache/ | ||
| .pytest_cache/ | ||
| .vscode/ | ||
| .idea/ |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,44 @@ | ||
| #!/bin/sh | ||
| # Build Stage | ||
| # syntax=docker/dockerfile:1.6 | ||
|
|
||
| # Build stage | ||
| FROM python:3.12 AS builder | ||
| WORKDIR /code | ||
| ADD . /code | ||
| RUN pip install "fastapi[standard]" | ||
| RUN pip install redis | ||
| RUN pip install sqlalchemy | ||
| RUN pip install pymysql | ||
| RUN pip install "sentry-sdk[fastapi]" | ||
| RUN pip install cryptography | ||
| RUN pip install pyinstaller | ||
| RUN pyinstaller -F main.py | ||
|
|
||
| # Runtime | ||
|
|
||
| # Use --mount=type=cache to cache pip downloads between builds | ||
| COPY requirements.txt /code/requirements.txt | ||
| COPY requirements.build.txt /code/requirements.build.txt | ||
| RUN --mount=type=cache,target=/root/.cache/pip,id=pip-cache \ | ||
| python -m pip install --upgrade pip wheel \ | ||
| && pip wheel -r requirements.txt -w /wheels \ | ||
| && pip wheel -r requirements.build.txt -w /wheels | ||
|
|
||
| # Copy source code | ||
| COPY . /code | ||
|
|
||
| # Install dependencies from wheels cache (offline installation) | ||
| RUN --mount=type=cache,target=/root/.cache/pip,id=pip-cache \ | ||
| pip install --no-index --find-links=/wheels -r requirements.txt \ | ||
| && pip install --no-index --find-links=/wheels -r requirements.build.txt | ||
|
|
||
| # Run PyInstaller to create a single executable | ||
| RUN --mount=type=cache,target=/root/.cache/pip,id=pip-cache \ | ||
| pyinstaller -F main.py | ||
|
|
||
|
|
||
| # Runtime stage | ||
| FROM ubuntu:24.04 AS runtime | ||
| WORKDIR /app | ||
| COPY --from=builder /code/dist/main . | ||
| EXPOSE 8000 | ||
| ENTRYPOINT ["./main"] | ||
|
|
||
| # Install runner dependencies | ||
| RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
| ca-certificates \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| # Copy the built executable from the builder stage | ||
| COPY --from=builder /code/dist/main /app/main | ||
|
|
||
| # Health check | ||
| # HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \ | ||
| # CMD curl -fsS http://localhost:8080/health || exit 1 | ||
|
|
||
| ENTRYPOINT ["/app/main"] |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| pyinstaller==6.10.0 | ||
| # setuptools is pinned below version 81 due to incompatibility with PyInstaller; see https://github.com/pyinstaller/pyinstaller/issues/7994 | ||
| setuptools<81 | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.