|
1 |
| -<!-- |
2 |
| -
|
3 |
| -Then set up a Service Account Key file: |
4 |
| -1. Open [Google Cloud Service Accounts](https://console.cloud.google.com/iam-admin/serviceaccounts) |
5 |
| -2. Create a new Service Account Key file: |
6 |
| - * set name (e.g. *dev-mapswipe-workers*) |
7 |
| - * add roles, (e.g. `Storage Admin` and `Firebase Admin`) or use pre-defined role instead (e.g. `Custom Firebase Developer`) |
8 |
| -3. Download Key as file: |
9 |
| - * select `.json` and save |
10 |
| -
|
| 1 | +# Configuration Reference |
11 | 2 |
|
| 3 | +Most of the configuration is stored in environment variables. |
| 4 | +At the root of the GitHub repository an example file (`example.env`) with all possible configuration variables exists. To get started copy this file to `.env` and fill in missing variables. Once done source this file to make variables accessible as environment variables: `source .env` to either be used by docker-compose during deployment setup or by MapSwipe Workers directly. |
12 | 5 |
|
| 6 | +In following chapters configuration values and keys are discussed for each part of the MapSwipe Back-end. |
13 | 7 |
|
14 | 8 |
|
15 |
| -## Firebase |
| 9 | +## MapSwipe Workers |
16 | 10 |
|
17 |
| -Firebase is a central part of MapSwipe. In our setup we use *Firebase Database*, *Firebase Database Rules* and *Firebase Functions*. In the documentation we will refer to two elements: |
18 |
| -1. `your_project_id`: This is the name of your Firebase project (e.g. *dev-mapswipe*) |
19 |
| -2. `your_database_name`: This is the name of your Firebase database. It is very likely that this will be the same as your Firebase project name as well.) |
| 11 | +All configuration values for MapSwipe Workers are stored in environment variables. |
20 | 12 |
|
21 |
| -The `mapswipe_workers` module uses the [Firebase Python SDK](https://firebase.google.com/docs/reference/admin/python) to access *Firebase Database* services as administrator, you must generate a Service Account Key file in JSON format. For this we use the previously generated Service Account Key. (Check the *Google APIs and Services Credentials* section again if you don't have it.) Copy the file to `mapswipe_workers/config/serviceAccountKey.json`. |
| 13 | +Required environment variables are: |
| 14 | +- FIREBASE_API_KEY |
| 15 | +- FIREBASE_DB |
| 16 | +- GOOGLE_APPLICATION_CREDENTIALS |
| 17 | +- POSTGRES_DB |
| 18 | +- POSTGRES_HOST |
| 19 | +- POSTGRES_PASSWORD |
| 20 | +- POSTGRES_PORT |
| 21 | +- POSTGRES_USER |
22 | 22 |
|
23 |
| -The `mapswipe_workers` module further uses the [Firebase Database REST API](https://firebase.google.com/docs/reference/rest/database) to access *Firebase Database* either as a normal user or project manager. |
| 23 | +Mandatory environment variables are: |
| 24 | +- SLACK_CHANNEL |
| 25 | +- SLACK_TOKEN |
| 26 | +- SENTRY_DSN |
24 | 27 |
|
25 |
| -For both things to work you need to add your `database_name` in the configuration file. For the the REST API add also the previously generated *mapswipe_workers* api key. (Check the *Google APIs & Services Credentials* section again if you don't have it.) The firebase section in `mapswipe_workers/config/configuration.json` should look like this now: |
| 28 | +For satellite imagery access to at least one provider is needed. Define the API key as environment variable: |
| 29 | +- IMAGE_BING_API_KEY |
| 30 | +- IMAGE_MAPBOX_API_KEY |
| 31 | +- IMAGE_MAXA_PREMUIM_API_KEY |
| 32 | +- IMAGE_MAXAR_STANDARD_API_KEY |
| 33 | +- IMAGE_ESRI_API_KEY |
| 34 | +- IMAGE_ESRI_BETA_API_KEY |
26 | 35 |
|
27 |
| -```json |
28 |
| -"firebase": { |
29 |
| - "database_name": "your_database_name", |
30 |
| - "api_key": "mapswipe_workers_api_key" |
31 |
| -} |
32 |
| -``` |
| 36 | +In addition to get access to Firebase a Service Account Key is required. |
| 37 | +The path the Service Account Key is defined in: |
| 38 | +- GOOGLE_APPLICATION_CREDENTIALS |
33 | 39 |
|
34 |
| -The `manager_dashboard` module uses the [Firebase JavaScript client SDK](https://firebase.google.com/docs/database/web/start) to access *Firebase Database* service as authenticated as MapSwipe user with project manager credentials. Add the previously generated *manager-dashboard* api key. (Check the *Google APIs & Services Credentials* section again if you don't have it.) Project-id refers to the name of your Firebase project (e.g. dev-mapswipe). The firebaseConfig in `mapswipe_dashboard/js/app.js` should look like this now: |
| 40 | +> Notes: When deploying using `docker` or `docker-compose` `POSTGRES_HOST` should have the value `postgres` and the Service Account Key (`serviceAccountKey.json`) should be copied to `mapswipe_workers/serviceAccountKey.json` as described in detail in [Deployment](deployment.md). |
35 | 41 |
|
36 |
| -```javascript |
37 |
| -var firebaseConfig = { |
38 |
| - apiKey: "manager_dashboard_api_key", |
39 |
| - authDomain: "your_project_id.firebaseapp.com", |
40 |
| - databaseURL: "https://your_project_id.firebaseio.com", |
41 |
| - storageBucket: "your_project_id.appspot.com" |
42 |
| - }; |
43 |
| -``` |
44 | 42 |
|
45 |
| -The `firebase` module uses the [Firebase Command Line Interface (CLI) Tools](https://github.com/firebase/firebase-tools) to access *Firebase Database Rules* and *Firebase Functions*. You need a firebase token. Here's how you generate it: |
46 |
| -1. On a PC with a browser install the Firebase Command Line Tools ([https://firebase.google.com/docs/cli/](https://firebase.google.com/docs/cli/#install_the_firebase_cli)) |
47 |
| -2. Run `firebase login:ci` to generate a Firebase Token. |
48 |
| -3. Save the Firebase Token to `.env` at the root of the cloned MapSwipe Backend repository: `echo "FIREBASE_TOKEN=your_token" >> .env` |
49 |
| -4. You should have an entry for the firebase token in your `.env` now: |
50 |
| -
|
51 |
| -```bash |
52 |
| -FIREBASE_TOKEN="your_token" |
53 |
| -``` |
54 |
| -
|
55 |
| ---> |
56 |
| - |
57 |
| -# Configuration Reference |
| 43 | +## Postgres |
58 | 44 |
|
59 |
| -This document provides details on all required configuration files: |
| 45 | +Required environment variables are: |
| 46 | +- POSTGRES_DB |
| 47 | +- POSTGRES_HOST |
| 48 | +- POSTGRES_PASSWORD |
| 49 | +- POSTGRES_PORT |
| 50 | +- POSTGRES_USER |
60 | 51 |
|
61 |
| -- `.env file` |
62 |
| - * postgres password |
63 |
| - * firebase token |
64 |
| - * wal-g google storage prefix |
65 |
| -- `mapswipe_workers/config/configuration.json` |
66 |
| - * firebase: api-key, databaseName |
67 |
| - * postgres: host, port, database, username, password |
68 |
| - * imagery: urls, api keys |
69 |
| - * slack: token, username, channel |
70 |
| - * sentry: dsn value |
71 |
| -- `mapswipe_workers/config/serviceAccountKey.json` |
72 |
| - * check if file exists |
73 |
| -- `manager_dashboard/manager_dashboard/js/app.js` |
74 |
| - * firebase: authDomain, apiKey, databaseUrl, storageBucket |
75 |
| -- `nginx/nginx.conf` |
76 |
| - * server name |
77 |
| - * ssl certificates, ssl certificates key |
78 | 52 |
|
79 |
| -You can run the script `test_config.py` to check if you set all the needed variables and file. The script will test the following files: |
| 53 | +### Postgres Backup |
80 | 54 |
|
| 55 | +On details of how the back-up works please refer to [Postgres Backup](backup.md). |
81 | 56 |
|
82 |
| -## .env |
| 57 | +Required environment variables are: |
| 58 | +- WALG_GS_PREFIX |
83 | 59 |
|
84 |
| -The environment file (`.env`) contains all variables needed by services running in Docker container. |
| 60 | +To gain access to Google Cloud Storage another Service Account Key is needed. Again refer to [Postgres Backup](backup.md) on how to create this file. |
| 61 | +The Service Account Key (`serviceAccountKey.json`) should be saved to `postgres/serviceAccountKey.json` |
85 | 62 |
|
86 |
| -```.env |
87 |
| -POSTGRES_PASSWORD=password |
88 | 63 |
|
89 |
| -# Google Cloud Storage path for backups of Postgres |
90 |
| -WALG_GS_PREFIX=gs://x4m-test-bucket/walg-folder |
| 64 | +### Manager Dashboard |
91 | 65 |
|
92 |
| -# Token for deployment of Firebase Rules and Functions |
93 |
| -FIREBASE_TOKEN=firebase_token |
| 66 | +`manager_dashboard/manager_dashboard/js/app.js` |
94 | 67 |
|
95 |
| -GOOGLE_APPLICATION_CREDENTIALS=google_application_credentials |
96 | 68 | ```
|
97 |
| - |
98 |
| - |
99 |
| -## MapSwipe Workers - Configuration |
100 |
| - |
101 |
| -`mapswipe_workers/config/configuration.json`: |
102 |
| - |
103 |
| -```json |
104 |
| -{ |
105 |
| - "postgres": { |
106 |
| - "host": "postgres", |
107 |
| - "port": "5432", |
108 |
| - "database": "mapswipe", |
109 |
| - "username": "mapswipe_workers", |
110 |
| - "password": "your_mapswipe_db_password" |
111 |
| - }, |
112 |
| - "firebase": { |
113 |
| - "database_name": "your_firebase_database_name", |
114 |
| - "api_key": "your_firebase_api_key" |
115 |
| - }, |
116 |
| - "imagery":{ |
117 |
| - "bing": { |
118 |
| - "api_key": "your_bing_api_key", |
119 |
| - "url": "http://t0.tiles.virtualearth.net/tiles/a{quad_key}.jpeg?g=854&mkt=en-US&token={key}" |
120 |
| - }, |
121 |
| - "digital_globe": { |
122 |
| - "api_key": "your_digital_globe_api_key", |
123 |
| - "url": "https://api.mapbox.com/v4/digitalglobe.nal0g75k/{z}/{x}/{y}.png?access_token={key}" |
124 |
| - }, |
125 |
| - "sinergise": { |
126 |
| - "api_key": "your_sinergise_api_key", |
127 |
| - "url": "https://services.sentinel-hub.com/ogc/wmts/{key}?request=getTile&tilematrixset=PopularWebMercator256&tilematrix={z}&tilecol={x}&tilerow={y}&layer={layer}" |
128 |
| - } |
129 |
| - }, |
130 |
| - "slack": { |
131 |
| - "token": "your_slack_token", |
132 |
| - "channel": "your_slack_channel", |
133 |
| - "username": "your_slack_username" |
134 |
| - }, |
135 |
| - "sentry": { |
136 |
| - "dsn": "your_sentry_dsn_value" |
137 |
| - } |
138 |
| -} |
| 69 | +TODO |
139 | 70 | ```
|
140 | 71 |
|
141 | 72 |
|
142 | 73 | ## NGINX
|
143 | 74 |
|
| 75 | +`nginx/nginx.conf`: |
| 76 | + |
144 | 77 | ```
|
145 | 78 | server {
|
146 | 79 | listen 80;
|
@@ -181,19 +114,3 @@ server {
|
181 | 114 | }
|
182 | 115 | }
|
183 | 116 | ```
|
184 |
| - |
185 |
| -## Postgres Backup |
186 |
| -We back up the Postgres database using [Wal-G](https://github.com/wal-g/wal-g) and [Google Cloud Storage](https://console.cloud.google.com/storage). You could also set it up using another cloud storage service. |
187 |
| - |
188 |
| -First, create a new cloud storage bucket: |
189 |
| -1. Google Cloud Platform > Storage > Create Bucket |
190 |
| -2. Choose a bucket name, e.g. `your_project_id_postgres_backup` |
191 |
| -3. Select storage location > `Multi-Region` > `eu` |
192 |
| -4. Select storage class > `Coldline` |
193 |
| - |
194 |
| -We need to access Google Cloud Storage. For this we use the previously generated Service Account Key. (Check the *Google APIs and Services Credentials* section again if you don't have it.) Copy the file to `postges/serviceAccountKey.json`. |
195 |
| - |
196 |
| -```bash |
197 |
| -GCS_Link_URL=https://console.cloud.google.com/storage/browser/your_project_id_postgres_backup |
198 |
| -GCS_Link_for_gsutil=gs://your_project_id_postgres_backup |
199 |
| -``` |
0 commit comments