-
Notifications
You must be signed in to change notification settings - Fork 3
/
Dockerfile
66 lines (55 loc) · 1.88 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
# Build a base image for development and production stages.
# Note that this stage won't get thrown out so we need to think about
# layer sizes from this point on.
FROM registry.access.redhat.com/ubi9/nginx-122 as appbase
WORKDIR /usr/src/app
USER root
RUN chmod g+w /usr/src/app
# Copy requirement files.
COPY requirements.txt ./
# Install main project dependencies and clean up.
# Note that production dependencies are installed here as well since
# that is the default state of the image and development stages are
# just extras.
USER root
RUN dnf install -y \
postgresql \
postgresql-libs \
python3 \
python-unversioned-command \
postgresql-devel \
gcc \
python3-devel \
&& python3 -m ensurepip \
&& pip3 install --no-cache-dir -r ./requirements.txt \
&& dnf remove -y \
postgresql-devel \
gcc \
python3-devel \
&& dnf clean all \
&& rm -rf /var/cache/dnf
ENV STATIC_ROOT /var/parking-service/static
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
RUN mkdir -p /var/parking-service/static
# Build production image using the appbase stage as base. This should always
# be the last stage of Dockerfile.
FROM appbase as prod
# Copy application code.
COPY . ./
# /app/data needs write access for Django management commands to work
RUN mkdir -p ./data
RUN chgrp -R 0 ./data && chmod g+w -R ./data
# Collect static files
RUN SECRET_KEY="only-used-for-collectstatic" python3 manage.py collectstatic --noinput
# Copy NGINX conf
COPY nginx.conf /etc/nginx/nginx.conf
# link nginx logs to container stdout
RUN ln -sf /dev/stdout /var/log/nginx/access.log && ln -sf /dev/stderr /var/log/nginx/error.log
# Copy and set the entrypoint.
COPY docker-entrypoint.sh ./
RUN ["chmod", "+x", "/usr/src/app/docker-entrypoint.sh"]
ENTRYPOINT ["./docker-entrypoint.sh"]
# Document the port and set random user to simulate OpenShift behaviour
USER nobody:0
EXPOSE 8080/tcp