Skip to content

Commit

Permalink
Merge pull request #44 from geoadmin/feat-license-and-updates
Browse files Browse the repository at this point in the history
Added license and some updates - #minor
  • Loading branch information
ltshb authored Jan 19, 2022
2 parents 6ddeceb + 0b232f5 commit c3017f5
Show file tree
Hide file tree
Showing 11 changed files with 280 additions and 280 deletions.
7 changes: 4 additions & 3 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[settings]
known_third_party=pytest
known_flask=flask
known_third_party=pytest,celery,gatilegrid
known_flask=flask,flask_sqlalchemy
known_sqlalchemy=sqlalchemy
force_single_line=True
sections=FUTURE,STDLIB,THIRDPARTY,FLASK,FIRSTPARTY,LOCALFOLDER
sections=FUTURE,STDLIB,THIRDPARTY,SQLALCHEMY,FLASK,FIRSTPARTY,LOCALFOLDER
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ ignore-docstrings=yes
ignore-imports=no

# Minimum lines number of a similarity.
min-similarity-lines=4
min-similarity-lines=20


[VARIABLES]
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Buster slim python 3.7 base image.
FROM python:3.7-slim-buster
# Buster slim python 3.9 base image.
FROM python:3.9-slim-buster
ENV HTTP_PORT 8080
RUN groupadd -r geoadmin && useradd -r -s /bin/false -g geoadmin geoadmin

Expand Down
29 changes: 29 additions & 0 deletions LICENSE
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.
15 changes: 7 additions & 8 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ verify_ssl = true
name = "pypi"

[packages]
PyYAML = "~=5.4"
gevent = "~=20.9.0"
gunicorn = "~=19.9.0"
Flask = "~=1.1.1"
Pillow = "~=8.1.1"
logging-utilities = "~=1.2.1"
python-dotenv = "~=0.19.1"
PyYAML = "*"
gevent = "*"
gunicorn = "*"
Flask = "*"
logging-utilities = "*"
python-dotenv = "*"

[dev-packages]
yapf = "*"
Expand All @@ -20,4 +19,4 @@ pylint-flask = "*"
shellcheck-py = "*"

[requires]
python_version = "3.7"
python_version = "3.9"
464 changes: 216 additions & 248 deletions Pipfile.lock

Large diffs are not rendered by default.

17 changes: 4 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

- [Table of content](#table-of-content)
- [Description](#description)
- [Staging Environments](#staging-environments)
- [Versioning](#versioning)
- [Local Development](#local-development)
- [Make Dependencies](#make-dependencies)
Expand All @@ -25,14 +24,6 @@
A simple description of the service should go here
A detailed descriptions of the endpoints can be found in the [OpenAPI Spec](openapi.yaml).

### Staging Environments

| Environments | URL |
| ------------ | --------------------------------------------------------------------------------------------------------------------- |
| DEV | [https://service-name.bgdi-dev.swisstopo.cloud/v4/name/](https://service-name.bgdi-dev.swisstopo.cloud/v4/name/) |
| INT | [https://service-name.bgdi-int.swisstopo.cloud/v4/name/](https://service-name.bgdi-int.swisstopo.cloud/v4/name/) |
| PROD | [https://service-name.bgdi-prod.swisstopo.cloud/v4/name/](https://service-name.bgdi-int.swisstopo.cloud/v4/name/) |

## Versioning

This service uses [SemVer](https://semver.org/) as versioning scheme. The versioning is automatically handled by `.github/workflows/main.yml` file.
Expand All @@ -43,7 +34,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

Expand Down Expand Up @@ -137,9 +128,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.
TO DO: give instructions to deploy to kubernetes.

### Deployment configuration

The service is configured by Environment Variable:
Expand All @@ -149,3 +137,6 @@ The service is configured by Environment Variable:
| LOGGING_CFG | logging-cfg-local.yml | Logging configuration file |
| FORWARED_ALLOW_IPS | `*` | Sets the gunicorn `forwarded_allow_ips` (see https://docs.gunicorn.org/en/stable/settings.html#forwarded-allow-ips). This is required in order to `secure_scheme_headers` to works. |
| FORWARDED_PROTO_HEADER_NAME | `X-Forwarded-Proto` | Sets gunicorn `secure_scheme_headers` parameter to `{FORWARDED_PROTO_HEADER_NAME: 'https'}`, see 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_WORKERS | `2` | WSGI service number of workers. 0 or negative value means that the number of worker are computed from the number of cpu. |
| WSGI_TIMEOUT | `30`| WSGI timeout. |
5 changes: 5 additions & 0 deletions app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,8 @@
# Proxy settings
FORWARED_ALLOW_IPS = os.getenv('FORWARED_ALLOW_IPS', '*')
FORWARDED_PROTO_HEADER_NAME = os.getenv('FORWARDED_PROTO_HEADER_NAME', 'X-Forwarded-Proto')
WSGI_WORKERS = int(os.getenv('WSGI_WORKERS', '2'))
if WSGI_WORKERS <= 0:
from multiprocessing import cpu_count
WSGI_WORKERS = (cpu_count() * 2) + 1
WSGI_TIMEOUT = int(os.getenv('WSGI_TIMEOUT', '3'))
4 changes: 2 additions & 2 deletions buildspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ env:
phases:
install:
runtime-versions:
python: 3.7
python: 3.9
commands:
- aws --version
- echo "Login to AWS ECR docker registry"
Expand All @@ -29,7 +29,7 @@ phases:
export GITHUB_BRANCH=${GITHUB_BRANCH#remotes/origin/};
fi
- export GITHUB_COMMIT=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
- export GITHUB_TAG="$(git describe --tags 2>/dev/null)"
- export GITHUB_TAG="$(git describe --tags || echo 'no-version-info')"
- echo "GITHUB_BRANCH=${GITHUB_BRANCH} GITHUB_COMMIT=${GITHUB_COMMIT} GITHUB_TAG=${GITHUB_TAG} DOCKER_IMG_TAG=${DOCKER_IMG_TAG}"
- echo "Creating a clean environment"
- make ci
Expand Down
4 changes: 3 additions & 1 deletion service_launcher.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
'''Service launcher to use Flask without wsgi.py
'''
from app import app # pylint: disable=unused-import
from app.helpers.utils import init_logging

# Initialize Logging using JSON format for all loggers and using the Stream Handler.
init_logging()

# pylint: disable=unused-import,wrong-import-position
from app import app # pylint: disable=unused-import
9 changes: 7 additions & 2 deletions wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from app.settings import FORWARDED_PROTO_HEADER_NAME
from app.settings import FORWARED_ALLOW_IPS
from app.settings import HTTP_PORT
from app.settings import WSGI_WORKERS
from app.settings import WSGI_TIMEOUT


class StandaloneApplication(BaseApplication): # pylint: disable=abstract-method
Expand Down Expand Up @@ -32,8 +34,11 @@ def load(self):
options = {
'bind': f"0.0.0.0:{HTTP_PORT}",
'worker_class': 'gevent',
'workers': 2, # scaling horizontally is left to Kubernetes
'timeout': 60,
'workers': WSGI_WORKERS,
'timeout': WSGI_TIMEOUT,
'access_log_format':
'%(h)s %(l)s %(u)s "%(r)s" %(s)s %(B)s Bytes '
'"%(f)s" "%(a)s" %(L)ss',
'logconfig_dict': get_logging_cfg(),
'forwarded_allow_ips': FORWARED_ALLOW_IPS,
'secure_scheme_headers': {
Expand Down

0 comments on commit c3017f5

Please sign in to comment.