-
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Dockerfile and init.sh for the api
- Loading branch information
1 parent
f11d7ec
commit d5b4678
Showing
25 changed files
with
225 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,59 @@ | ||
FROM python:3.11.6-slim-bookworm | ||
|
||
ARG ENVIRONMENT | ||
ENV PYTHONUNBUFFERED=1 | ||
|
||
ENV RUN_MIGRATION=yes | ||
ENV RUN_COMPILE_MESSAGES=no | ||
ENV RUN_COLLECT_STATIC=no | ||
ENV RUN_CREATE_SUPER_USER=yes | ||
|
||
ENV IS_CONTAINERIZED=True | ||
|
||
ENV DEBIAN_FRONTEND=noninteractive | ||
|
||
ENV ENVIRONMENT ${ENVIRONMENT:-production} | ||
ENV DJANGO_SETTINGS_MODULE seismic_site.settings.${ENVIRONMENT} | ||
ENV DOCKERIZE_VERSION v0.6.1 | ||
|
||
RUN apt-get update && \ | ||
apt-get upgrade -y && \ | ||
apt-get install -y --no-install-recommends \ | ||
build-essential \ | ||
postgresql-client \ | ||
libpq-dev \ | ||
gettext \ | ||
wget | ||
nginx gcc xz-utils gettext build-essential postgresql-client libpq-dev | ||
|
||
|
||
ARG S6_OVERLAY_VERSION=3.1.2.1 | ||
ENV S6_CMD_WAIT_FOR_SERVICES_MAXTIME 0 | ||
|
||
ADD https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-noarch.tar.xz /tmp | ||
ADD https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-x86_64.tar.xz /tmp | ||
RUN tar -C / -Jxpf /tmp/s6-overlay-noarch.tar.xz && \ | ||
tar -C / -Jxpf /tmp/s6-overlay-x86_64.tar.xz | ||
|
||
|
||
ENTRYPOINT ["/init"] | ||
|
||
COPY docker/nginx/nginx.conf /etc/nginx/sites-available/default | ||
COPY docker/s6-rc.d /etc/s6-overlay/s6-rc.d | ||
|
||
|
||
# Python virtualenv paths | ||
ENV VIRTUAL_ENV=/opt/venv | ||
RUN python3 -m venv $VIRTUAL_ENV | ||
ENV PATH="$VIRTUAL_ENV/bin:$PATH" | ||
|
||
|
||
# install the backend libraries: | ||
COPY ./api/setup.cfg ./api/requirements.txt ./api/requirements-dev.txt /var/www/seismic/api/ | ||
WORKDIR /var/www/seismic/api/ | ||
RUN python3 -m pip install --upgrade pip setuptools && \ | ||
python3 -m pip install -r ./requirements.txt | ||
|
||
|
||
# install dockerize and update pip | ||
RUN wget https://github.com/jwilder/dockerize/releases/download/${DOCKERIZE_VERSION}/dockerize-linux-amd64-${DOCKERIZE_VERSION}.tar.gz && \ | ||
tar -C /usr/local/bin -xzvf dockerize-linux-amd64-${DOCKERIZE_VERSION}.tar.gz && \ | ||
rm dockerize-linux-amd64-${DOCKERIZE_VERSION}.tar.gz && \ | ||
chown root:root /usr/local/bin/dockerize && \ | ||
pip install "pip==23.*" -U | ||
# copy the backend source code: | ||
COPY ./api/ /var/www/seismic/api/ | ||
|
||
# install and cache app dependencies | ||
WORKDIR /opt/ | ||
|
||
COPY ./requirements*.txt ./ | ||
RUN if [ "${ENVIRONMENT}" = "production" ]; then pip install -r requirements.txt; else pip install -r requirements-dev.txt; fi | ||
# Make sure scripts in .local are usable: | ||
ENV PATH=/root/.local/bin:$PATH | ||
|
||
WORKDIR /code/ | ||
|
||
COPY ./docker-entrypoint / | ||
COPY ./ /code/ | ||
WORKDIR /var/www/seismic/ | ||
|
||
ENTRYPOINT ["/docker-entrypoint"] | ||
EXPOSE 8030 | ||
EXPOSE 80 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
FROM python:3.11.6-slim-bookworm | ||
|
||
ARG ENVIRONMENT | ||
|
||
ENV ENVIRONMENT ${ENVIRONMENT:-production} | ||
ENV DJANGO_SETTINGS_MODULE seismic_site.settings.${ENVIRONMENT} | ||
ENV DOCKERIZE_VERSION v0.6.1 | ||
|
||
RUN apt-get update && \ | ||
apt-get install -y --no-install-recommends \ | ||
build-essential \ | ||
postgresql-client \ | ||
libpq-dev \ | ||
gettext \ | ||
wget | ||
|
||
# install dockerize and update pip | ||
RUN wget https://github.com/jwilder/dockerize/releases/download/${DOCKERIZE_VERSION}/dockerize-linux-amd64-${DOCKERIZE_VERSION}.tar.gz && \ | ||
tar -C /usr/local/bin -xzvf dockerize-linux-amd64-${DOCKERIZE_VERSION}.tar.gz && \ | ||
rm dockerize-linux-amd64-${DOCKERIZE_VERSION}.tar.gz && \ | ||
chown root:root /usr/local/bin/dockerize && \ | ||
pip install "pip==23.*" -U | ||
|
||
# install and cache app dependencies | ||
WORKDIR /opt/ | ||
|
||
COPY ./requirements*.txt ./ | ||
RUN if [ "${ENVIRONMENT}" = "production" ]; then pip install -r requirements.txt; else pip install -r requirements-dev.txt; fi | ||
|
||
WORKDIR /code/ | ||
|
||
COPY ./docker-entrypoint / | ||
COPY ./ /code/ | ||
|
||
ENTRYPOINT ["/docker-entrypoint"] | ||
EXPOSE 8030 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# base image | ||
FROM node:18-alpine | ||
FROM node:18.18-bookworm-slim | ||
|
||
ARG ENVIRONMENT | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
server { | ||
listen [::]:80 default_server; | ||
listen 80 default_server; | ||
server_name _; | ||
|
||
client_max_body_size 200M; | ||
|
||
location / { | ||
# proxy_set_header X-Forwarded-Proto https; | ||
proxy_set_header X-Url-Scheme $scheme; | ||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
proxy_set_header Host $http_host; | ||
proxy_redirect off; | ||
proxy_pass http://unix:/run/gunicorn.sock; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
init |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/command/with-contenv sh | ||
cd /var/www/seismic/api/ | ||
|
||
# https://docs.gunicorn.org/en/latest/design.html#how-many-workers | ||
WORKERS=$(((2 * $(nproc)) + 1)) | ||
|
||
python3 -m gunicorn seismic_site.wsgi \ | ||
--bind "unix:///run/gunicorn.sock" \ | ||
--log-level info \ | ||
--worker-class gevent \ | ||
--workers $WORKERS \ | ||
--timeout 60 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
longrun |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/command/with-contenv bash | ||
|
||
cd "${BACKEND_ROOT:-/var/www/seismic/api}" || exit 1 | ||
|
||
echo "Checking..." | ||
python3 manage.py check | ||
|
||
if [ "${RUN_MIGRATION^^}" = "TRUE" ]; then | ||
echo "Migrating database" | ||
python3 manage.py migrate --run-syncdb | ||
python3 manage.py createcachetable | ||
fi | ||
|
||
if [ "${RUN_COMPILE_MESSAGES^^}" = "TRUE" ]; then | ||
echo "Compiling translation messages" | ||
python3 manage.py compilemessages | ||
fi | ||
|
||
if [ "${RUN_COLLECT_STATIC^^}" = "TRUE" ]; then | ||
echo "Collect static" | ||
mkdir static | ||
python3 manage.py collectstatic --noinput | ||
fi | ||
|
||
if [ "${RUN_CREATE_SUPER_USER^^}" = "TRUE" ]; then | ||
echo "Check superuser presence" | ||
SUPERUSERS=$(python3 manage.py shell -c "from django.contrib.auth import get_user_model; User = get_user_model(); print(User.objects.filter(username=\"${DJANGO_ADMIN_EMAIL}\").count())") | ||
|
||
if [ "${SUPERUSERS}" = "0" ]; then | ||
echo "Create first superuser" | ||
python3 manage.py createsuperuser --noinput --username "${DJANGO_ADMIN_EMAIL}" | ||
|
||
echo "Set superuser password" | ||
python3 manage.py shell -c "from django.contrib.auth import get_user_model; User = get_user_model(); u = User.objects.get(username=\"${DJANGO_ADMIN_EMAIL}\"); u.set_password(\"${DJANGO_ADMIN_PASSWORD}\"); u.save()" | ||
else | ||
echo "A superuser already exists" | ||
fi | ||
fi | ||
|
||
if [ "${RUN_LOAD_DUMMY_DATA^^}" = "TRUE" ] ; then | ||
echo "Load dummy data into the database" | ||
./manage.py loaddata proximal_utilities | ||
./manage.py loaddata work_performed | ||
fi | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
oneshot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/etc/s6-overlay/s6-rc.d/init/init.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/sh -e | ||
nginx -g "daemon off;" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
longrun |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
init |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/command/with-contenv sh | ||
cd /var/www/seismic/api/ | ||
|
||
python3 manage.py qcluster |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
longrun |
Empty file.
Empty file.
Empty file.
Empty file.