-
Notifications
You must be signed in to change notification settings - Fork 7
/
Dockerfile
63 lines (46 loc) · 1.55 KB
/
Dockerfile
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Build stage
FROM python:3.9 AS builder
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# Set the working directory in the container
WORKDIR /app
# Install system dependencies, including gettext
RUN apt-get update && apt-get install -y \
gettext \
&& rm -rf /var/lib/apt/lists/*
# Install Poetry
RUN pip install poetry
# Copy only pyproject.toml and poetry.lock (if it exists)
COPY pyproject.toml poetry.lock* ./
# Install project dependencies
RUN poetry config virtualenvs.create false \
&& poetry install --no-interaction --no-ansi --no-root
# Copy the project code into the container
COPY . .
# Ensure the env variables are present -- although they won't be used
# during the build, they need to be set.
COPY .env.example .env
# Install the project itself
RUN poetry install --no-interaction --no-ansi --no-root
# Collect static files
RUN make sass
RUN python manage.py collectstatic --noinput
# Compile translations
RUN python manage.py compilemessages
# Run stage
FROM python:3.9-slim
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV PORT 8000
# Set the working directory in the container
WORKDIR /app
# Copy the installed dependencies and project files from the builder stage
COPY --from=builder /usr/local/lib/python3.9/site-packages /usr/local/lib/python3.9/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin
COPY --from=builder /app /app
# Expose the port the app runs on
EXPOSE ${PORT}
# Start the application
CMD gunicorn --bind 0.0.0.0:${PORT} web.wsgi:application