Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 7 additions & 31 deletions .github/workflows/lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,6 @@ jobs:
lint-test:
runs-on: ubuntu-latest
env:
# List of licenses that are compatible with the MIT License and
# can be used in our project
ALLOWED_LICENSE: Apache Software License;
BSD License;
GNU Library or Lesser General Public License (LGPL);
ISC License (ISCL);
MIT License;
Mozilla Public License 2.0 (MPL 2.0);
Public Domain;
Python Software Foundation License;
The Unlicense (Unlicense)

# Dummy values for required bot environment variables
BOT_API_KEY: foo
BOT_SENTRY_DSN: blah
Expand All @@ -31,27 +19,15 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install Python Dependencies
uses: HassanAbouelela/actions/setup-python@setup-python_v1.6.0
- name: Install uv
uses: astral-sh/setup-uv@v6
with:
python_version: '3.12'

# Check all of our non-dev dependencies are compatible with the MIT license.
# If you added a new dependencies that is being rejected,
# please make sure it is compatible with the license for this project,
# and add it to the ALLOWED_LICENSE variable
enable-cache: true
cache-dependency-glob: "uv.lock"
activate-environment: true

# NOTE: at time of writing pip-licenses is not PEP-639 compliant
# so is not detecting the license for packages now following that style.
# As a temp fix, add packages to the ignore list after manually checking
# that the license in use is compatible with ours.
# Ref: https://github.com/raimon49/pip-licenses/issues/225
- name: Check Dependencies License
run: |
poetry self add poetry-plugin-export
pip-licenses --allow-only="$ALLOWED_LICENSE" \
--ignore-packages attrs \
--package $(poetry export -f requirements.txt --without-hashes | sed "s/==.*//g" | tr "\n" " ")
- name: Install dependencies
run: uv sync --frozen

- name: Run pre-commit hooks
run: SKIP=ruff pre-commit run --all-files
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repos:
- id: ruff
name: ruff
description: Run ruff linting
entry: poetry run ruff check --force-exclude
entry: uv run --frozen ruff check --force-exclude
language: system
'types_or': [python, pyi]
require_serial: true
Expand Down
36 changes: 29 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,38 @@
FROM --platform=linux/amd64 ghcr.io/owl-corp/python-poetry-base:3.12-slim
ARG python_version=3.12-slim

FROM python:$python_version AS builder
COPY --from=ghcr.io/astral-sh/uv:0.7 /uv /bin/

ENV UV_COMPILE_BYTECODE=1 \
UV_LINK_MODE=copy

# Install project dependencies with build tools available
WORKDIR /build
RUN pip install --no-cache-dir --upgrade pip setuptools wheel \
&& python -m venv .venv

RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync --frozen --no-dev
Comment on lines +14 to +17
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're doing bind mounts to avoid copying the files into the image, which would affect the build cache?


# -------------------------------------------------------------------------------

FROM python:$python_version

# Define Git SHA build argument for sentry
ARG git_sha="development"
ENV GIT_SHA=$git_sha

# Install project dependencies
WORKDIR /bot
COPY pyproject.toml poetry.lock ./
RUN poetry install --without dev
# Install dependencies from build cache
# .venv not put in /app so that it doesn't conflict with the dev
# volume we use to avoid rebuilding image every code change locally
COPY --from=builder /build /build
ENV PATH="/build/.venv/bin:$PATH"

# Copy the source code in last to optimize rebuilding the image
WORKDIR /bot
COPY . .

ENTRYPOINT ["poetry"]
CMD ["run", "python", "-m", "bot"]
ENTRYPOINT ["python", "-m"]
CMD ["bot"]
Loading
Loading