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
9 changes: 6 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
FROM python:3.13-slim AS dev
FROM python:3.14-slim AS dev
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/

RUN apt-get update -y && apt-get install -y \
gcc \
libpq-dev \
git \
file \
make \
&& rm -rf /var/lib/apt/lists/*

# Copying requirements of a project
Expand All @@ -15,13 +18,13 @@ ENV UV_SYSTEM_PYTHON=1
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-install-project
uv sync --locked --no-install-project

# Copy the project into the image
COPY . /app/
# Install the project
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen
uv sync --locked

ENV PATH="/app/.venv/bin:$PATH"
ENV DOCKER_RUNNING=1
Expand Down
13 changes: 7 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ services:
build:
context: .
target: dev
command:
bash -c "uv run alembic upgrade head && uvicorn app.main:app --host
command: bash -c "uv run alembic upgrade head && uvicorn app.main:app --host
0.0.0.0 --port 8001 --reload"
volumes:
- .:/app/src/
- .:/app/
- /app/.venv
env_file:
- .env
environment:
Expand All @@ -22,22 +22,23 @@ services:
condition: service_healthy

db:
image: postgres:17.3-bullseye
image: postgres:18.1-bookworm
hostname: postgres
environment:
POSTGRES_USER: ${DB_USER}
POSTGRES_PASSWORD: ${DB_PASSWORD}
POSTGRES_DB: ${DB_NAME}
POSTGRES_TEST_DB: ${TEST_DB_NAME}
PGDATA: /var/lib/postgresql/18/docker
volumes:
- api-db-data:/var/lib/postgresql/data
- api-db-data:/var/lib/postgresql/18/data
- ./docker_support/create-test-db.sh:/docker-entrypoint-initdb.d/create-test-db.sh
ports:
- 5433:${DB_PORT}
networks:
- api-network
healthcheck:
test: pg_isready -U ${DB_USER} -d ${DB_NAME}
test: ["CMD-SHELL", "pg_isready -U ${DB_USER} -d ${DB_NAME}"]
interval: 2s
timeout: 3s
retries: 40
Expand Down
46 changes: 37 additions & 9 deletions docs/development/docker.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
# Develop with Docker

!!! warning "PostgreSQL 18 Upgrade (Release 0.8.0)"
As of release `0.8.0`, we have upgraded PostgreSQL from version 17 to 18.1.
This version is not compatible with existing PostgreSQL 17 databases.

You will need to either:

1. **Delete and recreate** the database volume:
```console
docker compose down
docker volume rm api-db-data
docker compose up
```
2. **Dump and reload** your existing data before upgrading (see PostgreSQL
documentation for migration guides)

## Python and PostgreSQL versions

Currently, the Docker confguration uses Python version `3.13` and PostgreSQL
version `17` (or the latest patch version of each).
Currently, the Docker configuration uses Python version `3.14` and PostgreSQL
version `18.1` (or the latest patch version of each).

!!! warning "Database Version Changes"
At times we will update the Docker configurations to use a newer version of
Expand Down Expand Up @@ -77,14 +92,27 @@ docker compose build

## Database Administration

At this time, the CLI tool is not available in the Docker container, so you will
need to use an external tool such as `pgAdmin4` to manage the database. Note
that the database is exposed on port `5433` and the default username and
password are those set in your `.env` file.
The `api-admin` CLI tool is fully functional within the Docker container. You can
run any `api-admin` commands using:

```console
docker compose run --rm api api-admin <command>
```

Alternatively, you can use an external tool such as `pgAdmin4` to manage the
database. Note that the database is exposed on port `5433` and the default
username and password are those set in your `.env` file.

## Local File Changes

The Docker configuration uses volume mounting to ensure that any changes you make
to your local files (including source code and tests) are immediately reflected
in the running container. This means you don't need to rebuild the Docker image
every time you make a code change.

In the future I will try to get the `api-admin` tool working inside the Docker
container. The issue is getting this to work without destroying my local `.venv`
folder.
Your local `.venv` directory is protected and will not be affected by the
container's virtual environment, so you can safely develop both locally and
within Docker without conflicts.

## Run Tests

Expand Down
5 changes: 4 additions & 1 deletion tests/cli/test_cli_custom_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

def is_running_in_docker() -> bool:
"""Check for the .dockerenv file."""
return os.path.exists("/.dockerenv") # noqa: PTH110
return os.path.exists("/.dockerenv") or bool(os.getenv("DOCKER_RUNNING")) # noqa: PTH110


class TestCLI:
Expand Down Expand Up @@ -322,6 +322,9 @@ def test_full_metadata_command_cant_write_metadata(
assert result.exit_code == 2, "The metadata file should not be writable" # noqa: PLR2004
assert "Cannot Write the metadata" in result.output

@pytest.mark.skipif(
is_running_in_docker(), reason="This test fails under docker"
)
def test_metadata_command_cant_write_toml(self, runner, fs_setup) -> None:
"""Test the metadata command fails if pyproject.toml is not writable."""
# Make the file readable but not writable
Expand Down