Commit 3ff811f0 authored by Jonas Waeber's avatar Jonas Waeber
Browse files

Fix gunicorn config

Remove config file
Remove flake8 test
Remove unused dependencies
parent d95b1043
Pipeline #37210 passed with stage
in 53 seconds
......@@ -7,13 +7,4 @@ include:
stages:
- test
- publish
test:
stage: test
image: python:3.8
before_script:
- pip install pip --upgrade
- pip install -r requirements.txt
script:
- flake8 ./autodeploy_service_app
- publish
\ No newline at end of file
......@@ -10,20 +10,17 @@ ENTRYPOINT ["gunicorn"]
CMD [ "wsgi:app", "--config", "/configs/gunicorn.conf.py"]
RUN cd /usr/bin \
&& wget -q https://storage.googleapis.com/kubernetes-release/release/${K8S_VERSION}/bin/linux/amd64/kubectl \
&& chmod +x ./kubectl \
&& wget -q https://get.helm.sh/helm-${HELM_VERSION}-linux-amd64.tar.gz \
&& tar -xvzf helm-${HELM_VERSION}-linux-amd64.tar.gz \
&& mv linux-amd64/helm helm \
&& rm -rf linux-amd64
&& wget -q https://storage.googleapis.com/kubernetes-release/release/${K8S_VERSION}/bin/linux/amd64/kubectl \
&& chmod +x ./kubectl \
&& wget -q https://get.helm.sh/helm-${HELM_VERSION}-linux-amd64.tar.gz \
&& tar -xvzf helm-${HELM_VERSION}-linux-amd64.tar.gz \
&& mv linux-amd64/helm helm \
&& rm -rf linux-amd64
WORKDIR /
ADD setup.py /
RUN mkdir autodeploy_service_app \
&& pip install -e .
&& pip install --no-cache-dir -e .
WORKDIR /autodeploy_service_app
ADD requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
ADD autodeploy_service_app .
from flask import Flask
from autodeploy_service_app import configuration
app = Flask(__name__)
app.config.from_object(configuration)
app = Flask(__name__)
\ No newline at end of file
......@@ -5,13 +5,14 @@ from re import match
from shutil import rmtree
from tempfile import mkdtemp
from flask import request as flaskRequest
from flask import request as flask_request
from flask.views import MethodView
from autodeploy_service_app.app import app
class AutoDeploy(MethodView):
def post(self):
'''
Deploy on k8s
......@@ -48,7 +49,7 @@ class AutoDeploy(MethodView):
output = []
try:
headers = flaskRequest.headers
headers = flask_request.headers
secure_token = getenv('SECURE_TOKEN')
if secure_token and not headers.get('X-Gitlab-Token'):
msg = 'Request does not have an X-Gitlab-Token in headers'
......@@ -58,7 +59,7 @@ class AutoDeploy(MethodView):
msg = 'Request does not have a valid X-Gitlab-Token in headers'
app.logger.warning(msg)
return msg, 403
body = json.loads(flaskRequest.data.decode('utf-8'))
body = json.loads(flask_request.data.decode('utf-8'))
tag = ''
branch = ''
if body['object_attributes']['tag']:
......
......@@ -3,34 +3,16 @@ from os import path, environ
from flasgger import Swagger
from flask import send_from_directory, redirect
from flask.logging import default_handler
from kubernetes import config
from kubernetes.config import ConfigException
from autodeploy_service_app.app import app
from autodeploy_service_app.autodeploy import AutoDeploy
# TODO : maybe take that to a configuration (development vs pod running in
# k8s cluster)
try:
# to be used when inside a kubernetes cluster
config.load_incluster_config()
except ConfigException:
try:
# use .kube directory
# for local development
config.load_kube_config()
except ConfigException:
app.logger.error('No kubernetes cluster defined')
environ['HELM_EXPERIMENTAL_OCI'] = '1'
# If app is started via gunicorn
if __name__ != '__main__':
gunicorn_logger = logging.getLogger('gunicorn.error')
app.logger.handlers = gunicorn_logger.handlers
app.logger.setLevel(gunicorn_logger.level)
app.logger.removeHandler(default_handler)
app.logger = gunicorn_logger
app.logger.info('Starting production server')
app.config['SWAGGER'] = {
......
......@@ -2,6 +2,26 @@ bind = "0.0.0.0:5000"
reload = True
accesslog = "/dev/stdout"
access_log_format = '%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"'
disable_redirect_access_to_syslog = True
errorlog = "/dev/stderr"
loglevel = 'debug'
workers = 3
loglevel = 'info'
workers = 1
logconfig_dict = dict(
version=1,
disable_existing_loggers=True,
loggers={
"gunicorn.error": {
"level": "INFO",
"handlers": ["error_console"],
"propagate": False,
"qualname": "gunicorn.error"
}
},
formatters={
"generic": {
"format": "[%(levelname)s] [%(name)s] %(message)s",
"datefmt": "[%Y-%m-%d %H:%M:%S %z]",
"class": "logging.Formatter"
}
}
)
......@@ -2,6 +2,26 @@ bind = "0.0.0.0:5000"
reload = True
accesslog = "/dev/stdout"
access_log_format = '%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"'
disable_redirect_access_to_syslog = True
errorlog = "/dev/stderr"
loglevel = 'debug'
workers = 1
logconfig_dict = dict(
version=1,
disable_existing_loggers=True,
loggers={
"gunicorn.error": {
"level": "DEBUG",
"handlers": ["error_console"],
"propagate": False,
"qualname": "gunicorn.error"
}
},
formatters={
"generic": {
"format": "[%(levelname)s] [%(name)s] %(message)s",
"datefmt": "[%Y-%m-%d %H:%M:%S %z]",
"class": "logging.Formatter"
}
}
)
......@@ -5,6 +5,6 @@ setup(
packages=["autodeploy_service_app"],
include_package_data=True,
install_requires=[
"flask",
"flask", "gunicorn", "flasgger"
],
)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment