From 81537482c741e11a9fa335dc4643ea1eb1475493 Mon Sep 17 00:00:00 2001 From: Arthur Kelsch Date: Mon, 6 Jul 2020 13:25:36 +0200 Subject: [PATCH] Add db init to docker-compose --- README.md | 38 +++++++++++++++++++++++++------------- docker-compose.prod.yml | 10 ++++++++++ docker-compose.yml | 6 +----- lib/database.js | 5 +++-- 4 files changed, 39 insertions(+), 20 deletions(-) create mode 100644 docker-compose.prod.yml diff --git a/README.md b/README.md index d84d8bc..00d6f12 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,21 @@ -# dashboard-prototyp +# corona-dashboard + +Project as part of the web applications module at htw saar. It contains a backend application built with Express serving COVID-19 case data provided by RKI. + +## Endpoints + +See [Postman collection](etc/Corona%20Backend.postman_collection.json). ## Getting Started +### TLDR + +1. `git clone` +2. `npm install` +3. `docker-compose up -d` +4. `npm run init` +5. `npm start` + ### npm #### `npm install` @@ -28,24 +42,22 @@ Running the following command will start a PostgreSQL database including PostGIS docker-compose up -d ``` -To run and build the application with Docker uncomment the `app` part in [`docker-compose.yml`](docker-compose.yml) and run: +If you want to dockerize the application itself as well, add [`docker-compose.prod.yml`](docker-compose.prod.yml) to your list of compose files: ```sh -docker-compose up -d --build +docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d --build ``` #### pgAdmin -1. Go to http://localhost:8000/ -2. Login using admin/nimda +1. Open http://localhost:8000/ +2. Login + - Username: admin + - Password: nimda 3. Create a new server - 1. Host: postgres - 2. Port: 5432 - 3. Username: postgres - 4. Password: postgres + - Host: postgres + - Port: 5432 + - Username: postgres + - Password: mysecretpassword Note that the server configuration is persistent and will survive restarts. - -## Endpoints - -See [Postman collection](etc/Corona%20Backend.postman_collection.json). diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml new file mode 100644 index 0000000..9fdcc09 --- /dev/null +++ b/docker-compose.prod.yml @@ -0,0 +1,10 @@ +version: '3.4' + +services: + app: + build: . + command: sh -c "npm run init && npm start" + ports: + - 3000:3000 + environment: + PG_HOST: postgres diff --git a/docker-compose.yml b/docker-compose.yml index b2e988e..5d815c2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,16 +1,12 @@ version: '3.4' services: - # app: - # build: . - # ports: - # - 3000:3000 postgres: image: postgis/postgis ports: - 5432:5432 environment: - POSTGRES_PASSWORD: postgres + POSTGRES_PASSWORD: mysecretpassword volumes: - pgdata:/var/lib/postgresql/data pgadmin: diff --git a/lib/database.js b/lib/database.js index 67c7711..d63be51 100644 --- a/lib/database.js +++ b/lib/database.js @@ -5,10 +5,11 @@ const { Sequelize } = sequelize const DATABASE = 'postgres' const USERNAME = 'postgres' -const PASSWORD = 'postgres' +const PASSWORD = 'mysecretpassword' +const HOST = process.env.PG_HOST || 'localhost' const connection = new Sequelize(DATABASE, USERNAME, PASSWORD, { - host: 'localhost', + host: HOST, dialect: 'postgres' })