-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerFile
141 lines (101 loc) · 3.35 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
131
132
133
134
135
136
137
138
139
140
141
# Set the python version as a build-time argument
# with Python 3.12 as the default
ARG PYTHON_VERSION=3.12-slim-bullseye
FROM python:${PYTHON_VERSION}
# Create a virtual environment
RUN python -m venv /opt/venv
# Set the virtual environment as the current location
ENV PATH=/opt/venv/bin:$PATH
# Upgrade pip
RUN pip install --upgrade pip
# Set Python-related environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# Install os dependencies for our mini vm
RUN apt-get update && apt-get install -y \
# for postgres
libpq-dev \
# for Pillow
libjpeg-dev \
# for CairoSVG
libcairo2 \
# other
gcc \
&& rm -rf /var/lib/apt/lists/*
# Create the mini vm's code directory
RUN mkdir -p /code
# Set the working directory to that same code directory
WORKDIR /code
# Copy the requirements file into the container
COPY requirements.txt /tmp/requirements.txt
# copy the project code into the container's working directory
COPY ./src /code
# Install the Python project requirements
RUN pip install -r /tmp/requirements.txt
ARG DJANGO_SECRET_KEY
ENV DJANGO_SECRET_KEY=${DJANGO_SECRET_KEY}
ARG DJANGO_DEBUG=0
ENV DJANGO_DEBUG=${DJANGO_DEBUG}
ARG AWS_ACCESS_KEY_ID
ENV AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
ARG AWS_SECRET_ACCESS_KEY
ENV AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
ARG AWS_BUCKET_NAME
ENV AWS_BUCKET_NAME=${AWS_BUCKET_NAME}
ARG AWS_S3_REGION_NAME
ENV AWS_S3_REGION_NAME=${AWS_S3_REGION_NAME}
ARG ENVIRONMENT
ENV ENVIRONMENT=${ENVIRONMENT}
ARG CONN_MAX_AGE
ENV CONN_MAX_AGE=${CONN_MAX_AGE}
# ARG DATABASE_URL
# ENV DATABASE_URL=${DATABASE_URL}
ARG EMAIL_HOST
ENV EMAIL_HOST=${EMAIL_HOST}
ARG EMAIL_PORT
ENV EMAIL_PORT=${EMAIL_PORT}
ARG EMAIL_USE_TLS
ENV EMAIL_USE_TLS=${EMAIL_USE_TLS}
ARG EMAIL_USE_SSL
ENV EMAIL_USE_SSL=${EMAIL_USE_SSL}
ARG EMAIL_HOST_USER
ENV EMAIL_HOST_USER=${EMAIL_HOST_USER}
ARG EMAIL_HOST_PASSWORD
ENV EMAIL_HOST_PASSWORD=${EMAIL_HOST_PASSWORD}
ARG ADMIN_USER_NAME
ENV ADMIN_USER_NAME=${ADMIN_USER_NAME}
ARG ADMIN_USER_EMAIL
ENV ADMIN_USER_EMAIL=${ADMIN_USER_EMAIL}
ARG GITHUB_CLIENT_ID
ENV GITHUB_CLIENT_ID=${GITHUB_CLIENT_ID}
ARG GITHUB_CLIENT_SECRET
ENV GITHUB_CLIENT_SECRET=${GITHUB_CLIENT_SECRET}
ARG STRIPE_SECRET_KEY
ENV STRIPE_SECRET_KEY=${STRIPE_SECRET_KEY}
# ARG ADMIN_PASSWORD
# ENV ADMIN_PASSWORD=${ADMIN_PASSWORD}
# database isn't available during build
# run any other commands that do not need the database
# such as:
RUN python manage.py vendor_pull
RUN python manage.py collectstatic --noinput
#whitenoise (Use s3 if project become more robust)
# set the Django default project name
ARG PROJ_NAME="home"
# create a bash script to run the Django project
# this script will execute at runtime when
# the container starts and the database is available
RUN printf "#!/bin/bash\n" > ./paracord_runner.sh && \
printf "RUN_PORT=\"\${PORT:-8000}\"\n\n" >> ./paracord_runner.sh && \
printf "python manage.py migrate --no-input\n" >> ./paracord_runner.sh && \
printf "gunicorn ${PROJ_NAME}.wsgi:application --bind \"0.0.0.0:\$RUN_PORT\"\n" >> ./paracord_runner.sh
# make the bash script executable
RUN chmod +x paracord_runner.sh
# Clean up apt cache to reduce image size
RUN apt-get remove --purge -y \
&& apt-get autoremove -y \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Run the Django project via the runtime script
# when the container starts
CMD ./paracord_runner.sh