Commit 1039b8b5 authored by Matthias's avatar Matthias
Browse files

add files and folders

parents
FROM python:3.8
RUN mkdir /me_test_app
WORKDIR /me_test_app
ADD me_test_app /me_test_app/
ADD requirements.txt /me_test_app/
RUN mkdir /kubectl
WORKDIR /me_test_app/kubectl
#install kubectl so that helm can work in the docker container
RUN wget https://storage.googleapis.com/kubernetes-release/release/v1.16.2/bin/linux/amd64/kubectl && chmod +x ./kubectl
ENV PATH /me_test_app/kubectl:$PATH
WORKDIR /me_test_app
#install helm
RUN wget https://get.helm.sh/helm-v3.2.1-linux-amd64.tar.gz && tar -xvzf helm-v3.2.1-linux-amd64.tar.gz && mv linux-amd64 helm
ENV PATH /me_test_app/helm:$PATH
RUN ./pull-charts.sh
RUN pip install -r requirements.txt
WORKDIR /
ADD setup.py /
RUN pip install -e .
ENV FLASK_APP me_test_app
ENV FLASK_ENV development
EXPOSE 5000
ENTRYPOINT ["python"]
CMD ["/me_test_app/main.py"]
This diff is collapsed.
apiVersion: apps/v1
kind: Deployment
metadata:
name: me-test-deployment
namespace: memobase
spec:
selector:
matchLabels:
app: me-test-app
replicas: 1
template:
metadata:
labels:
app: me-test-app
tier: web
spec:
serviceAccountName: me-test-service-account #to be able to manage other pods inside the cluster
containers:
- name: me-test-container
image: cr.gitlab.switch.ch/memoriav/memobase-2020/services/me-test:latest
ports:
- containerPort: 5000
name: http
protocol: TCP
imagePullPolicy: Always
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
namespace: memobase
name: memobase-me-test-ingress
annotations:
cert-manager.io/cluster-issuer: letsencrypt-prod
nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
tls:
- hosts:
- me-test.memobase.k8s.unibas.ch
secretName: me-test.memobase.k8s.unibas.ch-tls
rules:
- host: me-test.memobase.k8s.unibas.ch
http:
paths:
- path: /
backend:
serviceName: me-test-service
servicePort: 5000
\ No newline at end of file
#create service account so that this pod can manage the other pods
apiVersion: v1
kind: ServiceAccount
metadata:
name: me-test-service-account
---
#necessary role so that the service account can access the kubernetes api to list pods
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
namespace: memobase
name: me-test-roles
rules:
- apiGroups: ["", "batch"] # "" indicates the core API group
resources: ["pods", "secrets", "configmaps", "jobs"]
verbs: ["get", "list", "create", "watch", "create", "update", "patch", "delete"]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: me-test-roles
namespace: memobase
subjects:
- kind: ServiceAccount
name: me-test-service-account
namespace: memobase
roleRef:
kind: Role
name: me-test-roles
apiGroup: rbac.authorization.k8s.io
\ No newline at end of file
apiVersion: v1
kind: Service
metadata:
namespace: memobase
name: me-test
labels:
app: me-test-app
spec:
ports:
- port: 5000
selector:
app: me-test-app
tier: web
clusterIP: None
\ No newline at end of file
from flask import Flask, send_from_directory, redirect
from flask_restful import Api
from flasgger import Swagger
from kubernetes import config
from me_test_app.resources.MeTest import MeTest
import me_test_app.configuration
import os
def create_app(test_config=None):
app = Flask(__name__)
app.config.from_object(me_test_app.configuration)
api = Api(app)
app.config['SWAGGER'] = {
'title': 'me-test',
'version': 'dev',
'uiversion': 3,
'termsOfService': 'http://memobase.ch/de/disclaimer',
'description': 'test app',
'contact': {
'name': 'UB Basel',
'url': 'https://ub.unibas.ch',
'email': 'swissbib-ub@unibas.ch'},
'favicon': '/favicon.ico'}
Swagger(app)
@app.route("/")
def home():
return redirect("/apidocs")
@app.route('/favicon.ico')
def favicon():
return send_from_directory(
os.path.join(
app.root_path,
'assets'),
'favicon.ico',
mimetype='image/vnd.microsoft.icon')
api.add_resource(MeTest, '/v1/metest')
# 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 BaseException:
try:
# use .kube directory
# for local development
config.load_kube_config()
except BaseException:
app.logger.error("No kubernetes cluster defined")
return app
NAMESPACE = "memobase"
DRUPAL_API_URL = "https://mb-wf1.memobase.unibas.ch/jsonapi"
from me_test_service_app import create_app
if __name__ == "__main__":
app = create_app()
app.run(host='0.0.0.0', debug=True)
from flask_restful import Resource
from flask import request as flaskRequest
class MeTest(Resource):
def post(self):
"""
just a dummy test app
---
tags:
- test
responses:
200:
description: always good...
"""
return "all good!", 200
from datetime import timezone
def generate_helm_name(process_id, job_name):
return process_id + '-' + job_name
def get_job_info(job):
""""
job is a Kubernetes V1Job
"""
utc_start_time = job.status.start_time
local_start_time = utc_start_time.replace(tzinfo=timezone.utc).astimezone(tz=None)
status = 'Unknown'
if job.status.failed:
status = 'Failed'
elif (job.status.active):
status = 'Running'
return {
"status": status,
"started": local_start_time.strftime("%m/%d/%Y, %H:%M:%S")
}
from setuptools import setup
setup(
name='autodeploy_service_app',
packages=['autodeploy_service_app'],
include_package_data=True,
install_requires=[
'flask',
],
)
[flake8]
#ignore = W503,E501,E203
max-line-length = 100
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