project structure done

This commit is contained in:
Torma Kristóf 2020-07-18 12:34:52 +02:00
parent 5b54d365dc
commit 940792c9b7
Signed by: tormakris
GPG Key ID: DC83C4F2C41B1047
15 changed files with 424 additions and 0 deletions

140
.dockerignore Normal file
View File

@ -0,0 +1,140 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
.python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
#Pycharm
.idea/
*.md
.gitignore
.git/
*.yml
contrib/*
postman/*
*.wav

77
.drone.yml Normal file
View File

@ -0,0 +1,77 @@
kind: pipeline
type: docker
name: default
steps:
- name: restore-cache-with-filesystem
image: meltwater/drone-cache
settings:
backend: "filesystem"
restore: true
cache_key: "{{ .Repo.Name }}"
archive_format: "gzip"
filesystem_cache_root: "/tmp/cache"
mount:
- '.pipcache'
volumes:
- name: cache
path: /tmp/cache
- name: static_analysis
image: "python:3.8"
commands:
- pip3 install --cache-dir='./.pipcache' pylint bandit mccabe
- pip3 install --cache-dir='./.pipcache' -r requirements.txt
- find . -name "*.py" -exec python3 -m py_compile '{}' \;
- find . -name "*.py" -exec pylint '{}' + || if [ $? -eq 1 ]; then echo "you fail"; fi
- find . -name "*.py" -exec python3 -m mccabe --min 3 '{}' + || if [ $? -eq 1 ]; then echo "you fail"; fi
- bandit -r . + || if [ $? -eq 1 ]; then echo "you fail"; fi
- name: code-analysis
image: aosapps/drone-sonar-plugin
settings:
sonar_host:
from_secret: SONAR_HOST
sonar_token:
from_secret: SONAR_CODE
- name: rebuild-cache-with-filesystem
image: meltwater/drone-cache:dev
pull: true
settings:
backend: "filesystem"
rebuild: true
cache_key: "{{ .Repo.Name }}"
archive_format: "gzip"
filesystem_cache_root: "/tmp/cache"
mount:
- '.pipcache'
volumes:
- name: cache
path: /tmp/cache
- name: kaniko
image: banzaicloud/drone-kaniko
settings:
registry: registry.kmlabz.com
repo: birbnetes/${DRONE_REPO_NAME}
username:
from_secret: DOCKER_USERNAME
password:
from_secret: DOCKER_PASSWORD
tags:
- latest
- ${DRONE_BUILD_NUMBER}
- name: ms-teams
image: kuperiu/drone-teams
settings:
webhook:
from_secret: TEAMS_WEBHOOK
when:
status: [ failure ]
volumes:
- name: cache
host:
path: "/tmp/cache"

8
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/

15
.idea/guard-service.iml Normal file
View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/k8s" type="java-resource" />
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.8 (guard-service)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="pytest" />
</component>
</module>

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

7
.idea/misc.xml Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8 (guard-service)" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/guard-service.iml" filepath="$PROJECT_DIR$/.idea/guard-service.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

17
Dockerfile Normal file
View File

@ -0,0 +1,17 @@
FROM python:3.8-slim
ENV TZ Europe/Budapest
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
WORKDIR /app
ARG RELEASE_ID
ENV RELEASE_ID ${RELEASE_ID:-""}
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY ./src .
ENTRYPOINT ["python3", "app.py"]

37
docker-compose.yml Normal file
View File

@ -0,0 +1,37 @@
networks:
guard:
external: false
services:
rabbitmq:
image: "rabbitmq:3"
hostname: "test-rabbitmq"
environment:
RABBITMQ_ERLANG_COOKIE: "akjahsfvbkueasnvfjkhsga"
RABBITMQ_DEFAULT_USER: "rabbitmq"
RABBITMQ_DEFAULT_PASS: "rabbitmq"
RABBITMQ_DEFAULT_VHOST: "/"
networks:
- guard
ports:
- "127.0.0.1:15672:15672"
- "127.0.0.1:5672:5672"
activemq:
image: registry.kmlabz.com/birbnetes/activemq-artemis
restart: always
networks:
- guard
volumes:
- ./artemis-volume:/var/lib/artemis-instance
guard-service:
image: registry.kmlabz.com/birbnetes/guard-service
restart: always
depends_on:
- activemq
- postgres
networks:
- guard
ports:
- "127.0.0.1:8080:8080"

19
k8s/configmap.yaml Normal file
View File

@ -0,0 +1,19 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: guard-service
labels:
app: guard-service
namespace: birbnetes
data:
SENTRY_DSN: "https://80d27db8c74f4556a19a1bf0180b373f@sentry.kmlabz.com/23"
RELEASE_ID: birb-k8s
GUARD_SERVICE_RELEASEMODE: release
GUARD_RABBITMQ_HOSTNAME: birb-rabbitmq
GUARD_RABBITMQ_EXCHANGE: "sample"
GUARD_RABBITMQ_USERNAME: user
GUARD_RABBITMQ_PASSWORD: 1wZVQnP5vy
GUARD_MQTT_HOSTNAME: guard-postgres
GUARD_MQTT_USERNAME: guard-service
GUARD_MQTT_PASSWORD: guard-service-supersecret
GUARD_MQTT_TOPIC: guard-service

27
k8s/deployment.yaml Normal file
View File

@ -0,0 +1,27 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: guard-service
namespace: birbnetes
labels:
app: guard-service
spec:
replicas: 1
selector:
matchLabels:
app: guard-service
strategy:
type: Recreate
template:
metadata:
labels:
app: guard-service
spec:
containers:
- name: guard-service
image: registry.kmlabz.com/birbnetesgit/guard-service
envFrom:
- configMapRef:
name: guard-service
imagePullSecrets:
- name: regcred

4
requirements.txt Normal file
View File

@ -0,0 +1,4 @@
sentry_sdk
pika
marshmallow
paho-mqtt

25
src/app.py Normal file
View File

@ -0,0 +1,25 @@
#!/usr/bin/env python3
import logging
import sentry_sdk
from config import *
"""
Main entry point
"""
__author__ = "@tormakris"
__copyright__ = "Copyright 2020, Birbnetes Team"
__module_name__ = "app"
__version__text__ = "1"
if SENTRY_DSN:
sentry_sdk.init(
dsn=SENTRY_DSN,
send_default_pii=True,
release=RELEASE_ID,
environment=RELEASEMODE
)
if __name__ == "__main__":
pass

28
src/config.py Normal file
View File

@ -0,0 +1,28 @@
#!/usr/bin/env python3
import os
"""
Configuration variables
"""
__author__ = "@tormakris"
__copyright__ = "Copyright 2020, Birbnetes Team"
__module_name__ = "config"
__version__text__ = "1"
SENTRY_DSN = os.environ.get("SENTRY_DSN")
RELEASE_ID = os.environ.get("RELEASE_ID", "test")
RELEASEMODE = os.environ.get("GUARD_SERVICE_RELEASEMODE", "dev")
RABBIT_HOSTNAME = os.getenv("GUARD_RABBITMQ_HOSTNAME", "localhost")
RABBIT_USERNAME = os.getenv("GUARD_RABBITMQ_USERNAME", "guard-service")
RABBIT_PASSWORD = os.getenv("GUARD_RABBITMQ_PASSWORD", "guard-service")
RABBIT_EXCHANGE = os.getenv("GUARD_RABBITMQ_EXCHANGE", "guard-service")
MQTT_HOSTNAME = os.getenv("GUARD_MQTT_HOSTNAME", "localhost")
MQTT_USERNAME = os.getenv("GUARD_MQTT_USERNAME", "guard-service")
MQTT_PASSWORD = os.getenv("GUARD_MQTT_PASSWORD", "guard-service")
MQTT_EXCHANGE = os.getenv("GUARD_MQTT_EXCHANGE", "guard-service")