Skip to content

Commit 7023b46

Browse files
Arthur-IMEaugustoericorooterico
authored
Update docker
* Bump app version (#28) * build: bump app version --------- Co-authored-by: root <root@nes-dev.ime.usp.br> Co-authored-by: erico <erico@numec.prp.usp.br> * build: update first stage for NES * chore: remove wsgi from entrypoint * build: add second stage to build * chore: update WSGI to default * chore: remove wsgi.py from .gitignore * build: add missing dep * build: conditionally run migrations and db-related ops * build: add docker-compose.yml * chore: remove deprecated property from docker-compose.yml * build: add docker files * build: fix compose * build: simplify Dockerfile to single stage * build: create super user on entrypoint --------- Co-authored-by: Erico Silva <augusto.ericosilva@gmail.com> Co-authored-by: root <root@nes-dev.ime.usp.br> Co-authored-by: erico <erico@numec.prp.usp.br>
1 parent a4a2c99 commit 7023b46

6 files changed

Lines changed: 87 additions & 126 deletions

File tree

docker/compose/nes/Dockerfile

Lines changed: 40 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,44 @@
1-
FROM python:3.8-alpine3.12 as wheeler
1+
# sudo docker build -t nes:test -f docker/compose/nes/Dockerfile .
2+
# sudo docker run --rm -it nes:test /bin/bash
3+
FROM python:3.8-slim
24
ENV PYTHONUNBUFFERED=1
35

4-
RUN apk update && \
5-
apk add --no-cache \
6-
libpng-dev \
7-
freetype-dev \
8-
build-base \
9-
git \
10-
postgresql-dev \
11-
openblas-dev \
12-
libjpeg-turbo-dev \
13-
hdf5-dev && \
14-
rm -rf /var/cache/apk/* && \
15-
ln -s /usr/include/locale.h /usr/include/xlocale.h
16-
17-
ARG NES_TAG=unset
18-
ARG NES_BRANCH=unset
19-
ARG NES_DIR=/nes
20-
ENV NES_DIR=$NES_DIR
21-
22-
RUN mkdir -p "$NES_DIR" && \
23-
if [ "$NES_TAG" != "unset" ]; then \
24-
echo Cloning tag "$NES_TAG" ;\
25-
wget https://github.com/neuromat/nes/archive/TAG-"${NES_TAG}".tar.gz -qO - | \
26-
tar xzv --strip-components=1 -C "$NES_DIR" ;\
27-
sed -i 's/\(psycopg2==\)[0-9.]\+/\12.7.5/' /nes/patientregistrationsystem/qdc/requirements.txt ;\
28-
sed -i '1isetuptools>=40.6.3' /nes/patientregistrationsystem/qdc/requirements.txt ;\
29-
sed -i '1ipip>=18.1' /nes/patientregistrationsystem/qdc/requirements.txt ;\
30-
echo 'mne>=0.17.0' >> /nes/patientregistrationsystem/qdc/requirements.txt ;\
31-
echo '-e "git+https://github.com/AllenInstitute/nwb-api.git#egg=nwb&subdirectory=ainwb"' >> /nes/patientregistrationsystem/qdc/requirements.txt ;\
32-
elif [ "$NES_BRANCH" != "unset" ]; then \
33-
echo Cloning "$NES_BRANCH" branch ;\
34-
git clone -j $(nproc) -b "$NES_BRANCH" https://github.com/neuromat/nes.git "$NES_DIR" ;\
35-
else \
36-
echo Cloning master branch ;\
37-
git clone -j $(nproc) https://github.com/neuromat/nes.git "$NES_DIR" ;\
38-
fi
39-
40-
RUN mkdir -p /wheels/requirement && \
41-
cp "$NES_DIR"/patientregistrationsystem/qdc/requirements.txt /wheels/requirement
42-
43-
WORKDIR /wheels
44-
45-
RUN pip3 install -U pip setuptools wheel && \
46-
pip3 install -r requirement/requirements.txt && \
47-
pip3 wheel -r requirement/requirements.txt
48-
49-
FROM alpine:3.12
50-
516
SHELL ["/bin/sh","-exc"]
527

53-
RUN apk update && \
54-
apk add --no-cache \
55-
git \
56-
libpq \
57-
openblas-dev \
58-
libjpeg-turbo-dev \
59-
python3 \
60-
py3-pip \
61-
graphviz \
62-
hdf5-dev && \
63-
rm -rf /var/cache/apk/*
64-
65-
ARG NES_DIR=/nes
66-
ENV NES_DIR=$NES_DIR
67-
68-
COPY --from=wheeler /wheels /wheels
69-
70-
COPY --from=wheeler $NES_DIR $NES_DIR
71-
72-
RUN pip3 install -U pip setuptools wheel && \
73-
pip3 install -r /wheels/requirement/requirements.txt -f /wheels && \
74-
rm -rf /wheels && \
75-
rm -rf /root/.cache/pip*
76-
77-
VOLUME $NES_DIR
78-
79-
COPY ./entrypoint.sh /
80-
81-
ENV NES_IP ${NES_IP:-0.0.0.0}
82-
ENV NES_PORT ${NES_PORT:-8000}
83-
84-
ENTRYPOINT [ "/entrypoint.sh" ]
85-
86-
CMD [ "/bin/sh", "-c", "/usr/bin/python3 -u ${NES_DIR}/patientregistrationsystem/qdc/manage.py runserver -v3 $NES_IP:$NES_PORT" ]
8+
# System deps (build + runtime together)
9+
RUN apt-get update && \
10+
apt-get install -y --no-install-recommends \
11+
git \
12+
build-essential \
13+
python3-distutils \
14+
libpq-dev \
15+
libpq5 \
16+
libopenblas-dev \
17+
libjpeg62-turbo-dev \
18+
libpng-dev \
19+
libfreetype6-dev \
20+
graphviz \
21+
libhdf5-dev && \
22+
rm -rf /var/lib/apt/lists/*
23+
24+
# App location
25+
ENV NES_DIR=/nes
26+
WORKDIR $NES_DIR
27+
28+
RUN git config --global --add safe.directory /nes
29+
30+
# App source
31+
COPY . .
32+
33+
# Python deps
34+
RUN pip install --no-cache-dir \
35+
-r patientregistrationsystem/qdc/requirements.txt
36+
37+
# Runtime config
38+
ENV NES_IP=0.0.0.0
39+
ENV NES_PORT=8000
40+
41+
COPY docker/compose/nes/entrypoint.sh /
42+
ENTRYPOINT ["/entrypoint.sh"]
43+
44+
# CMD ["/bin/sh", "-c", "python -u patientregistrationsystem/qdc/manage.py runserver -v3 $NES_IP:$NES_PORT"]
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# sudo docker compose -f docker/compose/nes/docker-compose.yml up
2+
services:
3+
db:
4+
image: postgres:15
5+
environment:
6+
POSTGRES_DB: nes_db
7+
POSTGRES_USER: nes_user
8+
POSTGRES_PASSWORD: nes_password
9+
volumes:
10+
- pgdata:/var/lib/postgresql/data
11+
12+
web:
13+
build:
14+
context: ../../..
15+
dockerfile: docker/compose/nes/Dockerfile
16+
command: python manage.py runserver 0.0.0.0:8000
17+
ports:
18+
- "8000:8000"
19+
environment:
20+
NES_DB_HOST: db
21+
NES_DB: nes_db
22+
NES_DB_USER: nes_user
23+
NES_DB_PASSWORD: nes_password
24+
depends_on:
25+
- db
26+
27+
volumes:
28+
pgdata:

docker/compose/nes/entrypoint.sh

Lines changed: 15 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ NES_DB_PORT=${NES_DB_PORT:-'5432'}
1313
NES_DB_PASSWORD=${NES_DB_PASSWORD:-'nes_password'}
1414

1515
# External LimeSurvey settings
16-
LIMESURVEY_HOST=${LIMESURVEY_HOST:-'localhost'}
17-
LIMESURVEY_PORT=${LIMESURVEY_PORT:-'8080'}
16+
LIMESURVEY_API_URL=${LIMESURVEY_API_URL:-'http://localhost:8080'}
17+
LIMESURVEY_WEB_URL=${LIMESURVEY_WEB_URL:-'http://localhost:8080'}
1818
LIMESURVEY_ADMIN_USER=${LIMESURVEY_ADMIN_USER:-'limesurvey_admin'}
1919
LIMESURVEY_ADMIN_PASSWORD=${LIMESURVEY_ADMIN_PASSWORD:-'limesurvey_admin_password'}
2020

@@ -36,26 +36,6 @@ then
3636
exit 1
3737
fi
3838

39-
if [ -f "${NES_SETUP_PATH}"/wsgi.py ]
40-
then
41-
echo "INFO: NES wsgi.py file already provisioned"
42-
else
43-
echo "INFO: Creating NES wsgi.py file"
44-
cat <<-EOF > "${NES_SETUP_PATH}"/wsgi.py
45-
import os
46-
import sys
47-
import site
48-
paths = ["$NES_PROJECT_PATH", "$NES_DIR", "/usr/local", "/usr/bin", "/bin",]
49-
for path in paths:
50-
if path not in sys.path:
51-
sys.path.append(path)
52-
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "qdc.settings")
53-
from django.core.wsgi import get_wsgi_application
54-
application = get_wsgi_application()
55-
EOF
56-
chown -R nobody "${NES_SETUP_PATH}"/wsgi.py
57-
fi
58-
5939
if [ -f "${NES_SETUP_PATH}"/settings_local.py ]
6040
then
6141
echo "INFO: NES settings_local.py file already provisioned"
@@ -79,8 +59,8 @@ else
7959
}
8060
}
8161
LIMESURVEY = {
82-
"URL_API": "http://$LIMESURVEY_HOST:$LIMESURVEY_PORT",
83-
"URL_WEB": "http://$LIMESURVEY_HOST:$LIMESURVEY_PORT",
62+
"URL_API": "$LIMESURVEY_API_URL",
63+
"URL_WEB": "$LIMESURVEY_WEB_URL",
8464
"USER": "$LIMESURVEY_ADMIN_USER",
8565
"PASSWORD": "$LIMESURVEY_ADMIN_PASSWORD"
8666
}
@@ -89,15 +69,12 @@ else
8969
chown -R nobody "${NES_SETUP_PATH}"/settings_local.py
9070
fi
9171

92-
while ! nc -z "$NES_DB_HOST" "$NES_DB_PORT"
93-
do
94-
sleep 0.2
95-
done
72+
# while ! nc -z "$NES_DB_HOST" "$NES_DB_PORT"
73+
# do
74+
# sleep 0.2
75+
# done
9676

97-
if [ -f "${NES_DIR}"/.nes_initialization.placeholder ]
98-
then
99-
echo "INFO: NES data has already been initialized"
100-
else
77+
if [ ! -f "${NES_DIR}"/.nes_initialized.placeholder ]; then
10178
echo "INFO: Initializing NES data (migrations, initial, superuser, ICD)"
10279
cd "$NES_PROJECT_PATH"
10380

@@ -108,20 +85,18 @@ else
10885
EOF
10986

11087
python3 -u manage.py migrate
111-
# Different versions may have different commands
11288
python3 -u manage.py shell < add_initial_data.py || true
11389
python3 -u manage.py loaddata load_initial_data.json || true
114-
python3 -u manage.py shell < /tmp/create_superuser.py || true
115-
python3 -u manage.py import_icd_cid --file icd10cid10v2017.csv || true
11690
python3 -u manage.py createcachetable || true
91+
python3 -u manage.py shell < /tmp/create_superuser.py
11792

11893
rm /tmp/create_superuser.py
11994

120-
# If NES was installed from a release it won't have a .git directory
121-
chown -R nobody "${NES_DIR}"/.git || true
122-
chown -R nobody "${NES_DIR}"/patientregistrationsystem
123-
124-
touch "${NES_DIR}"/.nes_initialization.placeholder
95+
touch "${NES_DIR}"/.nes_initialized.placeholder
12596
fi
12697

98+
# If NES was installed from a release it won't have a .git directory
99+
chown -R nobody "${NES_DIR}"/.git || true
100+
chown -R nobody "${NES_DIR}"/patientregistrationsystem
101+
127102
exec "$@"

patientregistrationsystem/qdc/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ media
44
.idea
55
qdc/settings_local.py
66
*.DS_Store
7-
qdc/wsgi.py
87
db.sqlite3
98
__pycache__/
109
geckodriver.log

patientregistrationsystem/qdc/qdc/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,4 +211,4 @@
211211
except ImportError:
212212
pass
213213

214-
VERSION = '1.72.7'
214+
VERSION = '1.73.0'

patientregistrationsystem/qdc/qdc/wsgi_default.py renamed to patientregistrationsystem/qdc/qdc/wsgi.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/
66
"""
77
import os
8-
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "qdc.settings")
98
from django.core.wsgi import get_wsgi_application
10-
application = get_wsgi_application()
9+
10+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "qdc.settings")
11+
application = get_wsgi_application()

0 commit comments

Comments
 (0)