-
Notifications
You must be signed in to change notification settings - Fork 0
Update dependencies and modernize dependency management #50
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 8 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
cbe8875
Refactor from poetry to uv.
onyxfish 4fdb292
Simplify and modernize Dockerfile.
onyxfish 2d34d49
Add MySQL configuration and DB bootstrapping to Docker compose setup
onyxfish 3fe620b
Exclude caches from docker build.
onyxfish e8fc143
Bypass bandit error.
onyxfish 5b7449d
Exclude venv from Vulture scan.
onyxfish fd67f76
Prevent automatic upgrade to Python 3.14.
onyxfish a96c5d9
Upgrade dependency versions.
onyxfish cb9c74d
Update docker-compose.yml to pass env vars
onyxfish 326ec33
Remove compatibility CI jobs.
onyxfish 2f508f9
Remove another unnecesary job.
onyxfish bb347ab
Fix env.template name.
onyxfish 8c6d3f9
Reduce privileges for production Docker stage.
onyxfish 4e8edef
Sanitize URL in documentation to prevent (very unlikely) injection at…
onyxfish 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 |
|---|---|---|
| @@ -1,2 +1,6 @@ | ||
| .env | ||
| __pycache__ | ||
| __pycache__ | ||
| .venv | ||
| .data | ||
| .pytest_cache | ||
| .ruff_cache |
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
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 was deleted.
Oops, something went wrong.
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,76 +1,68 @@ | ||
| ARG IMAGE_TAG=3.13-slim-bullseye | ||
|
|
||
| FROM python:${IMAGE_TAG} AS base | ||
| # Allowing the argumenets to be read into the dockerfile. Ex: .env > compose.yml > Dockerfile | ||
| ARG UID=1000 | ||
| ARG GID=1000 | ||
| # | ||
| # Python dependencies stage | ||
| # | ||
| FROM python:${IMAGE_TAG} AS deps | ||
|
|
||
| # Create the user and usergroup | ||
| RUN groupadd -g ${GID} -o app | ||
| RUN useradd -m -d /app -u ${UID} -g ${GID} -o -s /bin/bash app | ||
| # Copy uv binary for dependency management | ||
| COPY --from=ghcr.io/astral-sh/uv:0.8.4 /uv /usr/local/bin/uv | ||
|
|
||
| # Set the working directory to /app | ||
| WORKDIR /app | ||
|
|
||
| # Both build and development need poetry, so it is its own step. | ||
| FROM base AS poetry | ||
| RUN pip install poetry | ||
|
|
||
| # Use this page as a reference for python and poetry environment variables: | ||
| # https://docs.python.org/3/using/cmdline.html#envvar-PYTHONUNBUFFERED Ensure | ||
| # the stdout and stderr streams are sent straight to terminal, then you can see | ||
| # the output of your application | ||
| ENV PYTHONUNBUFFERED=1\ | ||
| # Avoid the generation of .pyc files during package install | ||
| # Disable pip's cache, then reduce the size of the image | ||
| PIP_NO_CACHE_DIR=off \ | ||
| # Save runtime because it is not look for updating pip version | ||
| PIP_DISABLE_PIP_VERSION_CHECK=on \ | ||
| PIP_DEFAULT_TIMEOUT=100 \ | ||
| # Disable poetry interaction | ||
| POETRY_NO_INTERACTION=1 \ | ||
| POETRY_VIRTUALENVS_CREATE=1 \ | ||
| POETRY_VIRTUALENVS_IN_PROJECT=1 \ | ||
| POETRY_CACHE_DIR=/tmp/poetry_cache | ||
|
|
||
| FROM poetry AS build | ||
| COPY pyproject.toml poetry.lock ./ | ||
| RUN poetry install --no-root --without dev && rm -rf ${POETRY_CACHE_DIR}; | ||
|
|
||
| # FROM poetry AS build-minor-update | ||
| # # Install minor version updates in the absence of poetry.lock file | ||
| # COPY pyproject.toml poetry.lock ./ | ||
| # RUN poetry install --no-root --without dev && rm -rf ${POETRY_CACHE_DIR}; | ||
|
|
||
| FROM build AS test | ||
| ENV PYTHONUNBUFFERED=1 \ | ||
| # Compile Python bytecode for faster startup | ||
| UV_COMPILE_BYTECODE=1 \ | ||
| # Use copy mode (required in Docker; hardlinks don't work across layers) | ||
| UV_LINK_MODE=copy | ||
|
|
||
| # Install production dependencies | ||
| COPY pyproject.toml uv.lock ./ | ||
| RUN --mount=type=cache,target=/root/.cache/uv \ | ||
| uv sync --frozen --no-install-project --no-dev | ||
|
|
||
| # | ||
| # Test stage | ||
| # | ||
| FROM deps AS test | ||
|
|
||
| # Install dev dependencies | ||
| RUN poetry install --only dev --no-root && rm -rf ${POETRY_CACHE_DIR}; | ||
| RUN --mount=type=cache,target=/root/.cache/uv \ | ||
| uv sync --frozen --no-install-project | ||
|
|
||
| COPY . . | ||
| # Run tests | ||
| USER app | ||
| RUN poetry run pytest tests | ||
|
|
||
| FROM build AS test-minor-update | ||
| # Install dev dependencies | ||
| RUN poetry install --only dev --no-root && rm -rf ${POETRY_CACHE_DIR}; | ||
| RUN poetry update | ||
| CMD ["uv", "run", "pytest", "tests"] | ||
|
|
||
| # | ||
| # Test stage (with minor version updates) | ||
| # | ||
| FROM deps AS test-minor-update | ||
|
|
||
| # Update to latest compatible versions and install dev dependencies | ||
| RUN --mount=type=cache,target=/root/.cache/uv \ | ||
| uv lock --upgrade && uv sync --no-install-project | ||
|
|
||
| COPY . . | ||
| # Run tests | ||
| USER app | ||
| RUN poetry run pytest tests | ||
|
|
||
| CMD ["uv", "run", "pytest", "tests"] | ||
|
|
||
| # | ||
| # Production stage | ||
| # | ||
| FROM python:${IMAGE_TAG} AS production | ||
|
|
||
| # Copy uv binary for runtime | ||
| COPY --from=ghcr.io/astral-sh/uv:0.8.4 /uv /usr/local/bin/uv | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| FROM base AS production | ||
| RUN mkdir -p /venv && chown ${UID}:${GID} /venv | ||
| ENV PYTHONUNBUFFERED=1 | ||
|
|
||
| # By adding /venv/bin to the PATH, the dependencies in the virtual environment | ||
| # are used | ||
| ENV VIRTUAL_ENV=/venv \ | ||
| PATH="/venv/bin:$PATH" | ||
| # Copy the virtualenv from the deps stage | ||
| COPY --from=deps /app/.venv /app/.venv | ||
|
|
||
| COPY --chown=${UID}:${GID} . /app | ||
| COPY --chown=${UID}:${GID} --from=build "/app/.venv" ${VIRTUAL_ENV} | ||
| # Copy application source | ||
| COPY . . | ||
|
|
||
| # Switch to the app user | ||
| USER app | ||
| CMD ["uv", "run", "python", "-m", "gunicorn", "-c", "gunicorn_config.py"] | ||
onyxfish marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Oops, something went wrong.
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.