-
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 all 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 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 |
|---|---|---|
|
|
@@ -16,42 +16,39 @@ jobs: | |
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/[email protected] | ||
| with: | ||
| python-version: 3.x | ||
| - name: Install uv | ||
| uses: astral-sh/setup-uv@v5 | ||
|
|
||
| - name: Display Python version | ||
| run: | | ||
| python --version | ||
| uv run python --version | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| pip install poetry | ||
| poetry install --no-root --with dev | ||
| uv sync --frozen | ||
|
|
||
| - name: Check for outdated dependencies | ||
| if: env.skip-job != 'true' | ||
| run: | | ||
| poetry show --outdated --only main | ||
| uv tree --outdated | ||
|
|
||
| - name: Run tests with coverage in latest stable 3.x | ||
| run: | | ||
| poetry run pytest --cov=app --cov-report=term-missing | ||
| uv run pytest --cov=app --cov-report=term-missing | ||
| continue-on-error: false | ||
|
|
||
| - name: Run Bandit for security analysis | ||
| run: | | ||
| poetry run bandit -r app | ||
| uv run bandit -r app | ||
| continue-on-error: false | ||
|
|
||
| - name: Run Ruff for linting | ||
| run: | | ||
| poetry run ruff check . | ||
| uv run ruff check . | ||
| continue-on-error: false | ||
|
|
||
| - name: Run Vulture for dead code analysis | ||
| run: | | ||
| poetry run vulture . --min-confidence 70 | ||
| uv run vulture . --min-confidence 70 --exclude .venv | ||
| continue-on-error: false | ||
|
|
||
This file was deleted.
Oops, something went wrong.
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
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,64 @@ | ||
| 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 | ||
| # Install dev dependencies | ||
| RUN poetry install --only dev --no-root && rm -rf ${POETRY_CACHE_DIR}; | ||
| COPY . . | ||
| # Run tests | ||
| USER app | ||
| RUN poetry run pytest tests | ||
| 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 | ||
|
|
||
| FROM build AS test-minor-update | ||
| # Install dev dependencies | ||
| RUN poetry install --only dev --no-root && rm -rf ${POETRY_CACHE_DIR}; | ||
| RUN poetry update | ||
| RUN --mount=type=cache,target=/root/.cache/uv \ | ||
| uv sync --frozen --no-install-project | ||
|
|
||
| COPY . . | ||
| # Run tests | ||
| USER app | ||
| RUN poetry run pytest tests | ||
|
|
||
| CMD ["uv", "run", "pytest", "tests"] | ||
|
|
||
| FROM base AS production | ||
| RUN mkdir -p /venv && chown ${UID}:${GID} /venv | ||
| # | ||
| # Production stage | ||
| # | ||
| FROM python:${IMAGE_TAG} AS production | ||
|
|
||
| # By adding /venv/bin to the PATH, the dependencies in the virtual environment | ||
| # are used | ||
| ENV VIRTUAL_ENV=/venv \ | ||
| PATH="/venv/bin:$PATH" | ||
| # Copy uv binary for runtime | ||
| COPY --from=ghcr.io/astral-sh/uv:0.8.4 /uv /usr/local/bin/uv | ||
|
|
||
| COPY --chown=${UID}:${GID} . /app | ||
| COPY --chown=${UID}:${GID} --from=build "/app/.venv" ${VIRTUAL_ENV} | ||
| COPY . . | ||
| # Create an unprivileged user and group to run the application | ||
| RUN groupadd --gid 1001 app && \ | ||
| useradd --uid 1001 --gid app --no-create-home app | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| ENV PYTHONUNBUFFERED=1 \ | ||
| # Deps are pre-installed in the venv; no cache needed at runtime | ||
| UV_NO_CACHE=1 | ||
|
|
||
| # Copy the virtualenv from the deps stage with correct ownership | ||
| COPY --from=deps --chown=app:app /app/.venv /app/.venv | ||
|
|
||
| # Copy application source with correct ownership | ||
| COPY --chown=app:app . . | ||
|
|
||
| # Switch to the unprivileged user before starting the process | ||
| USER app | ||
|
|
||
| # Switch to the app user | ||
| USER app | ||
| CMD ["uv", "run", "python", "-m", "gunicorn", "-c", "gunicorn_config.py"] | ||
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.