Skip to content

Commit

Permalink
Have kpi service wait for db services to be ready before setting up. …
Browse files Browse the repository at this point in the history
…Handle migrations appropriately within docker container. Have kpi server accessible on the browser for testing
  • Loading branch information
WinnyTroy committed May 5, 2021
1 parent e98f611 commit 312b2ad
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM nikolaik/python-nodejs:python3.8-nodejs10
ARG additional_pip_packages=pyjwt

ENV DEBIAN_FRONTEND=noninteractive
ENV LANG=en_US.UTF-8
Expand Down Expand Up @@ -73,9 +74,10 @@ COPY . "${KPI_SRC_DIR}"
RUN virtualenv "$VIRTUAL_ENV"
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
RUN pip install --quiet --upgrade pip && \
pip install --quiet pip-tools && pip install jwt
pip install --quiet pip-tools
COPY ./dependencies/pip/external_services.txt /srv/tmp/pip_dependencies.txt
RUN pip-sync /srv/tmp/pip_dependencies.txt 1>/dev/null && \
pip install ${additional_pip_packages} && \
rm -rf ~/.cache/pip

###########################
Expand Down
12 changes: 8 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ services:
volumes:
# One level above the code to prevent having to move or delete
# it everytime we rebuild.
- /var/lib/postgresql/data
- ../.kpi_db:/var/lib/postgresql/data
onadata_db:
image: postgis/postgis:9.6-3.0
environment:
Expand All @@ -20,7 +20,7 @@ services:
volumes:
# One level above the code to prevent having to move or delete
# it everytime we rebuild.
- /var/lib/postgresql/data
- ../.onadata_db:/var/lib/postgresql/data
web:
build:
context: .
Expand All @@ -32,6 +32,10 @@ services:
- kpi_db
- onadata_db
environment:
- DATABASE_URL=postgres://db:5432/kpi
- DATABASE_URL=postgres://kpi_db:5432/kpi
- DJANGO_SETTINGS_MODULE=kobo.settings.local_settings
- KPI_SRC_DIR=/srv/src/kpi
- KPI_LOGS_DIR=/srv/logs
- KPI_PREFIX=kpi
volumes:
- .:/srv/src/kpi
- .:/srv/src/kpi
15 changes: 13 additions & 2 deletions docker/init.bash
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ set -e

source /etc/profile

# Have web service wait until db services are ready to accept connections
sleep 1

echo 'KoBoForm initializing...'

cd "${KPI_SRC_DIR}"
Expand All @@ -15,10 +18,13 @@ fi


# Wait for databases to be up & running before going further
# /bin/bash "${INIT_PATH}/wait_for_mongo.bash"
# /bin/bash "${INIT_PATH}/wait_for_postgres.bash"
/bin/bash "${INIT_PATH}/wait_for_mongo.bash"
/bin/bash "${INIT_PATH}/wait_for_postgres.bash"


echo 'Running migrations...'
python manage.py makemigrations --merge --noinput
python manage.py makemigrations --noinput
python manage.py migrate --noinput

echo 'Creating superuser...'
Expand Down Expand Up @@ -65,4 +71,9 @@ rm -rf /tmp/celery*.pid

echo 'KoBoForm initialization completed.'

# Have kpi service accessible on the browser
source /opt/venv/bin/activate
cd /srv/src/kpi
python manage.py runserver 0.0.0.0:8000

exec /usr/bin/runsvdir /etc/service

0 comments on commit 312b2ad

Please sign in to comment.