From 928b51f6adfcc36e7915adc2b3f6210ee3eed525 Mon Sep 17 00:00:00 2001 From: Frank Niessink Date: Sat, 7 Mar 2020 21:16:44 +0100 Subject: [PATCH] Issue 1063 docker env files (#1086) * Remove DEBUG environment variable. * Add healthcheck to frontend container. * Pin Docker image versions. * Move environment variables to docker compose. * Remove environment env files. Closes #1063. --- README.md | 2 +- components/collector/README.md | 10 ++ components/frontend/Dockerfile | 8 +- .../frontend/README-Create-React-App.md | 44 ++++++ components/frontend/README.md | 47 ++----- components/server/README.md | 21 ++- components/server/src/quality_time_server.py | 12 +- docker/ci.env | 26 ---- docker/dev.env | 43 ------ docker/docker-compose.ci.yml | 8 +- docker/docker-compose.override.yml | 13 +- docker/docker-compose.yml | 36 +++-- docker/production.env | 35 ----- docker/staging.env | 35 ----- docs/DEPLOY.md | 127 +++++------------- docs/DEVELOP.md | 15 ++- 16 files changed, 170 insertions(+), 312 deletions(-) create mode 100644 components/frontend/README-Create-React-App.md delete mode 100644 docker/ci.env delete mode 100644 docker/dev.env delete mode 100644 docker/production.env delete mode 100644 docker/staging.env diff --git a/README.md b/README.md index c30316edf7..54a540ed57 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Also see: - [Supported metrics and sources](docs/DATA_MODEL.md) - [Deployment instructions](docs/DEPLOY.md) - [Developer manual](docs/DEVELOP.md) -- [Recent changes](docs/CHANGELOG.md) +- [Change log](docs/CHANGELOG.md) ## Screenshots diff --git a/components/collector/README.md b/components/collector/README.md index a1637643da..b4a506d6b1 100644 --- a/components/collector/README.md +++ b/components/collector/README.md @@ -10,3 +10,13 @@ If a metric has been recently measured and its parameters haven't been changed, Every time the collector wakes up, it writes the current date and time in ISO format to the 'health_check.txt' file. This date and time is read by the Docker health check (see the [Dockerfile](Dockerfile)). If the written date and time are too long ago, the collector container is considered to be unhealthy. +## Configuration + +The collector uses the following environment variables: + +| Name | Default value | Description | +| :--- | :---------- | :------------ | +| SERVER_HOST | server | Hostname of the server. The collector uses this to get the metrics and post the measurements. | +| SERVER_PORT | 5001 | Port of the server. The collector uses this to get the metrics and post the measurements. | +| COLLECTOR_SLEEP_DURATION | 60 | The amount of time (in seconds) that the collector sleeps after collecting measurements. | +| COLLECTOR_MEASUREMENT_FREQUENCY | 900 | The amount of time (in seconds) after which a metric should be measured again. | diff --git a/components/frontend/Dockerfile b/components/frontend/Dockerfile index e8c1a026d9..0aa9a7b9c5 100644 --- a/components/frontend/Dockerfile +++ b/components/frontend/Dockerfile @@ -1,12 +1,16 @@ -FROM node:alpine +FROM node:13.10.1-alpine3.11 LABEL maintainer="Frank Niessink " LABEL description="Quality-time frontend" +RUN apk --no-cache add curl + WORKDIR /work ADD . /work RUN npm install RUN npm install -g serve RUN npm run build -CMD ["serve", "-s", "build"] +HEALTHCHECK CMD curl -f http://localhost:${FRONTEND_PORT:-5000}/favicon.ico || exit 1 + +CMD serve --listen ${FRONTEND_PORT:-5000} --single build diff --git a/components/frontend/README-Create-React-App.md b/components/frontend/README-Create-React-App.md new file mode 100644 index 0000000000..897dc83660 --- /dev/null +++ b/components/frontend/README-Create-React-App.md @@ -0,0 +1,44 @@ +This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). + +## Available Scripts + +In the project directory, you can run: + +### `npm start` + +Runs the app in the development mode.
+Open [http://localhost:3000](http://localhost:3000) to view it in the browser. + +The page will reload if you make edits.
+You will also see any lint errors in the console. + +### `npm test` + +Launches the test runner in the interactive watch mode.
+See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. + +### `npm run build` + +Builds the app for production to the `build` folder.
+It correctly bundles React in production mode and optimizes the build for the best performance. + +The build is minified and the filenames include the hashes.
+Your app is ready to be deployed! + +See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. + +### `npm run eject` + +**Note: this is a one-way operation. Once you `eject`, you can’t go back!** + +If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. + +Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. + +You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. + +## Learn More + +You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). + +To learn React, check out the [React documentation](https://reactjs.org/). diff --git a/components/frontend/README.md b/components/frontend/README.md index 897dc83660..0bef7567dd 100644 --- a/components/frontend/README.md +++ b/components/frontend/README.md @@ -1,44 +1,17 @@ -This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). +# Quality-time frontend -## Available Scripts +## Overview -In the project directory, you can run: +The frontend contains the React frontend code. This component was bootstrapped using [Create React App](README-Create-React-App.md). -### `npm start` +## Health check -Runs the app in the development mode.
-Open [http://localhost:3000](http://localhost:3000) to view it in the browser. +As a health check, the favicon is downloaded. -The page will reload if you make edits.
-You will also see any lint errors in the console. +## Configuration -### `npm test` +The frontend uses the following environment variables: -Launches the test runner in the interactive watch mode.
-See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. - -### `npm run build` - -Builds the app for production to the `build` folder.
-It correctly bundles React in production mode and optimizes the build for the best performance. - -The build is minified and the filenames include the hashes.
-Your app is ready to be deployed! - -See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. - -### `npm run eject` - -**Note: this is a one-way operation. Once you `eject`, you can’t go back!** - -If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. - -Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. - -You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. - -## Learn More - -You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). - -To learn React, check out the [React documentation](https://reactjs.org/). +| Name | Default value | Description | +| :--- | :---------- | :------------ | +| FRONTEND_PORT | 5000 | The port the frontend listens on. | diff --git a/components/server/README.md b/components/server/README.md index 30a09bd911..3317c08692 100644 --- a/components/server/README.md +++ b/components/server/README.md @@ -2,11 +2,11 @@ ## Example reports -The [`example-reports`](example-reports) are imported when the server is started and the database doesn't contain any sample reports yet. The server [`data` package](src/data/example-reports) contains the example reports. +The [`example-reports`](src/data/example-reports) are imported when the server is started and the database doesn't contain any sample reports yet. Turn off the loading of example report by setting `LOAD_EXAMPLE_REPORTS` to `False`. See the [section on configuration](#configuration) below. ## API -API documentation can be retrieved via http://www.quality-time.example.org/api (all versions, all routes), http://www.quality-time.example.org/api/v[1|2] (all routes for a specific version), and http://www.quality-time.example.org/api/v[1|2]/ (all routes matching a specific text fragment).j +API documentation can be retrieved via http://www.quality-time.example.org/api (all versions, all routes), http://www.quality-time.example.org/api/v2 (all routes for a specific version, in this case version 2), and http://www.quality-time.example.org/api/v2/ (all routes matching a specific text fragment). ## Data model @@ -212,3 +212,20 @@ Data models, reports, and reports overviews are [temporal objects](https://www.m ## Health check The [Dockerfile](Dockerfile) contains a health check that uses curl to retrieve an API (api/health) from the server. Officially, this API does not exist, but since the server simply returns an empty JSON file it works for checking the health of the server. + +## Configuration + +The server uses the following environment variables: + +| Name | Default value | Description | +| :--- | :---------- | :------------ | +| SERVER_PORT | 5001 | Port of the server. | +| PROXY_HOST | www | Hostname of the proxy. The server uses this to construct URLs to pass to the renderer for exporting reports to PDF. | +| PROXY_PORT | 80 | Port of the proxy. The server uses this to construct URLs to pass to the renderer for exporting reports to PDF. | +| DATABASE_URL | mongodb://root:root@database:27017 | Mongo database connection URL. | +| LDAP_URL | ldap://ldap:389 | LDAP connection URL. | +| LDAP_ROOT_DN | dc=example,dc=org | LDAP root distinguished name. | +| LDAP_LOOKUP_USER_DN | cn=admin,dc=example,dc=org | LDAP lookup user distinguished name. | +| LDAP_LOOKUP_USER_PASSWORD | admin | LDAP lookup user password. | +| LDAP_SEARCH_FILTER | (|(uid=$$username)(cn=$$username)) | LDAP search filter. With this default search filter, users can use either their LDAP canonical name (`cn`) or their LDAP user id to login. The `$username` variable is filled by *Quality-time* at run time with the username that the user enters in the login dialog box. | +| LOAD_EXAMPLE_REPORTS | True | Whether or not to import example reports in the database on start up. | diff --git a/components/server/src/quality_time_server.py b/components/server/src/quality_time_server.py index 49f51fa788..5318c13134 100644 --- a/components/server/src/quality_time_server.py +++ b/components/server/src/quality_time_server.py @@ -1,12 +1,8 @@ """Quality-time server.""" import os - -DEBUG = os.environ.get("DEBUG", "").lower() == "true" - -if not DEBUG: - from gevent import monkey # pylint: disable=import-error - monkey.patch_all() +from gevent import monkey # pylint: disable=import-error +monkey.patch_all() # pylint: disable=wrong-import-order,wrong-import-position @@ -22,9 +18,7 @@ def serve() -> None: # pragma: nocover database = init_database() init_bottle(database) server_port = os.environ.get("SERVER_PORT", "5001") - bottle.run( # nosec - server="wsgiref" if DEBUG else "gevent", host="0.0.0.0", port=server_port, reloader=not DEBUG, - log=None if DEBUG else logging.getLogger()) + bottle.run(server="gevent", host="0.0.0.0", port=server_port, reloader=True, log=logging.getLogger()) # nosec if __name__ == "__main__": diff --git a/docker/ci.env b/docker/ci.env deleted file mode 100644 index 6a474df485..0000000000 --- a/docker/ci.env +++ /dev/null @@ -1,26 +0,0 @@ -# Settings for CI-environment. - -# Global -DEBUG=False - -# Proxy -PROXY_HOST=www -PROXY_PORT=80 - -# Frontend -FRONTEND_PORT=5000 - -# Server -SERVER_PORT=5001 -SERVER_HOST=server -DATABASE_URL=mongodb://root:root@database:27017 -LDAP_URL=ldap://ldap:389 -LDAP_ROOT_DN=dc=example,dc=org -LDAP_LOOKUP_USER_DN=cn=admin,dc=example,dc=org -LDAP_LOOKUP_USER_PASSWORD=admin -LDAP_SEARCH_FILTER=(|(uid=$username)(cn=$username)) -LOAD_EXAMPLE_REPORTS=False - -# Database (Mongo) -MONGO_INITDB_ROOT_USERNAME=root -MONGO_INITDB_ROOT_PASSWORD=root diff --git a/docker/dev.env b/docker/dev.env deleted file mode 100644 index 68134441c6..0000000000 --- a/docker/dev.env +++ /dev/null @@ -1,43 +0,0 @@ -# Settings for the development configuration. - -# Global -DEBUG=False - -# Proxy -PROXY_HOST=www -PROXY_PORT=80 - -# Collector -COLLECTOR_SLEEP_DURATION=10 -COLLECTOR_MEASUREMENT_FREQUENCY=60 - -# Frontend -FRONTEND_PORT=5000 - -# Server -SERVER_PORT=5001 -SERVER_HOST=server -DATABASE_URL=mongodb://root:root@database:27017 -LDAP_URL=ldap://ldap:389 -LDAP_ROOT_DN=dc=example,dc=org -LDAP_LOOKUP_USER_DN=cn=admin,dc=example,dc=org -LDAP_LOOKUP_USER_PASSWORD=admin -LDAP_SEARCH_FILTER=(|(uid=$username)(cn=$username)) -LOAD_EXAMPLE_REPORTS=True - -# Database (Mongo) -MONGO_INITDB_ROOT_USERNAME=root -MONGO_INITDB_ROOT_PASSWORD=root - -# Mongo-Express -ME_CONFIG_MONGODB_ADMINUSERNAME=root -ME_CONFIG_MONGODB_ADMINPASSWORD=root -ME_CONFIG_MONGODB_SERVER=database - -# PHPLDAPAdmin -PHPLDAPADMIN_LDAP_HOSTS=ldap -PHPLDAPADMIN_HTTPS=false - -# Renderer -ALLOW_HTTP=true -LC_ALL=en_GB.UTF-8 diff --git a/docker/docker-compose.ci.yml b/docker/docker-compose.ci.yml index 1b1df9aa79..248437fad6 100644 --- a/docker/docker-compose.ci.yml +++ b/docker/docker-compose.ci.yml @@ -5,16 +5,12 @@ version: "3" services: frontend: build: ../components/frontend - env_file: - - ${ENV:-ci}.env collector: build: ../components/collector - env_file: - - ${ENV:-ci}.env server: build: ../components/server - env_file: - - ${ENV:-ci}.env + environment: + - LOAD_EXAMPLE_REPORTS=False depends_on: - ldap ldap: diff --git a/docker/docker-compose.override.yml b/docker/docker-compose.override.yml index aed6e2c571..9e186a276d 100644 --- a/docker/docker-compose.override.yml +++ b/docker/docker-compose.override.yml @@ -24,8 +24,10 @@ services: image: mongo-express ports: - "8081:8081" - env_file: - - ${ENV:-dev}.env + environment: + - ME_CONFIG_MONGODB_ADMINUSERNAME=root + - ME_CONFIG_MONGODB_ADMINPASSWORD=root + - ME_CONFIG_MONGODB_SERVER=database depends_on: - database ldap: @@ -34,9 +36,10 @@ services: - "389:389" - "636:636" phpldapadmin: - image: osixia/phpldapadmin:latest - env_file: - - ${ENV:-dev}.env + image: osixia/phpldapadmin:0.9.0 + environment: + - PHPLDAPADMIN_LDAP_HOSTS=ldap + - PHPLDAPADMIN_HTTPS=false ports: - "3890:80" depends_on: diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index e1f4c2d6ac..4c8ac38d81 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -4,8 +4,6 @@ version: '3' services: www: image: ictu/caddy:1.0.3-no-stats - env_file: - - ${ENV:-dev}.env ports: - "${PROXY_PORT:-80}:${PROXY_PORT:-80}" environment: @@ -44,24 +42,36 @@ services: - frontend frontend: image: ictu/quality-time_frontend:v2.0.0-rc.2 - env_file: - - ${ENV:-dev}.env + environment: + - FRONTEND_PORT=5000 depends_on: - server cap_drop: - ALL collector: image: ictu/quality-time_collector:v2.0.0-rc.2 - env_file: - - ${ENV:-dev}.env + environment: + - SERVER_PORT=5001 + - SERVER_HOST=server + - COLLECTOR_SLEEP_DURATION=60 + - COLLECTOR_MEASUREMENT_FREQUENCY=900 depends_on: - server cap_drop: - ALL server: image: ictu/quality-time_server:v2.0.0-rc.2 - env_file: - - ${ENV:-dev}.env + environment: + - SERVER_PORT=5001 + - PROXY_HOST=www + - PROXY_PORT=80 + - DATABASE_URL=mongodb://root:root@database:27017 + - LDAP_URL=ldap://ldap:389 + - LDAP_ROOT_DN=dc=example,dc=org + - LDAP_LOOKUP_USER_DN=cn=admin,dc=example,dc=org + - LDAP_LOOKUP_USER_PASSWORD=admin + - LDAP_SEARCH_FILTER=(|(uid=$$username)(cn=$$username)) + - LOAD_EXAMPLE_REPORTS=True depends_on: - database cap_drop: @@ -69,13 +79,15 @@ services: database: image: mongo:4.2.3 restart: always - env_file: - - ${ENV:-dev}.env + environment: + - MONGO_INITDB_ROOT_USERNAME=root + - MONGO_INITDB_ROOT_PASSWORD=root volumes: - "dbdata:/data/db" renderer: image: ictu/url-to-pdf-api:v1.0.0 - env_file: - - ${ENV:-dev}.env + environment: + - ALLOW_HTTP=true + - LC_ALL=en_GB.UTF-8 volumes: dbdata: diff --git a/docker/production.env b/docker/production.env deleted file mode 100644 index 6fbe22749b..0000000000 --- a/docker/production.env +++ /dev/null @@ -1,35 +0,0 @@ -# Example settings for a production configuration. Adapt to your needs. - -# Global -DEBUG=False - -# Proxy -PROXY_HOST=www -PROXY_PORT=80 - -# Frontend -FRONTEND_PORT=5000 - -# Server -SERVER_PORT=5001 -SERVER_HOST=server -DATABASE_URL=mongodb://root:root@database:27017 -LDAP_URL=ldap://ldap:389 -LDAP_ROOT_DN=dc=example,dc=org -LDAP_LOOKUP_USER_DN=cn=admin,dc=example,dc=org -LDAP_LOOKUP_USER_PASSWORD=secret -LDAP_SEARCH_FILTER=(|(uid=$username)(cn=$username)) -LOAD_EXAMPLE_REPORTS=False - -# Database (Mongo) -MONGO_INITDB_ROOT_USERNAME=root -MONGO_INITDB_ROOT_PASSWORD=root - -# Mongo-Express -ME_CONFIG_MONGODB_ADMINUSERNAME=root -ME_CONFIG_MONGODB_ADMINPASSWORD=root -ME_CONFIG_MONGODB_SERVER=database - -# PHPLDAPAdmin -PHPLDAPADMIN_LDAP_HOSTS=ldap -PHPLDAPADMIN_HTTPS=false diff --git a/docker/staging.env b/docker/staging.env deleted file mode 100644 index 041f3cdedc..0000000000 --- a/docker/staging.env +++ /dev/null @@ -1,35 +0,0 @@ -# Example settings for a staging configuration. Adapt to your needs. - -# Global -DEBUG=False - -# Proxy -PROXY_HOST=www -PROXY_PORT=80 - -# Frontend -FRONTEND_PORT=5000 - -# Server -SERVER_PORT=5001 -SERVER_HOST=server -DATABASE_URL=mongodb://root:root@database:27017 -LDAP_URL=ldap://ldap:389 -LDAP_ROOT_DN=dc=example,dc=org -LDAP_LOOKUP_USER_DN=cn=admin,dc=example,dc=org -LDAP_LOOKUP_USER_PASSWORD=secret -LDAP_SEARCH_FILTER=(|(uid=$username)(cn=$username)) -LOAD_EXAMPLE_REPORTS=False - -# Database (Mongo) -MONGO_INITDB_ROOT_USERNAME=root -MONGO_INITDB_ROOT_PASSWORD=root - -# Mongo-Express -ME_CONFIG_MONGODB_ADMINUSERNAME=root -ME_CONFIG_MONGODB_ADMINPASSWORD=root -ME_CONFIG_MONGODB_SERVER=database - -# PHPLDAPAdmin -PHPLDAPADMIN_LDAP_HOSTS=ldap -PHPLDAPADMIN_HTTPS=false diff --git a/docs/DEPLOY.md b/docs/DEPLOY.md index 25b54caeac..e037c9d6d5 100644 --- a/docs/DEPLOY.md +++ b/docs/DEPLOY.md @@ -2,45 +2,22 @@ Quality-time consists of containers that together form the application: a proxy that routes incoming traffic to either the frontend container to serve the React frontend and static resources or the server container that serves the REST API. The database container runs a Mongo database server and the collector container collects the measurement data for the metrics. -## Docker-compositions +## Docker-composition -This document assumes docker-compose is used to deploy the containers. The docker folder of this repo contains different compose files for running Quality-time in development, continuous integration, staging, and production environments, see the [docker folder](../docker). +This document assumes docker-compose is used to deploy the containers. The docker folder of this repo contains different compose files for running Quality-time in development and continuous integration mode, see the [docker folder](../docker). You can use these compose files as basis for your own deployment configuration. ## Configuring LDAP -To configure an LDAP server to authenticate users with, set the `LDAP_URL`, `LDAP_ROOT_DN`, `LDAP_LOOKUP_USER_DN`, `LDAP_LOOKUP_USER_PASSWORD`, and `LDAP_SEARCH_FILTER` environment variables. When running locally, this can be done in the shell: - - - -```console -$ export LDAP_URL="ldap://ldap.example.org:389" -$ export LDAP_ROOT_DN="dc=example,dc=org" -$ export LDAP_LOOKUP_USER_DN="cn=lookup_user,dc=example,dc=org" -$ export LDAP_LOOKUP_USER_PASSWORD="secret" -$ export LDAP_SEARCH_FILTER='(|(uid=$username)(cn=$username))' # Single quotes to prevent the shell from expanding the username variable -$ cd components/server -$ python src/quality_report_server.py -INFO:root:Connected to database: Database(MongoClient(host=['localhost:27017'], document_class=dict, tz_aware=False, connect=True), 'quality_time_db') -INFO:root:Measurements collection has 108 measurements -INFO:root:Initializing LDAP server at ldap://ldap.example.org:389 -... -``` +To configure an LDAP server to authenticate users with, set the `LDAP_URL`, `LDAP_ROOT_DN`, `LDAP_LOOKUP_USER_DN`, `LDAP_LOOKUP_USER_PASSWORD`, and `LDAP_SEARCH_FILTER` environment variables. Add the LDAP environment variables to the server service in the [compose file](../docker/docker-compose.yml): -When using docker-compose, add the LDAP environment variables to the relevant env file in the [docker folder](../docker): - -```bash -... -# Server -SERVER_PORT=5001 -SERVER_HOST=server -DATABASE_URL=mongodb://root:root@database:27017 -LDAP_URL=ldap://ldap.example.org:389 -LDAP_ROOT_DN=dc=example,dc=org -LDAP_LOOKUP_USER_DN=cn=admin,dc=example,dc=org -LDAP_LOOKUP_USER_PASSWORD=admin -LDAP_SEARCH_FILTER=(|(uid=$username)(cn=$username)) -LOAD_EXAMPLE_REPORTS=True -... +```yaml + server: + environment: + - LDAP_URL=ldap://ldap:389 + - LDAP_ROOT_DN=dc=example,dc=org + - LDAP_LOOKUP_USER_DN=cn=admin,dc=example,dc=org + - LDAP_LOOKUP_USER_PASSWORD=admin + - LDAP_SEARCH_FILTER=(|(uid=$username)(cn=$username)) ``` When using the `LDAP_SEARCH_FILTER` as shown above, users can use either their LDAP canonical name (`cn`) or their LDAP user id to login. The `$username` variable is filled by *Quality-time* at run time with the username that the user enters in the login dialog box. @@ -51,79 +28,43 @@ See [https://ldap.com/ldap-filters/](https://ldap.com/ldap-filters/) for more in ### Proxy -External traffic is routed by a Caddy reverse proxy (container name: proxy) to either the frontend container or the server container. The proxy listens on port 80. There's currently no environment variable to change the proxy port, but you can override the Caddy configurion in the `docker-compose.yml` if so desired. +External traffic is routed by a Caddy reverse proxy (container name: www) to either the frontend container or the server container. The proxy listens on port 80. You can override the Caddy configuration in the [compose file](../docker/docker-compose.yml) if so desired. ### Frontend -The React UI is served by the frontend container, which runs at port 5000 by default. The Caddy reverse proxy routes external traffic that's not meant for the API to the frontend container. - -To configure the frontend container port, set the `FRONTEND_PORT` environment variable. When running locally, this can be done in the shell: - -```console -$ export FRONTEND_PORT=6000 -$ cd components/frontend -$ npm start -> quality-time-app@1.5.0 start /Users/fniessink/workspace/quality-time/components/frontend -> react-scripts start -... -``` - -When using docker-compose add the `FRONTEND_PORT` environment variable to the relevant env file in the docker folder: +The React UI is served by the frontend container, which runs at port 5000 by default. The Caddy reverse proxy routes external traffic that is not meant for the API to the frontend container. To configure the frontend container port, set the `FRONTEND_PORT` environment variable. Add the `FRONTEND_PORT` environment variable to both the proxy (www) and the frontend service: -```bash -... -# Frontend -FRONTEND_PORT=6000 -... +```yaml + www: + environment: + - FRONTEND_PORT=6000 + frontend: + environment: + - FRONTEND_PORT=6000 ``` ### Server -The API is accessible at the server container, running at port 5001 by default. The Caddy reverse proxy routes URLs that start with /api to the server. - -To configure the server container port, set the `SERVER_PORT` environment variable. When running locally, this can be done in the shell: +The API is accessible at the server container, running at port 5001 by default. The Caddy reverse proxy routes URLs that start with /api to the server. To configure the server container port, set the `SERVER_PORT` environment variable. Add the `SERVER_PORT` environment variable to both the server and the collector service: -```console -$ export SERVER_PORT=6001 -$ cd components/server -$ python src/quality_time_server.py -INFO:root:Connected to database: Database(MongoClient(host=['localhost:27017'], document_class=dict, tz_aware=False, connect=True), 'quality_time_db') -INFO:root:Database has 101 report documents and 467 measurement documents -INFO:root:Skipping loading the data model; it is unchanged -INFO:root:Skipping initializing reports overview; it already exists -... -``` - -When using docker-compose add the `SERVER_PORT` environment variable to the relevant env file in the docker folder: - -```bash -... -# Server -SERVER_PORT=6001 -... +```yaml + server: + environment: + - SERVER_PORT=6001 + collector: + environment: + - SERVER_PORT=6001 ``` ### Collector The collector contacts the server to see whether there's metrics that need to be measured and uses the server API to store the new measurements in the database. By default, the collector measures metrics whose configuration hasn't been changed every 15 minutes and sleeps 60 seconds in between measurements. -To configure the sleep duration and the measurement frequency, set the `COLLECTOR_SLEEP_DURATION` and `COLLECTOR_MEASUREMENT_FREQUENCY` environment variables. Both variables have seconds as unit. When running locally, this can be done in the shell: - -```console -$ export COLLECTOR_SLEEP_DURATION=10 -$ export COLLECTOR_MEASUREMENT_FREQUENCY=60 -$ cd components/collector -$ python src/quality_report_collector.py -INFO:root:Loading data model... -INFO:root:Collecting... -``` - -When using docker-compose add the `COLLECTOR_SLEEP_DURATION` and `COLLECTOR_MEASUREMENT_FREQUENCY` environment variable to the relevant env file in the docker folder: +To configure the sleep duration and the measurement frequency, set the `COLLECTOR_SLEEP_DURATION` and `COLLECTOR_MEASUREMENT_FREQUENCY` environment variables. Both variables have seconds as unit. Add the `COLLECTOR_SLEEP_DURATION` and `COLLECTOR_MEASUREMENT_FREQUENCY` environment variables to collector service: -```bash -... -# Collector -COLLECTOR_SLEEP_DURATION=10 -COLLECTOR_MEASUREMENT_FREQUENCY=60 -... +```yaml + collector: + environment: + - COLLECTOR_SLEEP_DURATION=30 + - COLLECTOR_MEASUREMENT_FREQUENCY=600 ``` diff --git a/docs/DEVELOP.md b/docs/DEVELOP.md index b32e15376f..83c6ec4e3f 100644 --- a/docs/DEVELOP.md +++ b/docs/DEVELOP.md @@ -93,15 +93,18 @@ See [Release README](../ci/README.md). ![Components](components.png) -Quality-time consists of six components: +Quality-time consists of six components. Three standard components: + +- A proxy (we use the [ICTU variant of Caddy](https://github.com/ICTU/caddy), but this can be replaced by another proxy if so desired) routing traffic from and to the user's browser, +- A database ([Mongo](https://www.mongodb.com)) for storing reports and measurements, +- A renderer (we use the [ICTU variant of url-to-pdf-api](https://github.com/ICTU/url-to-pdf-api) to export reports to PDF, + +And three bespoke components: -- A proxy (Caddy, but can be replaced by another proxy if so desired) routing traffic from and to the user's browser, - A [frontend](../components/frontend/README.md) serving the React UI, -- A renderer to export reports to PDF, - A [server](../components/server/README.md) serving the API, -- A database (Mongo) for storing reports and measurements, - A [collector](../components/collector/README.md) to collect the measurements from the sources. -In addition, a LDAP server is expected to be available to authenticate users. +In addition, an LDAP server is expected to be available to authenticate users. -For testing purposes there is also [test data](../components/testdata/README.md) +For testing purposes there are also [test data](../components/testdata/README.md) and an [LDAP-server](../components/ldap/README.md).