Skip to content

Commit 084ba63

Browse files
committed
Update Dockerfile to use UV
1 parent 2a37067 commit 084ba63

2 files changed

Lines changed: 25 additions & 11 deletions

File tree

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 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: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,21 @@ ENV PYTHONUNBUFFERED=1
55
RUN mkdir /code
66
WORKDIR /code
77

8-
ADD requirements.txt /code/
8+
# Install UV
9+
RUN apk add --no-cache curl
10+
RUN curl -LsSf https://astral.sh/uv/install.sh | sh
11+
12+
# Add UV to PATH for this stage
13+
ENV PATH="/root/.local/bin:$PATH"
14+
15+
# Copy dependency files
16+
ADD pyproject.toml uv.lock* /code/
17+
18+
# Install dependencies
919
RUN apk add --no-cache postgresql-libs libstdc++
1020
RUN apk add --no-cache --virtual .build-deps gcc g++ musl-dev \
1121
postgresql-dev binutils rust cargo && \
12-
python3 -m pip install -r requirements.txt --no-cache-dir
22+
uv sync --frozen
1323

1424
FROM python:3.13.7-alpine
1525

@@ -19,15 +29,19 @@ ENV DJANGO_SETTINGS_MODULE='config.docker-compose'
1929
RUN mkdir /code
2030
WORKDIR /code
2131

32+
# Copy the entire virtual environment from builder
33+
COPY --from=builder /code /code
2234
COPY --from=builder /usr/local/lib/python3.13/site-packages /usr/local/lib/python3.13/site-packages
2335
COPY --from=builder /usr/local/bin /usr/local/bin
2436

25-
ADD . /code/
37+
# Install runtime dependencies
38+
RUN apk add --no-cache postgresql-libs libstdc++
2639

2740
RUN addgroup -g 1000 -S pokeapi && \
2841
adduser -u 1000 -S pokeapi -G pokeapi
2942
USER pokeapi
3043

31-
CMD ["gunicorn", "config.wsgi:application", "-c", "gunicorn.conf.py"]
44+
# Use Python directly to run gunicorn from the installed packages
45+
CMD ["python", "-m", "gunicorn", "config.wsgi:application", "-c", "gunicorn.conf.py"]
3246

3347
EXPOSE 80

0 commit comments

Comments
 (0)