-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
60 lines (48 loc) · 1.64 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
# Use python 3.9 as base image with alpine 3.13 as base OS
FROM python:3.9-alpine3.13
# Set maintainer
LABEL maintainer="Daniel White"
# Print output from python directly to terminal
ENV PYTHONNUNBUFFERED 1
# Copy requirements.txt in to the Docker Image
COPY ./requirements.txt /tmp/requirements.txt
# Copy dev requirements in to the Docker Image
COPY ./requirements.dev.txt /tmp/requirements.dev.txt
# Copy scripts directory in to the Docker Image
COPY ./scripts /scripts
# Copy app directory in to the Docker Image
COPY ./app /app
# Work in the /app directory
WORKDIR /app
# Expose port 8000
EXPOSE 8000
# Create a virtual environment, install pip and dependencies, remove temp files and create a user
ARG DEV=false
RUN python -m venv /py && \
/py/bin/pip install --upgrade pip && \
apk add --update --no-cache --virtual .tmp-build-deps \
build-base musl-dev zlib zlib-dev linux-headers && \
/py/bin/pip install -r /tmp/requirements.txt && \
if [ $DEV = "true" ]; \
then /py/bin/pip install -r /tmp/requirements.dev.txt ; \
fi && \
rm -rf /tmp && \
apk del .tmp-build-deps && \
adduser \
--disabled-password \
--no-create-home \
django-user && \
mkdir -p /vol/web/media && \
mkdir -p /vol/web/static && \
mkdir -p /vol/db && \
chown django-user:django-user /vol/db && \
chmod 755 /vol/db && \
chown -R django-user:django-user /vol && \
chmod -R 755 /vol && \
chmod -R +x /scripts
# Add the virtual environment to the path environment variable
ENV PATH="/scripts:/py/bin:$PATH"
# Switch to the django-user user
USER django-user
# Run the run.sh script
CMD ["run.sh"]