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
21 changes: 12 additions & 9 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,31 @@ jobs:
- uses: actions/setup-python@v5
with:
python-version: "3.13"
- name: Install Poetry
uses: snok/install-poetry@v1

- name: Install the latest version of uv
uses: astral-sh/setup-uv@v5
with:
version: 1.8.4
virtualenvs-create: true
virtualenvs-in-project: true
version: "0.5.15"

- name: Setup cache
uses: actions/cache@v4
with:
path: .venv
key: poetry-venv-${{ hashFiles('poetry.lock') }}
key: uv-venv-${{ hashFiles('uv.lock') }}

- name: Install dependencies
run: |
poetry install --no-interaction
uv sync

- name: Set CODEQL-PYTHON
run: |
source .venv/bin/activate
echo "CODEQL_PYTHON=$(which python)" >> $GITHUB_ENV
echo "CODEQL_PYTHON=/code/.venv/bin/python" >> $GITHUB_ENV

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: python
setup-python-dependencies: false

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
22 changes: 12 additions & 10 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,24 @@ jobs:
- uses: actions/setup-python@v5
with:
python-version: "3.13"
- name: Install Poetry
uses: snok/install-poetry@v1

- name: Install the latest version of uv
uses: astral-sh/setup-uv@v5
with:
version: 1.8.4
virtualenvs-create: true
virtualenvs-in-project: true
version: "0.5.15"

- name: Setup cache
uses: actions/cache@v4
with:
path: .venv
key: poetry-venv-${{ hashFiles('poetry.lock') }}
key: uv-venv-${{ hashFiles('uv.lock') }}

- name: Install dependencies
run: |
poetry install --no-interaction --no-root
uv sync

- name: Lint python projects
run: |
source .venv/bin/activate
ruff format . --check
ruff check .
uv run ruff format . --check
uv run ruff check .

88 changes: 46 additions & 42 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,80 +2,84 @@
# Uses multi-stage builds requiring Docker 17.05 or higher
# See https://docs.docker.com/develop/develop-images/multistage-build/

# Creating a python base with shared environment variables
# Creating a python base with shared dependencies
FROM python:3.13-bookworm AS python-base

RUN apt-get update \
&& apt-get install --no-install-recommends -y\
# non interactive frontend
ENV DEBIAN_FRONTEND=noninteractive

# Install essential tools
RUN apt-get update && apt-get install --no-install-recommends -y \
libsqlite3-mod-spatialite \
binutils \
libproj-dev \
gdal-bin
gdal-bin && \
apt-get clean && rm -rf /var/lib/apt/lists/*

# non interactive frontend
ENV DEBIAN_FRONTEND=noninteractive

ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100 \
POETRY_VERSION=1.8.4 \
POETRY_HOME="/opt/poetry" \
POETRY_VIRTUALENVS_IN_PROJECT=true \
POETRY_NO_INTERACTION=1 \
PYSETUP_PATH="/opt/pysetup" \
CODE_PATH="/code"
CODE_PATH="/code" \
VENV_PATH="/code/.venv"

# add poetry home to path
ENV PATH="$POETRY_HOME/bin:$PYSETUP_PATH/.venv/bin/:$PATH"
FROM python-base AS builder

FROM python-base AS builder-base
# Install curl and uv
RUN apt-get install -y curl && \
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/astral-sh/uv/releases/download/0.5.15/uv-installer.sh | sh && \
ln -s /root/.local/bin/uv /usr/local/bin/uv && \
apt-get clean && rm -rf /var/lib/apt/lists/*

RUN apt-get install --no-install-recommends -y \
software-properties-common \
curl \
build-essential
WORKDIR $CODE_PATH

RUN curl -sSL https://install.python-poetry.org | python
COPY pyproject.toml uv.lock ./

WORKDIR $PYSETUP_PATH
COPY poetry.lock pyproject.toml ./
# Install core dependencies
RUN uv sync --frozen --no-dev

RUN poetry install --no-dev
# Development stage
FROM python-base AS development

# testing stage
FROM python-base AS testing
WORKDIR $CODE_PATH

COPY --from=builder-base $POETRY_HOME $POETRY_HOME
COPY --from=builder-base $PYSETUP_PATH $PYSETUP_PATH
# Copy dependencies and source code
COPY --from=builder /usr/local/bin/uv /usr/local/bin/uv
COPY --from=builder $VENV_PATH $VENV_PATH
COPY . $CODE_PATH

# Use development entrypoint
ENTRYPOINT ["/code/docker/entrypoint.dev.sh"]

# Testing stage
FROM python-base AS testing

WORKDIR $CODE_PATH

ENTRYPOINT ["/code/docker/entrypoint.test.sh"]
# Copy dependencies and source code
COPY --from=builder /usr/local/bin/uv /usr/local/bin/uv
COPY --from=builder $VENV_PATH $VENV_PATH
COPY . $CODE_PATH

# development stage
FROM python-base AS development
# Use testing entrypoint
ENTRYPOINT ["/code/docker/entrypoint.test.sh"]

COPY --from=builder-base $POETRY_HOME $POETRY_HOME
COPY --from=builder-base $PYSETUP_PATH $PYSETUP_PATH
# Production build stage
FROM builder AS production-build

WORKDIR $CODE_PATH

ENTRYPOINT ["/code/docker/entrypoint.dev.sh"]
RUN uv sync --frozen --no-dev --extra production

# production stage
FROM builder-base AS production-build

RUN poetry install --no-root --no-dev --extras asgi

# production stage
# Production stage
FROM python-base AS production

COPY --from=production-build $PYSETUP_PATH $PYSETUP_PATH

WORKDIR $CODE_PATH

COPY --from=production-build $VENV_PATH $VENV_PATH
COPY . $CODE_PATH

ENV PATH="$VENV_PATH/bin:$PATH"

ENTRYPOINT [ "/code/docker/entrypoint.prod.sh"]
16 changes: 9 additions & 7 deletions docker/entrypoint.dev.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
#!/bin/sh
poetry install --no-root
# uv sync will also take care of the "dev" dependency
# Optional, we can also use "uv sync --group dev"
uv sync --frozen --no-install-project
if [ "$CELERY_WORKER" = "true" ]
then
if [ -z "$CELERY_QUEUES" ]
then
celery -A neatplus worker -l info
uv run celery -A neatplus worker -l info
else
celery -A neatplus worker -l info -Q "$CELERY_QUEUES"
uv run celery -A neatplus worker -l info -Q "$CELERY_QUEUES"
fi
else
poetry run python ./manage.py collectstatic --no-input
poetry run python ./manage.py migrate --no-input
poetry run python ./manage.py import_default_email_template
poetry run python ./manage.py runserver_plus 0.0.0.0:8000 || ./manage.py runserver 0.0.0.0:8000
uv run manage.py collectstatic --no-input
uv run manage.py migrate --no-input
uv run manage.py import_default_email_template
uv run manage.py runserver_plus 0.0.0.0:8000 || uv run manage.py runserver 0.0.0.0:8000
fi
6 changes: 3 additions & 3 deletions docker/entrypoint.test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
poetry install --no-root
poetry run python ./manage.py collectstatic --no-input
poetry run python ./manage.py test -v 3
uv sync --frozen --no-dev --group test
uv run manage.py collectstatic --no-input
uv run manage.py test -v 3
Loading
Loading