Skip to content

Commit dce77af

Browse files
committed
Update Dockerfile to use UV
1 parent 3c1583d commit dce77af

File tree

5 files changed

+44
-25
lines changed

5 files changed

+44
-25
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

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

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)