-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
130 lines (93 loc) · 2.93 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# Use the official Python image from the Docker Hub
FROM python:3.12-slim-bookworm AS BASE
ARG UID
ARG GID
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# Add system packages required to RUN your application here.
RUN set -ex; \
apt-get update; \
apt-get install -y --no-install-recommends \
gpg \
gpg-agent \
dirmngr \
libpq5; \
rm -rf /var/lib/apt/lists/*
# Create user
RUN set -ex; \
groupadd --gid $GID app; \
useradd --create-home --uid $UID --gid app app
# Set work directory
WORKDIR /home/app
# BUILDER
# Creates a virtual environment with all dependencies.
FROM base AS builder
# Add system packages required to BUILD your application here.
RUN set -ex; \
apt-get update; \
apt-get install -y --no-install-recommends \
build-essential \
pkg-config \
libpq-dev \
; \
rm -rf /var/lib/apt/lists/*
USER app
RUN \
--mount=type=bind,source=requirements.txt,target=/home/app/requirements.txt \
set -ex; \
python -m venv /home/app/venv; \
. /home/app/venv/bin/activate; \
pip install --upgrade pip; \
pip install --no-cache-dir -r /home/app/requirements.txt
ENV VIRTUAL_ENV="/home/app/venv" \
PATH="/home/app/venv/bin:$PATH"
RUN \
--mount=type=bind,source=oekostrom_db,target=/home/app/oekostrom_db \
set -ex; \
python /home/app/oekostrom_db/manage.py collectstatic --no-input
# Image containing the application.
FROM base AS app
ENV VIRTUAL_ENV="/home/app/venv" \
PATH="/home/app/venv/bin:$PATH"
COPY log_key.asc /home/app
COPY entrypoint.sh /home/app/entrypoint.sh
COPY oekostrom-recherche/scraped_data /home/app/oekostrom-recherche/scraped_data
RUN set -ex; \
mkdir -p /home/app/.gnupg; \
chmod 700 /home/app/.gnupg; \
echo "use-agent: no\n" >> /home/app/.gnupg/gpg.conf; \
chown -R app:app /home/app; \
chmod a+rx /home/app/entrypoint.sh
USER app
RUN gpg --batch --import /home/app/log_key.asc
# Copy the virtual environment from the builder.
COPY --from=builder /home/app/venv /home/app/venv
# Set up entrypoint
ENTRYPOINT ["/home/app/entrypoint.sh"]
EXPOSE 8000
# Develop
FROM app as development
CMD ["/home/app/oekostrom_db/dev.sh" ]
FROM nginx:mainline-bookworm as nginx
# copy non root config
COPY nginx.conf /etc/nginx/nginx.conf
COPY nginx_site.conf.template /etc/nginx/templates/default.conf.template
RUN mkdir -p /home/app
COPY --from=builder /home/app/static /home/app/static
COPY favicon.ico /home/app/static/favicon.ico
# ensure write permisisons are okay
RUN set -ex; \
chmod -R a+rX /home; \
chown -R nginx:nginx /etc/nginx/; \
chmod -R u+rwX /etc/nginx
# TODO create a docker-entrypoint script that makes config ro again
USER nginx
# PRODUCTION
FROM app as production
# Copy project
COPY oekostrom_db /home/app/oekostrom_db
EXPOSE 8000
WORKDIR /home/app
# Command to run Daphne server
CMD ["daphne", "-b", "0.0.0.0", "-p", "8000", "oekostrom_db.asgi:application"]