Skip to content

Commit

Permalink
Update docker-compose.yml for production
Browse files Browse the repository at this point in the history
  • Loading branch information
thenav56 committed Aug 27, 2020
1 parent 2e8b49a commit cd867af
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
# Share PA_BRANCH variable amount steps
echo "::set-env name=ID_BRANCH_NAME::$ID_BRANCH_NAME"
touch .env
cp docker-sample.env docker.env
- name: Docker pull
run: docker-compose pull localdb api || ID_BRANCH_NAME= docker-compose pull localdb api || true
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ source/supervisord.log
source/supervisord.pid
.vscode/settings.json
.env

docker.env
6 changes: 5 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ services:
# IMPORTANT: Remove this on production
- POSTGRES_HOST_AUTH_METHOD=trust
volumes:
- ./pgdata:/var/lib/postgresql/data
- postgres-data:/var/lib/postgresql/data
ports:
- 127.0.0.1:5433:5432

Expand Down Expand Up @@ -66,3 +66,7 @@ services:
command: sh -c './scripts/wait-for-it.sh localdb:5432 && python3 -m unittest /home/idetect/python/idetect/tests/test_*.py'
volumes:
- ./source:/home/idetect


volumes:
postgres-data:
35 changes: 17 additions & 18 deletions docker-prod.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
version: '3.4'

x-base-idetect-setup: &x-base-idetect-setup
image: docker.pkg.github.com/idmc-labs/idetect/idetect:$RELEASE
image: docker.pkg.github.com/idmc-labs/idetect/idetect:${RELEASE-release}
build:
context: .
dockerfile: ./docker/idetect/Dockerfile
cache_from:
- "docker.pkg.github.com/idmc-labs/idetect/idetect:${RELEASE}"
- docker.pkg.github.com/idmc-labs/idetect/idetect:release
- docker.pkg.github.com/idmc-labs/idetect/idetect:latest
args:
- UID=${UID}
env_file: docker.env
user: ${UID}
depends_on:
- localdb

restart: on-failure

services:

localdb:
image: docker.pkg.github.com/idmc-labs/idetect/localdb:$RELEASE
ports:
- 127.0.0.1:5433:5432
volumes:
- ./pgdata:/var/lib/postgresql/data

api:
<<: *x-base-idetect-setup
command: sh -c "./scripts/wait-for-it.sh localdb:5432 && /usr/bin/supervisord -c /idetect-configs/api-supervisord.conf"
Expand All @@ -29,13 +28,13 @@ services:
volumes:
- ./logs:/var/log

notebooks:
<<: *x-base-idetect-setup
command: jupyter notebook --no-browser --ip=0.0.0.0 --port 5002 /home/idetect/notebooks
ports:
- 5002:5002

cron:
<<: *x-base-idetect-setup
user: root
command: sh -c 'cron -f -L 7 /idetect-configs/crontab'

# notebooks:
# <<: *x-base-idetect-setup
# command: jupyter notebook --no-browser --ip=0.0.0.0 --port 5002 /home/idetect/notebooks
# ports:
# - 5002:5002
4 changes: 2 additions & 2 deletions docker.env → docker-sample.env
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# These DB connection parameters are set up in docker/postgres/docker-entrypoint-initdb.d/project.sh
DB_HOST=localdb
DB_USER=idetect
DB_PASS=democracy
DB_PASSWORD=democracy
DB_NAME=idetect
DB_PORT=5432

# Python packages in source/python are made available to python-based containers here
PYTHONPATH=/home/idetect/python

MAPZEN_KEY=thisisnotakey
MAPZEN_KEY=thisisnotakey
4 changes: 2 additions & 2 deletions docker/idetect/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM ubuntu:latest
FROM ubuntu:18.04

ENV DEBIAN_FRONTEND noninteractive

# python basics
RUN apt-get clean && \
apt-get update && \
apt-get -y install python3 python3-pip python3-dev
apt-get -y install python3.6 python3-pip python3-dev

## download the spacy model using curl for progress indication
# This is quite large, so we're downloading it early in the build for the sake of caching
Expand Down
2 changes: 1 addition & 1 deletion source/python/idetect/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def db_url():
user=os.environ.get('DB_USER'),
passwd=os.environ.get('DB_PASSWORD'),
db_host=os.environ.get('DB_HOST'),
db_port=os.environ.get('DB_PORT'),
db_port=os.environ.get('DB_PORT', 5432),
db=os.environ.get('DB_NAME'))


Expand Down
16 changes: 13 additions & 3 deletions source/scripts/update_mviews.bash
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
#!/bin/bash

echo "REFRESH MATERIALIZED VIEW idetect_fact_api_locations" | psql -h localdb -U idetect
echo "REFRESH MATERIALIZED VIEW idetect_fact_api" | psql -h localdb -U idetect
echo "REFRESH MATERIALIZED VIEW idetect_map_week_mview" | psql -h localdb -U idetect
# Environment variables required by psql
export PGUSER=${DB_USER}
export PGPASSWORD=${DB_PASSWORD}
export PGDATABASE=${DB_NAME}
export PGHOST=${DB_HOST}
export PGPORT=${DB_PORT}

set -x
psql -c "REFRESH MATERIALIZED VIEW idetect_map_mview;"
psql -c "REFRESH MATERIALIZED VIEW idetect_map_week_mview;"
psql -c "REFRESH MATERIALIZED VIEW idetect_fact_api_locations"
psql -c "REFRESH MATERIALIZED VIEW idetect_fact_api"
set +x

0 comments on commit cd867af

Please sign in to comment.