Skip to content

Commit

Permalink
Issue 1063 docker env files (#1086)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
fniessink authored Mar 7, 2020
1 parent 98bb87b commit 928b51f
Show file tree
Hide file tree
Showing 16 changed files with 170 additions and 312 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 10 additions & 0 deletions components/collector/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
8 changes: 6 additions & 2 deletions components/frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
FROM node:alpine
FROM node:13.10.1-alpine3.11

LABEL maintainer="Frank Niessink <frank.niessink@ictu.nl>"
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
44 changes: 44 additions & 0 deletions components/frontend/README-Create-React-App.md
Original file line number Diff line number Diff line change
@@ -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.<br>
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.

The page will reload if you make edits.<br>
You will also see any lint errors in the console.

### `npm test`

Launches the test runner in the interactive watch mode.<br>
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.<br>
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.<br>
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/).
47 changes: 10 additions & 37 deletions components/frontend/README.md
Original file line number Diff line number Diff line change
@@ -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.<br>
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.<br>
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.<br>
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.<br>
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.<br>
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. |
21 changes: 19 additions & 2 deletions components/server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]/<route_fragment> (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/<route_fragment> (all routes matching a specific text fragment).

## Data model

Expand Down Expand Up @@ -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 | (&#124;(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. |
12 changes: 3 additions & 9 deletions components/server/src/quality_time_server.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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__":
Expand Down
26 changes: 0 additions & 26 deletions docker/ci.env

This file was deleted.

43 changes: 0 additions & 43 deletions docker/dev.env

This file was deleted.

8 changes: 2 additions & 6 deletions docker/docker-compose.ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 8 additions & 5 deletions docker/docker-compose.override.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
36 changes: 24 additions & 12 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -44,38 +42,52 @@ 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:
- ALL
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:
Loading

0 comments on commit 928b51f

Please sign in to comment.