Skip to content

Commit 5c98346

Browse files
committed
Initial commit
0 parents  commit 5c98346

15 files changed

+354
-0
lines changed

.coveragerc

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# .coveragerc to control coverage.py
2+
[run]
3+
branch = True
4+
omit = ./tests*,
5+
./.venv/*
6+
7+
[report]
8+
# Regexes for lines to exclude from consideration
9+
exclude_lines =
10+
# Have to re-enable the standard pragma
11+
pragma: no cover
12+
13+
# Don't complain about missing debug-only code:
14+
def __repr__
15+
if self\.debug
16+
17+
# Don't complain if tests don't hit defensive assertion code:
18+
raise AssertionError
19+
raise NotImplementedError
20+
21+
# Don't complain if non-runnable code isn't run:
22+
if 0:
23+
if __name__ == .__main__.:
24+
25+
ignore_errors = True
26+
27+
[html]
28+
directory = coverage_html_report

.flaskenv

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CAPTCHA_API_CONFIG=test_adapter_config.py
2+
FLASK_APP=wsgi.py
3+
FLASK_DEBUG=1

.gitignore

+139
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# Adapter configurations for testing
7+
test_adapter_config*.py
8+
9+
# C extensions
10+
*.so
11+
12+
# Distribution / packaging
13+
.Python
14+
build/
15+
develop-eggs/
16+
dist/
17+
downloads/
18+
eggs/
19+
.eggs/
20+
lib/
21+
lib64/
22+
parts/
23+
sdist/
24+
var/
25+
wheels/
26+
pip-wheel-metadata/
27+
share/python-wheels/
28+
*.egg-info/
29+
.installed.cfg
30+
*.egg
31+
MANIFEST
32+
33+
# PyInstaller
34+
# Usually these files are written by a python script from a template
35+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
36+
*.manifest
37+
*.spec
38+
39+
# Installer logs
40+
pip-log.txt
41+
pip-delete-this-directory.txt
42+
43+
# Unit test / coverage reports
44+
htmlcov/
45+
.tox/
46+
.nox/
47+
.coverage
48+
.coverage.*
49+
.cache
50+
nosetests.xml
51+
coverage.xml
52+
*.cover
53+
*.py,cover
54+
.hypothesis/
55+
.pytest_cache/
56+
57+
# Translations
58+
*.mo
59+
*.pot
60+
61+
# Django stuff:
62+
*.log
63+
local_settings.py
64+
db.sqlite3
65+
db.sqlite3-journal
66+
67+
# Flask stuff:
68+
instance/
69+
.webassets-cache
70+
71+
# Scrapy stuff:
72+
.scrapy
73+
74+
# Sphinx documentation
75+
docs/_build/
76+
77+
# PyBuilder
78+
target/
79+
80+
# Jupyter Notebook
81+
.ipynb_checkpoints
82+
83+
# IPython
84+
profile_default/
85+
ipython_config.py
86+
87+
# pyenv
88+
.python-version
89+
90+
# pipenv
91+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
93+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
94+
# install all needed dependencies.
95+
#Pipfile.lock
96+
97+
# celery beat schedule file
98+
celerybeat-schedule
99+
100+
# SageMath parsed files
101+
*.sage.py
102+
103+
# Environments
104+
.env
105+
.venv
106+
env/
107+
venv/
108+
ENV/
109+
env.bak/
110+
venv.bak/
111+
112+
# Spyder project settings
113+
.spyderproject
114+
.spyproject
115+
116+
# Rope project settings
117+
.ropeproject
118+
119+
# mkdocs documentation
120+
/site
121+
122+
# mypy
123+
.mypy_cache/
124+
.dmypy.json
125+
dmypy.json
126+
127+
# Pyre type checker
128+
.pyre/
129+
130+
#Ours
131+
.vscode
132+
.idea
133+
config
134+
.gitlab-ci.yml
135+
openshift
136+
coverage_html_report
137+
138+
# Test database
139+
test.db

Dockerfile

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM python:3.8-slim
2+
3+
RUN apt-get update && apt-get install -y -qq libfreetype6 fontconfig-config
4+
5+
WORKDIR /app
6+
COPY . .
7+
ENV PIP_CONFIG_FILE /app/pip.conf
8+
9+
RUN pip install --no-cache-dir -r requirements.txt
10+
11+
EXPOSE 8080
12+
CMD [ "gunicorn", "--bind", "0.0.0.0:8080", "wsgi:app" ]

activate.sh

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
if [ -s ./.venv ] ; then
2+
. ./.venv/bin/activate ;
3+
else
4+
echo 'No venv defined, creating...' ;
5+
venvprompt=${PWD##*/}
6+
python -m venv --prompt $venvprompt .venv ;
7+
. ./.venv/bin/activate ;
8+
fi;
9+

captcha_api/__init__.py

Whitespace-only changes.

dev-requirements.txt

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pytest
2+
flake8
3+
pylint
4+
coverage

gitlab-ci.yml

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
image: python:3.8-slim
2+
variables:
3+
NAMESPACE_PROD: captcha
4+
APP_NAME: ${CI_PROJECT_NAME}
5+
6+
stages:
7+
- lint
8+
- test
9+
- build_docker
10+
- deploy
11+
12+
.docker_build_template: &docker_definition
13+
stage: build_docker
14+
image:
15+
# We recommend using the CERN version of the Kaniko image: gitlab-registry.cern.ch/ci-tools/docker-image-builder
16+
name: gitlab-registry.cern.ch/ci-tools/docker-image-builder
17+
entrypoint: [""]
18+
script:
19+
# Prepare Kaniko configuration file
20+
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
21+
# Build and push the image from the Dockerfile at the root of the project.
22+
# To push to a specific docker tag, amend the --destination parameter, e.g. --destination $CI_REGISTRY_IMAGE:$CI_BUILD_REF_NAME
23+
# See https://docs.gitlab.com/ee/ci/variables/predefined_variables.html#variables-reference for available variables
24+
- /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination ${TO}
25+
26+
.deploy_template: &deploy_definition
27+
stage: deploy
28+
image: gitlab-registry.cern.ch/paas-tools/openshift-client:latest
29+
script:
30+
- LOWERCASE_PATH=$(echo ${CI_PROJECT_PATH} | awk '{ print tolower($0) } ')
31+
# Adding || true to disable the error message when the image already exists
32+
- oc import-image ${APP_NAME} --from="gitlab-registry.cern.ch/${LOWERCASE_PATH}:${TAG}" --confirm --token=${TOKEN} --server=${OPENSHIFT_SERVER} -n ${NAMESPACE} || true
33+
- oc tag "gitlab-registry.cern.ch/${LOWERCASE_PATH}:${TAG}" "${APP_NAME}:latest" --token=${TOKEN} --server=${OPENSHIFT_SERVER} -n ${NAMESPACE}
34+
35+
### Linting
36+
flake8:
37+
image: python:3.8-alpine
38+
stage: lint
39+
before_script:
40+
- pip install -r dev-requirements.txt
41+
script:
42+
- python -m flake8 *.py captcha_api
43+
allow_failure: true
44+
45+
pylint:
46+
image: python:3.8-alpine
47+
stage: lint
48+
before_script:
49+
- pip install -r dev-requirements.txt
50+
script:
51+
- python -m pylint *.py captcha_api
52+
allow_failure: true
53+
54+
### Testing
55+
test:
56+
stage: test
57+
before_script:
58+
- export PIP_CONFIG_FILE=$(pwd)/pip.conf
59+
- apt-get update && apt-get install -y -qq libfreetype6 fontconfig-config
60+
- pip install -r dev-requirements.txt
61+
- pip install -r requirements.txt
62+
script:
63+
- coverage run -m pytest
64+
- coverage html
65+
- coverage xml
66+
- coverage report
67+
artifacts:
68+
reports:
69+
cobertura: coverage.xml
70+
paths:
71+
- coverage_html_report
72+
expire_in: 1 week
73+
74+
### Docker build definitions
75+
76+
build_docker_prod:
77+
<<: *docker_definition
78+
variables:
79+
TO: ${CI_REGISTRY_IMAGE}:${PROD_TAG}
80+
only:
81+
- master # the branch you want to publish
82+
83+
### Deployment definitions
84+
85+
86+
deploy_prod:
87+
<<: *deploy_definition
88+
variables:
89+
ENVIRONMENT: prod
90+
TOKEN: ${OPENSHIFT_DEPLOY_TOKEN}
91+
OPENSHIFT_SERVER: ${OPENSHIFT_SERVER_PROD}
92+
NAMESPACE: ${NAMESPACE_PROD}
93+
TAG: ${PROD_TAG}
94+
ROUTE_HOSTNAME: https://captcha.web.cern.ch
95+
environment:
96+
name: prod
97+
url: https://captcha.web.cern.ch
98+
only:
99+
- master

requirements.txt

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Flask==1.1.1
2+
gunicorn>=19.5.0
3+
requests==2.23.*
4+
flask-restx==0.2.0
5+
certifi==2019.11.28
6+
werkzeug==0.16.1
7+
flask_cors==3.0.*
8+
python-dotenv==0.12.0
9+
flask-sqlalchemy==2.4.4
10+
pillow==7.2.0
11+
celery==4.4.7
12+
redis==3.5.3

setup.cfg

Whitespace-only changes.

setup.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env python
2+
3+
from os import path
4+
5+
from setuptools import setup, find_packages
6+
7+
8+
def load_requirements():
9+
try:
10+
with open("requirements.txt", "r") as f:
11+
return f.readlines()
12+
except:
13+
print("Exception getting requirements.txt file, returning []")
14+
return []
15+
16+
17+
here = path.abspath(path.dirname(__file__))
18+
19+
setup(
20+
name="captcha-api",
21+
version="0.1.0",
22+
description="CERN CAPTCHA service",
23+
url="https://gitlab.cern.ch/authzsvc/backends/captcha-api",
24+
author="MALT IAM team",
25+
author_email="[email protected]",
26+
classifiers=[
27+
"Development Status :: 4 - Beta",
28+
"Intended Audience :: Developers",
29+
"Topic :: Software Development :: Libraries :: Python Modules",
30+
"Programming Language :: Python :: 3.7",
31+
"Programming Language :: Python :: 3.8",
32+
],
33+
install_requires=load_requirements(),
34+
keywords=["captcha", "service", "Flask", "SQLAlchemy", "CLI"],
35+
packages=find_packages(exclude=("tests*", "*tests", "tests")),
36+
include_package_data=True
37+
)

tests/__init__.py

Whitespace-only changes.

tests/testing_config.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SQLALCHEMY_DATABASE_URI = "sqlite://"

tests/unit/__init__.py

Whitespace-only changes.

wsgi.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from captcha_api.app_factory import create_app
2+
3+
app = create_app()
4+
5+
if __name__ == "__main__":
6+
app.run(
7+
host="0.0.0.0",
8+
port=5000,
9+
debug=True,
10+
)

0 commit comments

Comments
 (0)