-
Notifications
You must be signed in to change notification settings - Fork 11
/
Dockerfile
70 lines (52 loc) · 2.31 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
64
65
66
67
68
69
70
FROM python:3.11 as production
# Update the package listing, so we know what packages exist
RUN apt-get update
# Install security updates:
RUN apt-get upgrade --yes
# Install nodejs, so we are able to generate our front end bundles with tailwind
RUN curl https://deb.nodesource.com/setup_18.x > /tmp/setup_18.x.sh
RUN bash /tmp/setup_18.x.sh
RUN apt-get install nodejs --no-install-recommends --yes
# Delete cached files we don't need anymore
RUN apt-get clean
# Delete index files we don't need anymore:
RUN rm -rf /var/lib/apt/lists/*
# Install dependencies in a virtualenv
ENV VIRTUAL_ENV=/app/.venv
RUN useradd deploy --create-home && mkdir /app $VIRTUAL_ENV && chown -R deploy /app $VIRTUAL_ENV
WORKDIR /app
# Adding the virtual environment to the path saves us needing to
# run `source /app/.venv/bin/activate`, and adding python path
# makes it easier to run manage.py commands
ENV PATH=$VIRTUAL_ENV/bin:$PATH \
PYTHONPATH=/app
# Default port exposed by this container
EXPOSE 9000
# We don't want to use root. We use this user elsewhere without docker
# so we keep the same name for consistency
USER deploy
# Set up our virtual env directory
RUN python -m venv $VIRTUAL_ENV
# Add our python libraries for managing dependencies
uv 0.1.43 is triggering bad certificate errors, so we pin to 0.1.39
RUN python -m pip install uv==0.1.39 wheel --upgrade
# Copy application code, with dockerignore filtering out the stuff we don't want
# from our final build artefact
COPY --chown=deploy . .
# Install dependencies via uv
RUN uv pip install -r requirements/requirements.linux.generated.txt
# Set up front end pipeline
RUN python ./manage.py tailwind install
RUN python ./manage.py tailwind build
# Install the other node dependencies
# TODO: we might not need node in production *at all* if we can generate
# the static files in the build step. Investigate if this results
# in meaningful savings on the final image size
WORKDIR /app
RUN cd ./apps/theme/static_src/ && \
npx rollup --config
# Collect static files
RUN python ./manage.py collectstatic --noinput --clear
# Use the shell form of CMD, so we have access to our environment variables
# $GUNICORN_CMD_ARGS allows us to add additional arguments to the gunicorn command
CMD gunicorn greenweb.wsgi --bind $GUNICORN_BIND_IP:$PORT --config gunicorn.conf.py $GUNICORN_CMD_ARGS