-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
83 lines (56 loc) · 2.36 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
FROM alpine:latest AS builder
# Set DEPLOY=1 environnement variable
ENV DEPLOY=1
# Install dependencies
RUN apk update
RUN apk upgrade --available
RUN apk add --no-cache git python3 python3-dev py-pip tzdata mariadb-client mariadb-connector-c-dev gcc musl-dev rust cargo libffi-dev mariadb-dev
RUN pip3 install --upgrade --break-system-packages virtualenv wheel
# Add an user
# RUN useradd -ms /bin/bash workshop
RUN adduser -D workshop
# We copy the files from the parent directory
COPY . Upsilon-Workshop-API-Django
# Remove the .git folder
RUN rm -rf Upsilon-Workshop-API-Django/.git
# Change the owner of the files
RUN chown -R workshop:workshop Upsilon-Workshop-API-Django
# Run as the user
USER workshop
WORKDIR Upsilon-Workshop-API-Django
# Create a virtual environment
RUN virtualenv -p python3 venv
# Activate the virtual environment
ENV PATH="/Upsilon-Workshop-API-Django/venv/bin:${PATH}"
# Install the dependencies
RUN pip3 install -r requirements.txt gunicorn
# RUN python3 manage.py migrate
RUN python3 manage.py collectstatic --noinput
# Replace `ALLOWED_HOSTS: list[str] = []` with `ALLOWED_HOSTS: list[str] = ["0.0.0.0"]` in `workshop/settings.py`
RUN sed -i 's/ALLOWED_HOSTS: list\[str\] = \[\]/ALLOWED_HOSTS: list\[str\] = \["*"\]/g' workshop/settings.py
# Expose the port
EXPOSE 80
# Entrypoint
CMD ["sh", "-c", "sh ./deploy/prepare_run.sh && python3 $(which gunicorn) workshop.wsgi --bind 0.0.0.0:8000"]
# Deployment image (no build dependencies)
FROM alpine:latest
# Set DEPLOY=1 environnement variable
ENV DEPLOY=1
# Install dependencies
RUN apk update && apk upgrade --available && apk add --no-cache mariadb-client mariadb-connector-c tzdata python3
# Add an user
RUN adduser -D workshop
# Copy the files from the builder image
COPY --from=builder /Upsilon-Workshop-API-Django /home/workshop/Upsilon-Workshop-API-Django
# Activate the virtual environment
ENV PATH="/home/workshop/Upsilon-Workshop-API-Django/venv/bin:${PATH}"
# Change the owner of the files
RUN chown -R workshop:workshop /home/workshop/Upsilon-Workshop-API-Django
# Run as the user
USER workshop
# Set the working directory
WORKDIR /home/workshop/Upsilon-Workshop-API-Django
# Expose the port
EXPOSE 80
# Entrypoint
CMD ["sh", "-c", "source venv/bin/activate && deactivate && source venv/bin/activate && sh ./deploy/prepare_run.sh && python3 $(which gunicorn) workshop.wsgi --bind 0.0.0.0:8000"]