generated from geoadmin/template-service-flask
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from geoadmin/develop
New Release v1.1.0 - #minor
- Loading branch information
Showing
20 changed files
with
384 additions
and
349 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
ALLOWED_DOMAINS=http[s]?://localhost | ||
ALLOWED_DOMAINS=.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,4 +58,6 @@ nose2-junit.xml | |
*.orig | ||
|
||
# visual studio code config | ||
.vscode | ||
.vscode | ||
|
||
out.png |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
BSD 3-Clause License | ||
|
||
Copyright (c) 2020, swisstopo | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
1. Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
|
||
3. Neither the name of the copyright holder nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,9 +11,6 @@ | |
- [Description](#description) | ||
- [Dependencies](#dependencies) | ||
- [Service API](#service-api) | ||
- [Staging Environments](#staging-environments) | ||
- [checker GET](#checker-get) | ||
- [color GET](#color-get) | ||
- [Versioning](#versioning) | ||
- [Local Development](#local-development) | ||
- [Make Dependencies](#make-dependencies) | ||
|
@@ -22,8 +19,6 @@ | |
- [Test your work](#test-your-work) | ||
- [Docker](#docker) | ||
- [Deployment](#deployment) | ||
- [Dev](#dev) | ||
- [Int](#int) | ||
- [Deployment configuration](#deployment-configuration) | ||
|
||
## Description | ||
|
@@ -36,37 +31,19 @@ This service doesn't have any external dependencies | |
|
||
## Service API | ||
|
||
This service has two endpoints: | ||
The service has the following endpoints: | ||
|
||
- [checker GET](#checker-get) | ||
- [color GET](#color-get) | ||
- `GET /checker` | ||
- `GET /sets` | ||
- `GET /sets/<icon_set_name>` | ||
- `GET /sets/<icon_set_name>/icons` | ||
- `GET /sets/<icon_set_name>/icons/<icon_name>` | ||
- `GET /sets/<icon_set_name>/icons/<icon_name>.png` | ||
- `GET /sets/<icon_set_name>/icons/<icon_name>-<red>,<green>,<blue>.png` | ||
- `GET /sets/<icon_set_name>/icons/<icon_name>@<scale>.png` | ||
- `GET /sets/<icon_set_name>/icons/<icon_name>@<scale>-<red>,<green>,<blue>.png` | ||
|
||
A detailed descriptions of the endpoints can be found in the [OpenAPI Spec](openapi.yaml). | ||
|
||
### Staging Environments | ||
|
||
| Environments | URL | | ||
| ------------ | --------------------------------------------------------------------------------------------------------------------- | | ||
| DEV | [https://service-icons.bgdi-dev.swisstopo.cloud/v4/icons/](https://service-icons.bgdi-dev.swisstopo.cloud/v4/icons/) | | ||
| INT | [https://service-icons.bgdi-int.swisstopo.cloud/v4/icons/](https://service-icons.bgdi-int.swisstopo.cloud/v4/icons/) | | ||
| PROD | [https://service-icons.bgdi-prod.swisstopo.cloud/v4/icons/](https://service-icons.bgdi-int.swisstopo.cloud/v4/icons/) | | ||
|
||
### checker GET | ||
|
||
This is a simple route meant to test if the server is up. | ||
|
||
| Path | Method | Argument | Response Type | | ||
| ----------------- | ------ | -------- | ---------------- | | ||
| /v4/icons/checker | GET | - | application/json | | ||
|
||
### color GET | ||
|
||
This route takes a color (defined by r, g and b values) and the name of a file containing a symbol to be colorized | ||
and returns the colorized symbol. | ||
|
||
| Path | Method | Argument | Response Type | | ||
| --------- | ------ | ----------------- | ------------- | | ||
| /v4/icons | GET | r, g, b, filename | image/png | | ||
A detailed descriptions of the endpoints can be found in the [OpenAPI Spec](https://github.com/geoadmin/doc-api-specs) repository. | ||
|
||
## Versioning | ||
|
||
|
@@ -78,7 +55,7 @@ See also [Git Flow - Versioning](https://github.com/geoadmin/doc-guidelines/blob | |
|
||
### Make Dependencies | ||
|
||
The **Make** targets assume you have **python3.7**, **pipenv**, **bash**, **curl**, **tar**, **docker** and **docker-compose** installed. | ||
The **Make** targets assume you have **python3.9**, **pipenv**, **bash**, **curl**, **tar**, **docker** and **docker-compose** installed. | ||
|
||
### Setting up to work | ||
|
||
|
@@ -91,7 +68,7 @@ git clone [email protected]:geoadmin/service-icons | |
Then, you can run the setup target to ensure you have everything needed to develop, test and serve locally | ||
|
||
```bash | ||
make setup | ||
make dev | ||
``` | ||
|
||
That's it, you're ready to work. | ||
|
@@ -137,9 +114,14 @@ make dockerrun | |
|
||
This will serve the application with the wsgi server, inside a container. | ||
|
||
curl -H "Origin: https://map.geo.admin.ch/" http://localhost:5000/v4/icons/255,133,133/[email protected] --output out.dat | ||
Here below are simple examples of how to test the service after serving on localhost:5000: | ||
|
||
```bash | ||
curl -H "Origin: www.example.com" http://localhost:5000/sets/default/icons | ||
curl -H "Origin: www.example.com" http://localhost:5000/sets/default/icons/001-marker@2x-255,133,133.png --output out.png | ||
``` | ||
|
||
This is a simple example of how to test the service after serving on localhost:5000 (`out.dat` will either contain a PNG image or contain an error message.) | ||
*NOTE: if you serve using gunicorn or docker, you need to add the route prefix `/api/icons`* | ||
|
||
## Docker | ||
|
||
|
@@ -176,35 +158,6 @@ docker ps --format="table {{.ID}}\t{{.Image}}\t{{.Labels}}" | |
|
||
## Deployment | ||
|
||
This service is to be deployed to the Kubernetes cluster once it is merged. | ||
|
||
**Check on which k8s you are before doing anything** | ||
|
||
by running : | ||
|
||
```bash | ||
kubectl config get-contexts | ||
``` | ||
or (if you already have it installed) | ||
```bash | ||
kubectx | ||
``` | ||
|
||
Make sure you are on the right context (staging) for what you want to achieve | ||
|
||
### Dev | ||
|
||
To deploy (or refresh) on dev, we have to kill all pods. The K8S configuration is made so that it will revive any killed pod while always retrieving the latest docker image. | ||
So as soon as your merge on `develop` as been successfully built by the CI (and so the CI has pushed the new image to our AWS ECR registry) you can kill all dev pods by running | ||
|
||
```bash | ||
kubectl delete --all pods --namespace=service-icons | ||
``` | ||
|
||
### Int | ||
|
||
TO DO: give instructions to deploy to kubernetes. | ||
|
||
### Deployment configuration | ||
|
||
The service is configured by Environment Variable: | ||
|
@@ -213,5 +166,9 @@ The service is configured by Environment Variable: | |
| ----------- | --------------------- | -------------------------- | | ||
| LOGGING_CFG | `logging-cfg-local.yml` | Logging configuration file | | ||
| ALLOWED_DOMAINS | `.*` | Comma separated list of regex that are allowed as domain in Origin header | | ||
| CACHE_CONTROL | `public, max-age=86400` | Cache Control header value of the `GET /v4/icons/*` endpoints | | ||
| CACHE_CONTROL | `public, max-age=86400` | Cache Control header value of the `GET /*` endpoints | | ||
| CACHE_CONTROL_4XX | `public, max-age=3600` | Cache Control header for 4XX responses | | ||
| FORWARED_ALLOW_IPS | `*` | Sets the gunicorn `forwarded_allow_ips`. See [Gunicorn Doc](https://docs.gunicorn.org/en/stable/settings.html#forwarded-allow-ips). This setting is required in order to `secure_scheme_headers` to work. | | ||
| FORWARDED_PROTO_HEADER_NAME | `X-Forwarded-Proto` | Sets gunicorn `secure_scheme_headers` parameter to `{${FORWARDED_PROTO_HEADER_NAME}: 'https'}`. This settings is required in order to generate correct URLs in the service responses. See [Gunicorn Doc](https://docs.gunicorn.org/en/stable/settings.html#secure-scheme-headers). | | ||
| SCRIPT_NAME | `''` | If the service is behind a reverse proxy and not served at the root, the route prefix must be set in `SCRIPT_NAME`. | | ||
| WSGI_TIMEOUT | `5` | WSGI timeout. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.