- Getting Started
- Run dengue-backend OUTSIDE Docker Container
- Run dengue-backend INSIDE Docker Container
- License
brew install PostgreSQL
brew install postgis
brew install gdal
brew install libgeoip
brew install redis
sudo apt-get install libtiff5-dev libjpeg8-dev zlib1g-dev libfreetype6-dev liblcms2-dev libwebp-dev tcl8.6-dev tk8.6-dev python-tk
- Install Backend Packages
pipenv install
- Setup environment variables
export DENGUE_SECRET_KEY="some hard to guess value"
export DENGUE_DB_NAME="database name for postgis"
export DENGUE_DB_USER="user name for postgis"
export DENGUE_DB_PASSWORD="user password for postgis"
export DENGUE_DB_HOST="host for postgis"
export DENGUE_DB_PORT="port for postgis"
export DENGUE_CACHE_LOCATION="redis uri"
export AWS_ACCESS_KEY="AWS access key"
export AWS_SECRET_KEY="AWS secret key"
export GOOGLE_MAP_API_KEY="Google Map API key"
- Create user
$ createuser -P -e dengue_user
Enter password for new role: dengue
Enter it again: dengue
CREATE ROLE dengue_user PASSWORD ...
- Create database
createdb dengue_db
- Start Postgres server
pg_ctl -D /usr/local/var/postgres start
- Create postgis extension
$ psql
postgres=# GRANT ALL PRIVILEGES ON DATABASE dengue_db TO dengue_user;
postgres=# \c dengue_db;
dengue_db=# CREATE EXTENSION postgis;
CREATE EXTENSION
- Initial Database
- Different can be configed in
dengue/dengue/settings
- Different can be configed in
pipenv run python dengue/manage.py migrate --settings=dengue.settings.<ENV>
- Create Superuser
- Different can be configed in
dengue/dengue/settings
- Different can be configed in
$ pipenv run python dengue/manage.py createsuperuser --settings=dengue.settings.<ENV>
Username: admin
Email address: admin@example.com
Password: some-secret
Password: (again): some-secret
Superuser created successfully.
- Initialize Data
- Different can be configed in
dengue/dengue/settings
- Different can be configed in
# Insert Substitute
pipenv run python dengue/manage.py init_taiwan_data --settings=dengue.settings.<ENV>
# Insert Hospitial
pipenv run python dengue/manage.py init_hospital_data --settings=dengue.settings.<ENV>
- Start
redis-server
cd dengue/static/
npm install
npm run typings install
npx tsc
- Start a local server
- Different can be configed in
dengue/dengue/settings
- Different can be configed in
pipenv run python dengue/manage.py runserver --settings=dengue.settings.<ENV>
- Start production server
cd dengue/
sudo uwsgi --ini dengue.ini
- Stop production server
sudo killall -s INT uwsgi
- Setup environement variables by creating
env.cfg
at the root directory (Useenv-template.cfg
as the template forenv.cfg
)- Note that the following key pairs should have the same value
POSTGRES_DBNAME
,DENGUE_DB_NAME
DENGUE_DB_USER
,POSTGRES_USER
DENGUE_DB_PASSWORD
,POSTGRES_PASS
INIT_DB
should be true andGOOGLE_MAP_API_KEY
should be proper API key only when the database is first created and used to initial data- The hostname and other nginx configuration can be configured in.
docker/nginx
.
- Note that the following key pairs should have the same value
docker-compose build
docker-compose up -d
It's possible that the "web" container runs before "postgis" contain is ready and thus cannot migrate database in time.
If this happens, you will get a 502 response when you enter http://127.0.0.1.
In such case, you should manually migrate the database.
Use docker ps
command to find the container ID of "dengue-backend_web" and execute the following command to migrate the database.
docker exec -it <CONTAINER ID> python3 dengue/manage.py migrate --settings=dengue.settings.production
docker exec -it <CONTAINER ID> python3 dengue/manage.py createsuperuser --settings=dengue.settings.production
Note that this command will clean up all the data.
docker-compose down -v --rmi local
Copyright (c) NCKU The Mosquito Man Project. All rights reserved.
Licensed under the MIT License.