Skip to content

Commit

Permalink
add postgres db for staging and production
Browse files Browse the repository at this point in the history
  • Loading branch information
David Wilby committed Oct 6, 2021
1 parent 3336304 commit c74e058
Show file tree
Hide file tree
Showing 6 changed files with 231 additions and 35 deletions.
16 changes: 15 additions & 1 deletion annotation_tool/settings/production.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<<<<<<< HEAD
import logging
import sys
=======
import os
>>>>>>> add postgres db for staging and production
from .base import *

# Enable csrf in production
Expand Down Expand Up @@ -33,4 +37,14 @@
'propagate': True,
},
},
}
}
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': os.environ.get("DJANGO_DB_NAME", "annotations_db"),
"USER": os.environ.get("DB_USERNAME", "user"),
"PASSWORD": os.environ.get("DB_PASSWORD", "password"),
"HOST": os.environ.get("DB_HOST", "db"),
"PORT": os.environ.get("DB_PORT", "5432"),
}
}
13 changes: 12 additions & 1 deletion annotation_tool/settings/staging.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from .base import *

# Enable csrf in production
Expand Down Expand Up @@ -30,4 +31,14 @@
'propagate': True,
},
},
}
}
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': os.environ.get("DJANGO_DB_NAME", "annotations_db"),
"USER": os.environ.get("DB_USERNAME", "user"),
"PASSWORD": os.environ.get("DB_PASSWORD", "password"),
"HOST": os.environ.get("DB_HOST", "db"),
"PORT": os.environ.get("DB_PORT", "5432"),
}
}
10 changes: 10 additions & 0 deletions create-django-db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh

psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<EOSQL
CREATE USER $DJANGO_DB_USER WITH PASSWORD '$DJANGO_DB_PASSWORD';
CREATE DATABASE $DJANGO_DB_NAME;
GRANT ALL PRIVILEGES ON DATABASE $DJANGO_DB_NAME TO $DJANGO_DB_USER;
CREATE USER $DB_BACKUP_USER WITH PASSWORD '$DB_BACKUP_PASSWORD';
GRANT CONNECT ON DATABASE $DJANGO_DB_NAME TO $DB_BACKUP_USER;
GRANT USAGE ON SCHEMA public TO $DB_BACKUP_USER;
EOSQL
7 changes: 7 additions & 0 deletions db-migrate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh
#
# Run Django migrations against the postgresql container to create the initial
# schema or migrate after an upgrade
#

docker-compose run --rm --entrypoint "python" backend manage.py migrate
45 changes: 22 additions & 23 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ services:
- DJANGO_DB_NAME
- DB_USERNAME
- DB_PASSWORD
# depends_on:
# - db
depends_on:
- db
volumes:
- ./db.sqlite3:/app/db.sqlite3
- logs/:/logs/
networks:
- django-nginx
Expand All @@ -31,33 +30,33 @@ services:
- 80:80
depends_on:
- backend
# - db
- db
networks:
- django-nginx


# db:
# image: postgres:12-alpine
# restart: always
# expose:
# - "5432"
# env_file:
# - ./.env
# environment:
# - POSTGRES_USER=postgres
# - POSTGRES_PASSWORD=${PG_SUPERUSER_PASSWORD}
# - DJANGO_DB_NAME
# - DJANGO_DB_USER=${DB_USERNAME}
# - DJANGO_DB_PASSWORD=${DB_PASSWORD}
# - DB_BACKUP_USER
# - DB_BACKUP_PASSWORD
# volumes:
# - postgresql-data:/var/lib/postgresql/data
# - ./create-django-db.sh:/docker-entrypoint-initdb.d/001-create-django-db.sh
db:
image: postgres:12-alpine
restart: always
expose:
- "5432"
env_file:
- ./.env
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=${PG_SUPERUSER_PASSWORD}
- DJANGO_DB_NAME
- DJANGO_DB_USER=${DB_USERNAME}
- DJANGO_DB_PASSWORD=${DB_PASSWORD}
- DB_BACKUP_USER
- DB_BACKUP_PASSWORD
volumes:
- postgresql-data:/var/lib/postgresql/data
- ./create-django-db.sh:/docker-entrypoint-initdb.d/001-create-django-db.sh

volumes:
logs:
# postgresql-data:
postgresql-data:

networks:
django-nginx:
Expand Down
175 changes: 165 additions & 10 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
name: annotation-tool
channels:
- conda-forge
- https://repo.anaconda.com/pkgs/free
- anaconda
- https://repo.anaconda.com/pkgs/free
- conda-forge
- defaults
dependencies:
- _libgcc_mutex=0.1=main
- brotlipy=0.7.0=py39h27cfd23_1003
- ca-certificates=2021.4.13=h06a4308_1
- ca-certificates=2021.7.5=h06a4308_1
- cairo=1.14.8=0
- certifi=2020.12.5=py39h06a4308_0
- certifi=2021.5.30=py39h06a4308_0
- cffi=1.14.5=py39h261ae71_0
- chardet=4.0.0=py39h06a4308_1003
- conda=4.10.1=py39hf3d152e_0
Expand All @@ -22,6 +22,7 @@ dependencies:
- freetype=2.5.5=2
- glib=2.50.2=1
- graphviz=2.38.0=5
- gunicorn=20.1.0=py39h06a4308_0
- harfbuzz=0.9.39=2
- icu=68.1=h58526e2_0
- idna=2.10=pyhd3eb1b0_0
Expand All @@ -42,12 +43,13 @@ dependencies:
- ncurses=6.2=he6710b0_1
- networkx=2.5.1=pyhd3eb1b0_0
- nodejs=12.19.0=hfa01f41_2
- openssl=1.1.1k=h27cfd23_0
- openssl=1.1.1l=h7f8727e_0
- pango=1.40.3=1
- pcre=8.39=1
- pip=21.0.1=py39h06a4308_0
- pixman=0.34.0=hceecf20_3
- postgresql=12.2=h20c2e04_0
- psycopg2=2.8.6=py39h3c74f83_1
- pycosat=0.6.3=py39h27cfd23_0
- pycparser=2.20=py_2
- pyopenssl=20.0.1=pyhd3eb1b0_1
Expand All @@ -69,25 +71,178 @@ dependencies:
- yaml=0.2.5=h7b6447c_0
- zlib=1.2.11=h7b6447c_3
- pip:
- aiohttp==3.7.4.post0
- aiohttp-cors==0.7.0
- alabaster==0.7.12
- anyio==3.0.1
- apipkg==1.5
- appdirs==1.4.4
- argon2-cffi==20.1.0
- asgiref==3.3.2
- astroid==2.4.1
- async-generator==1.10
- async-timeout==3.0.1
- attrs==20.3.0
- babel==2.9.1
- backcall==0.2.0
- bandit==1.7.0
- beautifulsoup4==4.9.3
- black==21.5b1
- bleach==3.3.0
- blis==0.7.4
- catalogue==2.0.4
- click==7.1.2
- conllu==4.4
- coverage==5.5
- cymem==2.0.5
- defusedxml==0.7.1
- distlib==0.3.1
- django==3.2
- django-extensions==3.1.3
- django-webpack-loader==0.7.0
- djangorestframework==3.12.4
- docutils==0.16
- dodgy==0.2.1
- entrypoints==0.3
- execnet==1.8.0
- filelock==3.0.12
- flake8==3.8.4
- flake8-polyfill==1.0.2
- frosted==1.4.1
- gatenlp==1.0.4
- gitdb==4.0.7
- gitpython==3.1.17
- imagesize==1.2.0
- iniconfig==1.1.1
- install==1.3.4
- ipykernel==5.5.5
- ipython==7.23.1
- ipython-genutils==0.2.0
- ipywidgets==7.6.3
- isort==4.3.21
- jedi==0.18.0
- jinja2==3.0.0
- joblib==1.0.1
- json5==0.9.5
- jsonschema==3.2.0
- jupyter-client==6.1.12
- jupyter-core==4.7.1
- jupyter-server==1.7.0
- jupyterlab==3.0.15
- jupyterlab-pygments==0.1.2
- jupyterlab-server==2.5.1
- jupyterlab-widgets==1.0.0
- lazy-object-proxy==1.4.3
- mako==1.1.4
- markdown==3.3.4
- markupsafe==2.0.0
- matchtext==0.2.3
- matplotlib-inline==0.1.2
- mccabe==0.6.1
- mistune==0.8.4
- msgpack==1.0.2
- multidict==5.1.0
- murmurhash==1.0.5
- mypy==0.812
- mypy-extensions==0.4.3
- nbclassic==0.2.8
- nbclient==0.5.3
- nbconvert==6.0.7
- nbformat==5.1.3
- nest-asyncio==1.5.1
- nltk==3.6.2
- notebook==6.3.0
- numpy==1.20.3
- packaging==20.9
- pandocfilters==1.4.3
- parso==0.8.2
- pathspec==0.8.1
- pathy==0.5.2
- pbr==5.6.0
- pdoc3==0.9.2
- pep8==1.7.1
- pep8-naming==0.10.0
- pexpect==4.8.0
- pickleshare==0.7.5
- pies==2.6.7
- pluggy==0.13.1
- preshed==3.0.5
- prometheus-client==0.10.1
- prompt-toolkit==3.0.18
- prospector==1.3.1
- protobuf==3.17.0
- ptyprocess==0.7.0
- py==1.10.0
- py4j==0.10.9.2
- pycodestyle==2.6.0
- pydantic==1.7.4
- pydocstyle==6.0.0
- pydot==1.4.2
- pyflakes==2.2.0
- pygments==2.9.0
- pygraphviz==1.7
- pylint==2.5.3
- pylint-celery==0.3
- pylint-django==2.1.0
- pylint-flask==0.6
- pylint-plugin-utils==0.6
- pyparsing==2.4.7
- pyroma==3.1
- pyrsistent==0.17.3
- pytest==6.2.3
- pytest-cache==1.0
- pytest-cov==2.12.0
- pytest-django==4.2.0
- pytest-pep8==1.0.6
- pytest-runner==5.3.0
- pytest-tornasync==0.6.0.post2
- python-dateutil==2.8.1
- pytz==2021.1
- pyyaml==5.4.1
- pyzmq==22.0.3
- recordclass==0.14.3
- regex==2021.4.4
- requirements-detector==0.7
- rise==5.7.1
- send2trash==1.5.0
- setoptconf==0.2.0
- smart-open==3.0.0
- smmap==4.0.0
- sniffio==1.2.0
- snowballstemmer==2.1.0
- sortedcontainers==2.3.0
- soupsieve==2.2.1
- spacy==3.0.6
- spacy-legacy==3.0.5
- sphinx==3.5.4
- sphinxcontrib-applehelp==1.0.2
- sphinxcontrib-devhelp==1.0.2
- sphinxcontrib-htmlhelp==1.0.3
- sphinxcontrib-jsmath==1.0.1
- sphinxcontrib-qthelp==1.0.3
- sphinxcontrib-serializinghtml==1.1.4
- sqlparse==0.4.1
- srsly==2.4.1
- stanza==1.2
- stevedore==3.3.0
- terminado==0.9.5
- testpath==0.4.4
- thinc==8.0.3
- toml==0.10.2
- gatenlp
- pyyaml
- msgpack
- bs4
prefix: /home/twin/miniconda3/envs/annotation-tool
- torch==1.8.1
- tornado==6.1
- tox==3.23.1
- traitlets==5.0.5
- typed-ast==1.4.3
- typer==0.3.2
- typing-extensions==3.10.0.0
- virtualenv==20.4.6
- voila==0.2.10
- vulture==2.3
- wasabi==0.8.2
- wcwidth==0.2.5
- webencodings==0.5.1
- websocket-client==0.59.0
- widgetsnbextension==3.5.1
- wrapt==1.12.1
- yarl==1.6.3

0 comments on commit c74e058

Please sign in to comment.