Skip to content

Commit

Permalink
fix: use inbuilt docker compose AB#23107
Browse files Browse the repository at this point in the history
  • Loading branch information
jannisvisser committed Aug 25, 2023
1 parent db46f14 commit 6c96e28
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 65 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ From root run
### Using Docker

```
docker-compose -f docker-compose.yml up -d # for production
docker compose -f docker-compose.yml up -d # for production
docker-compose up -d # for development (NOTE: this does not start the ibf-dashboard)
docker compose up -d # for development (NOTE: this does not start the ibf-dashboard)
docker-compose -f docker-compose.yml -f docker-compose.override.yml up -d # for development (same as previous line)
docker compose -f docker-compose.yml -f docker-compose.override.yml up -d # for development (same as previous line)
```

Expand All @@ -89,7 +89,7 @@ For IBF-dashboard

Suggestion: load everything through Docker, except IBF-dashboard. This has the benefit that changes in front-end code are immediately reflected, instead of having to rebuild.

- `docker-compose up -d`
- `docker compose up -d`
- `cd interfaces/IBF-dashboard`
- `npm start`

Expand All @@ -100,7 +100,7 @@ are connected to a database-server). For setting up a fully working version of t

1. Seed database with initial static data

- `docker-compose exec ibf-api-service npm run seed`
- `docker compose exec ibf-api-service npm run seed`

2. Load initial raster data

Expand Down
11 changes: 0 additions & 11 deletions docker-compose.override.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ services:
command: ['npm', 'run', 'start:dev']
environment:
- NODE_ENV=development
volumes:
- 'api_service_node_modules:/home/ibf/api-service/node_modules'
- ./services/API-service:/home/ibf/api-service
ports:
- 3000:3000
depends_on:
Expand All @@ -22,14 +19,6 @@ services:
ibf-geoserver:
ports:
- 8081:8080
volumes:
- ./services/API-service/geoserver-volume/raster-files:/opt/geoserver/data_dir/workspaces/ibf-system/ibf-pipeline
- ./services/API-service/geoserver-volume/geoserver-layers:/opt/geoserver/data_dir/workspaces/ibf-system

nginx:
volumes:
- ./nginx/conf.d:/etc/nginx/user.conf.d
- ./nginx/letsencrypt:/etc/letsencrypt

ibf-local-db:
image: postgis/postgis
Expand Down
32 changes: 6 additions & 26 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3.8'

services:
nginx:
image: staticfloat/nginx-certbot
Expand All @@ -13,7 +11,7 @@ services:
volumes:
- ./nginx/conf.d:/etc/nginx/user.conf.d
- ibf-dashboard-root:/var/www/ibf-dashboard
- letsencrypt:/etc/letsencrypt
- ./nginx/letsencrypt:/etc/letsencrypt
networks:
web-server-network:
restart: unless-stopped
Expand Down Expand Up @@ -49,7 +47,8 @@ services:
- TWILIO_WHATSAPP_NUMBER=${TWILIO_WHATSAPP_NUMBER}
- NG_API_URL=${NG_API_URL}
volumes:
- api-root:/home/ibf/api-service
- 'api_service_node_modules:/home/ibf/api-service/node_modules'
- ./services/API-service:/home/ibf/api-service
networks:
web-server-network:
api-network:
Expand Down Expand Up @@ -94,8 +93,8 @@ services:
- GEOSERVER_ADMIN_PASSWORD=${GEOSERVER_ADMIN_PASSWORD}
- JAVA_OPTS="-DALLOW_ENV_PARAMETRIZATION=true"
volumes:
- api-geoserver-files:/opt/geoserver/data_dir/workspaces/ibf-system/ibf-pipeline
- api-geoserver-workspace:/opt/geoserver/data_dir/workspaces/ibf-system
- ./services/API-service/geoserver-volume/raster-files:/opt/geoserver/data_dir/workspaces/ibf-system/ibf-pipeline
- ./services/API-service/geoserver-volume/geoserver-layers:/opt/geoserver/data_dir/workspaces/ibf-system
- ./.env:/opt/geoserver/data_dir/geoserver-environment.properties
networks:
web-server-network:
Expand All @@ -104,26 +103,7 @@ services:

volumes:
ibf-dashboard-root:
api-root:
driver_opts:
type: bind
device: ./services/API-service
o: bind
api-geoserver-files:
driver_opts:
type: bind
device: ./services/API-service/geoserver-volume/raster-files
o: bind
api-geoserver-workspace:
driver_opts:
type: bind
device: ./services/API-service/geoserver-volume/geoserver-layers
o: bind
letsencrypt:
driver_opts:
type: bind
device: ./nginx/letsencrypt
o: bind
api_service_node_modules:

networks:
web-server-network:
Expand Down
30 changes: 15 additions & 15 deletions docs/TROUBLESHOOT.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ Sometimes there is an issue with installing all packages for ibf-api-service. Yo
- exit (switch to normal user)
- cd /home/ibf-user/IBF-system/services/API-service
- npm install
- docker-compose restart ibf-api-service
- docker compose restart ibf-api-service

### 502 Bad Gateway on API-calls/Swagger UI

Sometimes for unknown reasons the API & Swagger are unavailable, while 'docker-compose logs ibf-api-service' tells you that the API is running correctly.
Sometimes for unknown reasons the API & Swagger are unavailable, while 'docker compose logs ibf-api-service' tells you that the API is running correctly.

- On the server run 'docker-compose restart nginx' in this case
- On the server run 'docker compose restart nginx' in this case
- which will usually solve it.

### Access to files on server
Expand All @@ -50,7 +50,7 @@ To check if everything starts up correctly:

- All containers mentioned in the docker-compose file /IBF-system/docker-compose.yml should be up and running. Check e.g. via `docker container ls`
- Application should load and respond properly on http://localhost:4200
- Check the logs of `ibf-api-service` via `docker-compose logs -f ibf-api-service`. Is it saying that the Nest application started successfully?
- Check the logs of `ibf-api-service` via `docker compose logs -f ibf-api-service`. Is it saying that the Nest application started successfully?
- Can you visit the Swagger UI API documentation on http://localhost:3000/docs and try one of the GET endpoints?

### Problem with existing database
Expand All @@ -59,14 +59,14 @@ If there is a problem with your existing database schema, you can always try to

- Access the database via e.g. DBeaver
- Alternatively, access it via commandline using
- `docker-compose exec ibf-local-db bash`
- `docker compose exec ibf-local-db bash`
- `psql -U <chosen local-db-username>`
- Throw away schema via `drop schema "IBF-app" cascade;`
- Recreate schema: `create schema "IBF-app";`
- Exit the database again
- Restart the ibf-api-service: `docker-compose restart ibf-api-service` or `docker-compose up -d ibf-api-service`
- Restart the ibf-api-service: `docker compose restart ibf-api-service` or `docker compose up -d ibf-api-service`
- This will automatically run migration-scripts upon restart, which involves an "initial migration script" which creates all necessary tables.
- Wait until done. Check via `docker-compose logs -f ibf-api-service`
- Wait until done. Check via `docker compose logs -f ibf-api-service`
- As always (see main [README](../README.md))
- Run the seed-script
- Run mock-endpoint (or external pipeline)
Expand All @@ -76,30 +76,30 @@ If there is a problem with your existing database schema, you can always try to
These below commands come in handy when you face such issue:

- The Docker compose command starts and runs your entire app:
docker-compose up
docker compose up

- For dev environment we can use:
docker-compose -f docker-compose.yml -f docker-compose.override.yml up
docker compose -f docker-compose.yml -f docker-compose.override.yml up

- Execute this will create a container named ibf-api-service and start a Bash session:
docker-compose exec ibf-api-service bash
docker compose exec ibf-api-service bash

- To run seed script:
docker-compose exec ibf-api-service npm run seed
docker compose exec ibf-api-service npm run seed

- Detached mode (-d) run command in the background:
docker-compose up -d ibf-api-service:
docker compose up -d ibf-api-service:

- Create the Docker image from the Dockerfile in this folder through:
docker build -t ibf-api-service

- To check the logs of IBF-api-service:
docker-compose logs -f ibf-api-service
docker compose logs -f ibf-api-service

- To restart the IBF-api-service in docker:
docker-compose restart ibf-api-service
docker compose restart ibf-api-service

- To install the IBF-api-services:
docker-compose exec ibf-api-service npm install
docker compose exec ibf-api-service npm install

You can refer this official docker document [here](https://docs.docker.com/engine/reference/commandline/compose_exec/)
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.258.0",
"private": true,
"scripts": {
"start:services": "docker-compose up -d",
"start:services": "docker compose up -d",
"start:interface": "npm start --prefix interfaces/IBF-dashboard/ -- --port 4200",
"install:interface": "npm install --no-optional --no-audit --no-fund --prefix interfaces/IBF-dashboard/",
"open": "npx npm-run-all open:ibf-api-service open:ibf-dashboard",
Expand Down Expand Up @@ -33,4 +33,4 @@
"puppeteer": "^8.0.0"
},
"pre-commit": "lint"
}
}
4 changes: 2 additions & 2 deletions services/API-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Developers use the following process for this.
1. The attribute 'synchronize' in ormconfig.js is set to 'false' by default. This means that any changes in your entities in code are not automatically reflected in the datamodel.
2. Otherwise TypeORM's migration:generate functionality cannot be used to automatically capture the difference between before (datamodel) and after (entities) state.
3. A developer develops + tests until running into a datamodel change. If that happens
- Generate a migration through `docker-compose exec ibf-api-service npm run migration:generate <MigrationName>`
- Generate a migration through `docker compose exec ibf-api-service npm run migration:generate <MigrationName>`
- Immediately run the migration (by restarting ibf-api-service, as migration:run is run upon 'prestart')
- Test the feature
- Continue developing and repeat this process as many times as needed
Expand Down Expand Up @@ -125,7 +125,7 @@ Use [ngrok](https://ngrok.com/) to mock an external API service:
- In the `WhatsApp sandbox settings` (go to right subaccount > Develop > Messaging > Settings > Whatsapp sandbox settings) as:
- `<EXTERNAL_API_SERVICE_URL>/api/notifications/whatsapp/incoming` in the `WHEN A MESSAGE COMES IN` field
- `<EXTERNAL_API_SERVICE_URL>/api/notifications/whatsapp/status` in the `STATUS CALLBACK URL` field
7. Rebuild the service with `docker-compose -d up ibf-api-service`
7. Rebuild the service with `docker compose -d up ibf-api-service`
8. Add your WhatsApp phone number to the WhatsApp sandbox by texting the code provided in the subaccount to the sandbox phone number
9. Create a new IBF-user through API with your WhatsApp phone number and assigned to the country you are testing for
10. Send a notification (for a country/disasterType with an active trigger) via the `/api/notification/send` endpoint.
Expand Down
8 changes: 4 additions & 4 deletions tools/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ function deploy() {
log "Update containers..."

cd "$repo" || return
docker-compose down -v
docker-compose --env-file /dev/null config > inspect.docker-compose.config
docker-compose --env-file /dev/null -f docker-compose.yml up -d --build
docker-compose --env-file /dev/null restart
docker compose down -v
docker compose --env-file /dev/null config > inspect.docker-compose.config
docker compose --env-file /dev/null -f docker-compose.yml up -d --build
docker compose --env-file /dev/null restart
# wait 2 minutes for services to go live
sleep 2m
}
Expand Down

0 comments on commit 6c96e28

Please sign in to comment.