1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
# Use the Astral Python image that comes with UV.
FROM ghcr.io/astral-sh/uv:python3.13-bookworm
# Set HOME for user. Allows UV to work properly.
ENV HOME=/app
# Disable Python cache files.
ENV PYTHONDONTWRITEBYTECODE=1
# Send Python straight to the console instead of buffering it.
ENV PYTHONUNBUFFERED=1
# Create a directory to hold the app code and navigate into it.
WORKDIR /app
# Install required tools.
COPY --from=ghcr.io/astral-sh/uv:0.7.12 /uv /uvx /bin/
# Create a user.
RUN addgroup --system django && adduser --system --ingroup django django
# Install requirements
COPY pyproject.toml uv.lock .
ENV UV_VENV_MANAGED=0
RUN uv sync --locked
# Copy source to app directory.
COPY . .
# Ensure entrypoint script has the right permissions. Must be done before switching users.
RUN chmod +x entrypoint.sh && \
mkdir -p .cache && \
chown -R django:django .
# Switch to the non-root user.
USER django
ENTRYPOINT ["./entrypoint.sh"]
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
#!/bin/sh
set -e
if [ "$#" -gt 0 ]; then
exec "$@"
fi
echo "[ENTRYPOINT]: Applying migrations..."
uv run manage.py migrate
if [ "$DJANGO_DEBUG" = "True" ]; then
echo "[ENTRYPOINT]: Starting development server"
exec uv run manage.py runserver 0.0.0.0:8000
else
echo "[ENTRYPOINT]: Starting production server"
exec uv run python -m gunicorn --worker-tmp-dir /dev/shm orpheum.wsgi
fi
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
services:
backend:
build: .
container_name: backend
depends_on:
- db
environment:
DATABASE_URL: postgres://postgres:password@db:5432/db?sslmode=disable
DJANGO_SECRET_KEY: okb#$6^ey^76*rldc$x0^tn-5sc+f_cdb-*v(mz_*0n5oal4!$
DJANGO_DEBUG: "True"
ports:
- 8000:8000
volumes:
- .:/app
develop:
watch:
- action: sync
path: .
target: /app
ignore:
- .venv/
- action: rebuild
path: ./uv.lock
db:
image: postgres:15
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: db
volumes:
- db:/var/lib/postgresql/data
volumes:
db: