Skip to content

Commit c9b0359

Browse files
committed
Update Dockerfile to use UV
1 parent f928e0b commit c9b0359

File tree

9 files changed

+59
-37
lines changed

9 files changed

+59
-37
lines changed

.github/workflows/database.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ jobs:
5757
uses: actions/checkout@v5
5858
with:
5959
submodules: recursive
60-
- name: Install uv
61-
uses: astral-sh/setup-uv@v7
6260
- name: Build
6361
run: |
6462
docker compose -f docker-compose.yml -f docker-compose-dev.yml up -d

Makefile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,16 @@ docker-up: # (Docker) Create services/volumes/networks
4747
docker compose up -d
4848

4949
docker-migrate: # (Docker) Run any pending migrations
50-
docker compose exec -T app python manage.py migrate ${docker_config}
50+
docker compose --verbose exec -T app uv run manage.py migrate ${docker_config}
5151

5252
docker-build-db: # (Docker) Build the database
53-
docker compose exec -T app sh -c 'echo "from data.v2.build import build_all; build_all()" | python manage.py shell ${docker_config}'
53+
docker compose exec -T app sh -c 'echo "from data.v2.build import build_all; build_all()" | uv run manage.py shell ${docker_config}'
5454

5555
docker-make-migrations: # (Docker) Create migrations files if schema has changed
56-
docker compose exec -T app sh -c 'python manage.py makemigrations ${docker_config}'
56+
docker compose exec -T app sh -c 'uv run manage.py makemigrations ${docker_config}'
5757

5858
docker-flush-db: # (Docker) Removes all the data present in the database but preserves tables and migrations
59-
docker compose exec -T app sh -c 'python manage.py flush --no-input ${docker_config}'
59+
docker compose exec -T app sh -c 'uv run manage.py flush --no-input ${docker_config}'
6060

6161
docker-destroy-db: # (Docker) Removes the volume where the database is installed on, alongside to the container itself
6262
docker rm -f pokeapi_db_1
@@ -72,7 +72,7 @@ docker-down: # (Docker) Stop and removes containers and networks
7272
docker compose down
7373

7474
docker-test: # (Docker) Run tests
75-
docker compose exec -T app python manage.py test ${local_config}
75+
docker compose exec -T app uv run manage.py test ${local_config}
7676

7777
docker-prod:
7878
docker compose -f docker-compose.yml -f docker-compose.override.yml -f Resources/compose/docker-compose-prod-graphql.yml up -d
@@ -130,10 +130,10 @@ kustomize-ga-apply: # (Kustomize) Run kubectl apply -k on the connected k8s clu
130130
kubectl apply -k Resources/k8s/kustomize/ga/
131131

132132
k8s-migrate: # (k8s) Run any pending migrations
133-
kubectl exec --namespace pokeapi deployment/pokeapi -- python manage.py migrate ${docker_config}
133+
kubectl exec --namespace pokeapi deployment/pokeapi -- uv run manage.py migrate ${docker_config}
134134

135135
k8s-build-db: # (k8s) Build the database
136-
kubectl exec --namespace pokeapi deployment/pokeapi -- sh -c 'echo "from data.v2.build import build_all; build_all()" | python manage.py shell ${docker_config}'
136+
kubectl exec --namespace pokeapi deployment/pokeapi -- sh -c 'echo "from data.v2.build import build_all; build_all()" | uv run manage.py shell ${docker_config}'
137137

138138
k8s-delete: # (k8s) Delete pokeapi namespace
139139
kubectl delete namespace pokeapi

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ A RESTful API for Pokémon - [pokeapi.co](https://pokeapi.co)
2323

2424
## Table of Contents
2525

26-
- [Setup](#setup)
26+
- [Table of Contents](#table-of-contents)
27+
- [Setup   ](#setup---)
2728
- [Database setup](#database-setup)
28-
- [Docker and Compose](#docker-and-compose)
29-
- [GraphQL](#graphql)
30-
- [Kubernetes](#kubernetes)
29+
- [Docker and Compose   ](#docker-and-compose---)
30+
- [GraphQL   ](#graphql---)
31+
- [Kubernetes   ](#kubernetes---)
3132
- [Wrappers](#wrappers)
3233
- [Donations](#donations)
3334
- [Join Us On Slack!](#join-us-on-slack)
@@ -99,8 +100,8 @@ If you don't have `make` on your machine you can use the following commands
99100
100101
```sh
101102
docker compose up -d
102-
docker compose exec -T app python manage.py migrate --settings=config.docker-compose
103-
docker compose exec -T app sh -c 'echo "from data.v2.build import build_all; build_all()" | python manage.py shell --settings=config.docker-compose'
103+
docker compose exec -T app uv run manage.py migrate --settings=config.docker-compose
104+
docker compose exec -T app sh -c 'echo "from data.v2.build import build_all; build_all()" | uv run manage.py shell --settings=config.docker-compose'
104105
```
105106
106107
Browse [localhost/api/v2/](http://localhost/api/v2/) or [localhost/api/v2/pokemon/bulbasaur/](http://localhost/api/v2/pokemon/bulbasaur/) on port `80`.
@@ -151,8 +152,8 @@ Configure `kubectl` to point to a cluster and then run the following commands to
151152
kubectl apply -k Resources/k8s/kustomize/base/
152153
kubectl config set-context --current --namespace pokeapi # (Optional) Set pokeapi ns as the working ns
153154
# Wait for the cluster to spin up
154-
kubectl exec --namespace pokeapi deployment/pokeapi -- python manage.py migrate --settings=config.docker-compose # Migrate the DB
155-
kubectl exec --namespace pokeapi deployment/pokeapi -- sh -c 'echo "from data.v2.build import build_all; build_all()" | python manage.py shell --settings=config.docker-compose' # Build the db
155+
kubectl exec --namespace pokeapi deployment/pokeapi -- uv run manage.py migrate --settings=config.docker-compose # Migrate the DB
156+
kubectl exec --namespace pokeapi deployment/pokeapi -- sh -c 'echo "from data.v2.build import build_all; build_all()" | uv run manage.py shell --settings=config.docker-compose' # Build the db
156157
kubectl wait --namespace pokeapi --timeout=120s --for=condition=complete job/load-graphql # Wait for Graphql configuration job to finish
157158
```
158159

Resources/docker/app/Dockerfile

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,32 @@
11
FROM python:3.13.7-alpine AS builder
22

33
ENV PYTHONUNBUFFERED=1
4+
ENV DJANGO_SETTINGS_MODULE='config.docker-compose'
45

56
RUN mkdir /code
67
WORKDIR /code
78

8-
ADD requirements.txt /code/
9-
RUN apk add --no-cache postgresql-libs libstdc++
10-
RUN apk add --no-cache --virtual .build-deps gcc g++ musl-dev \
11-
postgresql-dev binutils rust cargo && \
12-
python3 -m pip install -r requirements.txt --no-cache-dir
13-
14-
FROM python:3.13.7-alpine
15-
16-
ENV PYTHONUNBUFFERED=1
17-
ENV DJANGO_SETTINGS_MODULE='config.docker-compose'
9+
# Install UV
10+
RUN apk add --no-cache curl
11+
RUN curl -LsSf https://astral.sh/uv/install.sh | sh
1812

19-
RUN mkdir /code
20-
WORKDIR /code
13+
# Add UV to PATH for this stage
14+
ENV PATH="/root/.local/bin:$PATH"
2115

22-
COPY --from=builder /usr/local/lib/python3.13/site-packages /usr/local/lib/python3.13/site-packages
23-
COPY --from=builder /usr/local/bin /usr/local/bin
16+
# Copy dependency files
17+
ADD pyproject.toml uv.lock* /code/
2418

25-
ADD . /code/
19+
# Install dependencies
20+
RUN apk add --no-cache postgresql-libs libstdc++
21+
RUN apk add --no-cache --virtual .build-deps gcc g++ musl-dev \
22+
postgresql-dev binutils rust cargo && \
23+
uv sync --frozen
2624

2725
RUN addgroup -g 1000 -S pokeapi && \
2826
adduser -u 1000 -S pokeapi -G pokeapi
2927
USER pokeapi
3028

31-
CMD ["gunicorn", "config.wsgi:application", "-c", "gunicorn.conf.py"]
29+
30+
CMD ["uv", "run", "gunicorn", "config.wsgi:application", "-c", "gunicorn.conf.py"]
3231

3332
EXPOSE 80

Resources/docker/app/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@ Pokémon data isn't automatically present in this image. All Pokémon data is pe
4646
When the container is up and running, run the following shell commands:
4747

4848
```sh
49-
docker exec pokeapi python manage.py migrate --settings=config.docker-compose
50-
docker exec pokeapi sh -c 'echo "from data.v2.build import build_all; build_all()" | python manage.py shell --settings=config.docker-compose'
49+
docker exec pokeapi uv run manage.py migrate --settings=config.docker-compose
50+
docker exec pokeapi sh -c 'echo "from data.v2.build import build_all; build_all()" | uv run manage.py shell --settings=config.docker-compose'
5151
```

Resources/scripts/wait.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ wait_for_http() {
88
echo "Waiting for $url"
99
while [ "$(date +%s)" -lt "$end_time" ]; do # Loop until interval has elapsed.
1010
sleep 2
11+
echo "Checking $url"
1112
if [ "$(curl -s -o /dev/null -L -w '%{http_code}' "$url")" == "200" ]; then
1213
success='true'
1314
break
1415
fi
16+
echo "$(curl -s -o /dev/null -L -w '%{http_code}' "$url")"
1517
done
1618
if [ "$success" = 'true' ]; then
1719
exit 0
@@ -20,4 +22,4 @@ wait_for_http() {
2022
fi
2123
}
2224

23-
wait_for_http "${1:-http://localhost/api/v2/}"
25+
wait_for_http "${1:-http://localhost/api/v2/}"

data/v2/build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# To build out the data you'll need to jump into the Django shell
22
#
3-
# $ python manage.py shell
3+
# $ uv run manage.py shell
44
#
55
# and run the build script with
66
#

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ dependencies = [
1414
"drf-spectacular==0.29.0",
1515
"gunicorn==23.0.0",
1616
"psycopg==3.3.2",
17+
"psycopg2-binary>=2.9.11",
1718
"ruff>=0.14.14",
1819
"ty>=0.0.14",
1920
]

uv.lock

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)