Skip to content

Commit 02aa5f7

Browse files
authored
Merge pull request #195 from mapswipe/dev
Updated Tutorial
2 parents c13b647 + a9732d5 commit 02aa5f7

25 files changed

+697
-63239
lines changed

docs/source/cli.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Command Line Interface
22

3+
This document describes how to use the command line interface of MapSwipe Worker.
4+
5+
In our current deployment setup the commands of the MapSwipe Workers CLI are hard-coded in the Docker-Compose File.
6+
7+
38
```
49
Usage: mapswipe_workers [OPTIONS] COMMAND [ARGS]...
510
@@ -10,9 +15,11 @@ Options:
1015
1116
Commands:
1217
create-projects
18+
create-tutorial
1319
firebase-to-postgres
1420
generate-stats
1521
run
22+
user-management
1623
```
1724

1825

@@ -47,8 +54,10 @@ Options:
4754
Usage: mapswipe_workers generate-stats [OPTIONS]
4855
4956
Options:
50-
-s, --schedule [m|h|d] Will generate stats every 10 minutes (m), every hour
51-
(h) or every day (d).
57+
-s, --schedule [m|h|d] Generate stats every 10 minutes (m), every hour (h)
58+
or every day (d).
59+
--only_new_results Generate stats for all projects or only for those
60+
updated or with new results.
5261
--help Show this message and exit.
5362
```
5463

docs/source/configuration.md

Lines changed: 125 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,4 @@
1-
# Configuration Reference
2-
This document describes all configuration details used by the python-mapswipe-workers. By the end of this document the following configuration files will be set up:
3-
4-
* `.env`
5-
* `mapswipe_workers/config/configuration.json`
6-
* `mapswipe_workers/config/serviceAccountKey.json`
7-
* `manager_dashboard/manager_dashboard/js/app.js`
8-
* `nginx/nginx.conf`
9-
10-
## Google APIs & Services Credentials
11-
The python-mapswipe workers use a bunch of services provided by Google Cloud Platform. It's best to start to configure all api keys we need later directly from the beginning in Google APIs & Services.
12-
1. Open [Google APIs & Services > Credentials](https://console.cloud.google.com/apis/credentials)
13-
2. Create API key for MapSwipe workers:
14-
* set name of api key to `mapswipe_workers_api_key`
15-
* set Application restrictions > IP addresses > set IP addresse of mapswipe workers server`
16-
* set API restrictions > Restrict Key > Identity Toolkit API
17-
3. Create API key for Manager Dashboard:
18-
* set name of api key to `manager_dashboard_api_key`
19-
* set Application restrictions > HTTP referrers > set HTTP referrer of managers dashboard (e.g. `https://dev.mapswipe.org`)
20-
* set API restrictions > Restrict Key > Identity Toolkit API and Cloud Functions API
21-
4. Also make sure to configure the API keys for the App side here.
1+
<!--
222
233
Then set up a Service Account Key file:
244
1. Open [Google Cloud Service Accounts](https://console.cloud.google.com/iam-admin/serviceaccounts)
@@ -28,7 +8,12 @@ Then set up a Service Account Key file:
288
3. Download Key as file:
299
* select `.json` and save
3010
11+
12+
13+
14+
3115
## Firebase
16+
3217
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:
3318
1. `your_project_id`: This is the name of your Firebase project (e.g. *dev-mapswipe*)
3419
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.)
@@ -67,89 +52,148 @@ The `firebase` module uses the [Firebase Command Line Interface (CLI) Tools](htt
6752
FIREBASE_TOKEN="your_token"
6853
```
6954
70-
## Postgres
71-
The `postgres` module initializes a Postgres database. When running Postgres using the provided Dockerfile it will setup the database during the build. A Postgres password has to be defined in an environment file in the same directory as the `docker-compose.yaml` file (root). Add the following line to your `.env` file:
55+
-->
7256

73-
```bash
74-
POSTGRES_PASSWORD=your_mapswipe_db_password
75-
```
57+
# Configuration Reference
7658

77-
The `mapswipe_workers` module write data to the Postgres database and generate files for the `api` module based on views in Postgres. You need to provide information on Postgres in your `mapswipe_workers/config/configuration.json`.:
59+
This document provides details on all required configuration files:
7860

79-
```json
80-
"postgres": {
81-
"host": "postgres",
82-
"port": "5432",
83-
"database": "mapswipe",
84-
"username": "mapswipe_workers",
85-
"password": "your_mapswipe_db_password"
86-
},
87-
```
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
8878

89-
## Postgres Backup
90-
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.
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:
9180

92-
First, create a new cloud storage bucket:
93-
1. Google Cloud Platform > Storage > Create Bucket
94-
2. Choose a bucket name, e.g. `your_project_id_postgres_backup`
95-
3. Select storage location > `Multi-Region` > `eu`
96-
4. Select storage class > `Coldline`
9781

98-
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`.
82+
## .env
9983

100-
```bash
101-
GCS_Link_URL=https://console.cloud.google.com/storage/browser/your_project_id_postgres_backup
102-
GCS_Link_for_gsutil=gs://your_project_id_postgres_backup
103-
```
84+
The environment file (`.env`) contains all variables needed by services running in Docker container.
10485

105-
## Nginx
106-
The `nginx` module serves the MapSwipe API and Manager Dashboard. If you want these point to a specific domain, make sure to set it up. In our setup we use Google domains. Other tools will work similar.
86+
```.env
87+
POSTGRES_PASSWORD=password
10788
108-
Once you got your domain name add it to `nginx/nginx.conf`:
89+
# Google Cloud Storage path for backups of Postgres
90+
WALG_GS_PREFIX=gs://x4m-test-bucket/walg-folder
10991
92+
# Token for deployment of Firebase Rules and Functions
93+
FIREBASE_TOKEN=firebase_token
94+
95+
GOOGLE_APPLICATION_CREDENTIALS=google_application_credentials
11096
```
111-
server_name your_domain.org;
112-
```
11397

114-
To enable SSL for the API and MapSwipe Manager Dashboard we use [Certbot](https://certbot.eff.org/) to issue standalone certificates using [Let's Encrypt](https://letsencrypt.org/).
11598

116-
## Imagery
117-
MapSwipe uses satellite imagery provided by Tile Map Services (TMS). If you are not familiar with the basic concept have a look at [Bing's documentation](https://docs.microsoft.com/en-us/bingmaps/articles/bing-maps-tile-system). Make sure to get api keys for the services you would like to use in your app. For each satellite imagery provider add an `api_key` and `url`. You need to provide information on Imagery in your `mapswipe_workers/config/configuration.json`.:
99+
## MapSwipe Workers - Configuration
100+
101+
`mapswipe_workers/config/configuration.json`:
118102

119103
```json
120-
"imagery": {
121-
"bing": {
122-
"api_key": "your_bing_api_key",
123-
"url": "http://t0.tiles.virtualearth.net/tiles/a{quad_key}.jpeg?g=854&mkt=en-US&token={key}"
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+
}
124129
},
125-
"digital_globe": {
126-
"api_key": "your_digital_globe_api_key",
127-
"url": "https://api.mapbox.com/v4/digitalglobe.nal0g75k/{z}/{x}/{y}.png?access_token={key}"
130+
"slack": {
131+
"token": "your_slack_token",
132+
"channel": "your_slack_channel",
133+
"username": "your_slack_username"
128134
},
129-
"sinergise": {
130-
"api_key": "your_sinergise_api_key",
131-
"url": "https://services.sentinel-hub.com/ogc/wmts/{key}?request=getTile&tilematrixset=PopularWebMercator256&tilematrix={z}&tilecol={x}&tilerow={y}&layer={layer}"
135+
"sentry": {
136+
"dsn": "your_sentry_dsn_value"
132137
}
133-
}
138+
}
134139
```
135140

136-
## Sentry (optional)
137-
The `mapswipe_workers` module uses sentry to capture exceptions. You can find your project’s DSN in the “Client Keys” section of your “Project Settings” in Sentry. Check [Sentry's documentation](https://docs.sentry.io/error-reporting/configuration/?platform=python) for more information. You need to provide information on Sentry in your `mapswipe_workers/config/configuration.json`.:
138141

139-
```json
140-
"sentry": {
141-
"dsn": "your_sentry_dsn_value"
142-
}
142+
## NGINX
143+
143144
```
145+
server {
146+
listen 80;
147+
server_name dev.mapswipe.org;
144148
145-
## Slack (optional)
146-
The `mapswipe_workers` module sends messages to slack when a project has been created successfully, the project creation failed or an exception during mapswipe_workers cli occurred. You need to add a slack token to use slack messaging. You can find out more from [Python slackclient's documentation](https://github.com/slackapi/python-slackclient) how to get it. You need to provide information on Slack in your `mapswipe_workers/config/configuration.json`.:
149+
location / {
150+
return 301 https://$host$request_uri;
151+
}
152+
}
147153
148-
```json
149-
"slack": {
150-
"token": "your_slack_token",
151-
"channel": "your_slack_channel",
152-
"username": "your_slack_username"
153-
},
154+
155+
server {
156+
listen 443 ssl;
157+
158+
ssl_certificate /etc/letsencrypt/live/dev.mapswipe.org/fullchain.pem;
159+
ssl_certificate_key /etc/letsencrypt/live/dev.mapswipe.org/privkey.pem;
160+
161+
server_name dev.mapswipe.org;
162+
163+
location /api/ {
164+
proxy_pass http://api:80/;
165+
}
166+
167+
location /api {
168+
rewrite ^ /api/ permanent;
169+
}
170+
171+
location /manager_dashboard/ {
172+
proxy_pass http://manager_dashboard:80/;
173+
}
174+
175+
location /manager_dashboard {
176+
rewrite ^ /manager_dashboard/ permanent;
177+
}
178+
179+
location / {
180+
rewrite ^ /manager_dashboard/ permanent;
181+
}
182+
}
154183
```
155184

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+
```

docs/source/deployment_overview.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Deployment Overview
2+
3+
The MapSwipe Back-End is deployed using Docker.
4+
Every part of the back-end has a Dockerfile.
5+
All parts/ Dockerfiles come together in the docker-compose file.
6+
7+
To setup the whole ecosystem of MapSwipe Workers it is easier to first make sure every part is configured and all keys are in place.
8+
9+
MapSwipe utilizes a bunch of Google Cloud services:
10+
11+
- [Firebase](https://firebase.google.com/) project with Realtime Database and Functions
12+
- Create a project
13+
- Create a database: `> Develop > Database > Create Database`
14+
- [Google Cloud Storage](https://cloud.google.com/storage/) for backup of Postgres
15+
16+
[Configuration and Credentials]() describes all needed configuration and credentials.
17+
18+
[Installation]() describes step-by-step how to setup the backend for the first time.

docs/source/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Welcome to MapSwipe Back-End's documentation!
2626
:maxdepth: 2
2727
:caption: Deployment:
2828

29+
deployment_overview
2930
configuration
3031
installation
3132
tutorials

0 commit comments

Comments
 (0)