Skip to content

Commit e6926f1

Browse files
authored
Merge pull request #786 from seapagan/freshen-docker-config
Freshen docker config
2 parents 17aeba6 + 61e965c commit e6926f1

File tree

4 files changed

+54
-19
lines changed

4 files changed

+54
-19
lines changed

Dockerfile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
FROM python:3.13-slim AS dev
1+
FROM python:3.14-slim AS dev
22
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
33

44
RUN apt-get update -y && apt-get install -y \
55
gcc \
66
libpq-dev \
7+
git \
8+
file \
9+
make \
710
&& rm -rf /var/lib/apt/lists/*
811

912
# Copying requirements of a project
@@ -15,13 +18,13 @@ ENV UV_SYSTEM_PYTHON=1
1518
RUN --mount=type=cache,target=/root/.cache/uv \
1619
--mount=type=bind,source=uv.lock,target=uv.lock \
1720
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
18-
uv sync --frozen --no-install-project
21+
uv sync --locked --no-install-project
1922

2023
# Copy the project into the image
2124
COPY . /app/
2225
# Install the project
2326
RUN --mount=type=cache,target=/root/.cache/uv \
24-
uv sync --frozen
27+
uv sync --locked
2528

2629
ENV PATH="/app/.venv/bin:$PATH"
2730
ENV DOCKER_RUNNING=1

docker-compose.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ services:
44
build:
55
context: .
66
target: dev
7-
command:
8-
bash -c "uv run alembic upgrade head && uvicorn app.main:app --host
7+
command: bash -c "uv run alembic upgrade head && uvicorn app.main:app --host
98
0.0.0.0 --port 8001 --reload"
109
volumes:
11-
- .:/app/src/
10+
- .:/app/
11+
- /app/.venv
1212
env_file:
1313
- .env
1414
environment:
@@ -22,22 +22,23 @@ services:
2222
condition: service_healthy
2323

2424
db:
25-
image: postgres:17.3-bullseye
25+
image: postgres:18.1-bookworm
2626
hostname: postgres
2727
environment:
2828
POSTGRES_USER: ${DB_USER}
2929
POSTGRES_PASSWORD: ${DB_PASSWORD}
3030
POSTGRES_DB: ${DB_NAME}
3131
POSTGRES_TEST_DB: ${TEST_DB_NAME}
32+
PGDATA: /var/lib/postgresql/18/docker
3233
volumes:
33-
- api-db-data:/var/lib/postgresql/data
34+
- api-db-data:/var/lib/postgresql/18/data
3435
- ./docker_support/create-test-db.sh:/docker-entrypoint-initdb.d/create-test-db.sh
3536
ports:
3637
- 5433:${DB_PORT}
3738
networks:
3839
- api-network
3940
healthcheck:
40-
test: pg_isready -U ${DB_USER} -d ${DB_NAME}
41+
test: ["CMD-SHELL", "pg_isready -U ${DB_USER} -d ${DB_NAME}"]
4142
interval: 2s
4243
timeout: 3s
4344
retries: 40

docs/development/docker.md

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
11
# Develop with Docker
22

3+
!!! warning "PostgreSQL 18 Upgrade (Release 0.8.0)"
4+
As of release `0.8.0`, we have upgraded PostgreSQL from version 17 to 18.1.
5+
This version is not compatible with existing PostgreSQL 17 databases.
6+
7+
You will need to either:
8+
9+
1. **Delete and recreate** the database volume:
10+
```console
11+
docker compose down
12+
docker volume rm api-db-data
13+
docker compose up
14+
```
15+
2. **Dump and reload** your existing data before upgrading (see PostgreSQL
16+
documentation for migration guides)
17+
318
## Python and PostgreSQL versions
419

5-
Currently, the Docker confguration uses Python version `3.13` and PostgreSQL
6-
version `17` (or the latest patch version of each).
20+
Currently, the Docker configuration uses Python version `3.14` and PostgreSQL
21+
version `18.1` (or the latest patch version of each).
722

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

7893
## Database Administration
7994

80-
At this time, the CLI tool is not available in the Docker container, so you will
81-
need to use an external tool such as `pgAdmin4` to manage the database. Note
82-
that the database is exposed on port `5433` and the default username and
83-
password are those set in your `.env` file.
95+
The `api-admin` CLI tool is fully functional within the Docker container. You can
96+
run any `api-admin` commands using:
97+
98+
```console
99+
docker compose run --rm api api-admin <command>
100+
```
101+
102+
Alternatively, you can use an external tool such as `pgAdmin4` to manage the
103+
database. Note that the database is exposed on port `5433` and the default
104+
username and password are those set in your `.env` file.
105+
106+
## Local File Changes
107+
108+
The Docker configuration uses volume mounting to ensure that any changes you make
109+
to your local files (including source code and tests) are immediately reflected
110+
in the running container. This means you don't need to rebuild the Docker image
111+
every time you make a code change.
84112

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

89117
## Run Tests
90118

tests/cli/test_cli_custom_command.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

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

3636

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

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

0 commit comments

Comments
 (0)