Update application root and add deploy script

This commit is contained in:
Troy Dai 2018-05-11 16:00:32 -07:00
Родитель 8372e441c5
Коммит 5ecafa412e
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 9608535492BEDAC8
2 изменённых файлов: 101 добавлений и 11 удалений

Просмотреть файл

@ -5,11 +5,13 @@ import datetime
from flask import Flask, render_template, redirect, url_for, request, session
from flask_login import LoginManager, login_required, login_user, logout_user
from .models import User
from .auth import get_authorization_url, acquire_token, get_logout_uri
from app.models import User
from app.auth import get_authorization_url, acquire_token, get_logout_uri
# pylint: disable=invalid-name
APP_ROOT = "/monitor"
app = Flask(__name__)
app.secret_key = os.environ.get('SECRET_KEY', 'local_test')
@ -35,18 +37,18 @@ def unauthorized_handler():
return redirect(url_for('login', requiest_uri=request.path))
@app.route('/login')
@app.route(APP_ROOT + '/login')
def login():
return render_template('login.html', auth_link=get_authorization_url())
@app.route('/logout')
@app.route(APP_ROOT + '/logout')
def logout():
logout_user()
return redirect(get_logout_uri())
@app.route('/login_callback', methods=['GET'])
@app.route(APP_ROOT + '/login_callback', methods=['GET'])
def login_callback():
code, state = request.args['code'], request.args['state']
token = acquire_token(code)
@ -59,16 +61,12 @@ def login_callback():
return redirect(state)
@app.route('/')
@app.route(APP_ROOT)
@login_required
def index():
return render_template('index.html')
@app.route('/help', methods=['GET'])
@app.route(APP_ROOT + '/help', methods=['GET'])
def help_page():
return render_template('help.html')
if __name__ == '__main__':
app.run()

92
scripts/deploy Executable file
Просмотреть файл

@ -0,0 +1,92 @@
#!/usr/bin/env bash
build=$1
branch=$2
echo "apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: monitor
labels:
system: a01
group: base
spec:
replicas: 2
template:
metadata:
labels:
app: monitor
spec:
containers:
- name: main
image: adxautomationbase.azurecr.io/monitor:$branch-$build
ports:
- containerPort: 80
env:
- name: SECRET_KEY
valueFrom:
secretKeyRef:
name: monitor-secrets
key: secret_key
- name: AZURE_CLIENT_ID
valueFrom:
secretKeyRef:
name: monitor-secrets
key: client_id
- name: AZURE_CLIENT_TENANT
valueFrom:
secretKeyRef:
name: monitor-secrets
key: client_tenant
- name: AZURE_CLIENT_SECRET
valueFrom:
secretKeyRef:
name: monitor-secrets
key: client_secret
- name: AZURE_CLIENT_RESOURCE
valueFrom:
secretKeyRef:
name: monitor-secrets
key: client_resource
imagePullSecrets:
- name: monitor-registry
---
apiVersion: v1
kind: Service
metadata:
name: monitor
labels:
system: a01
group: base
spec:
ports:
- port: 80
selector:
app: monitor
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: store-ingress
labels:
system: a01
group: base
annotations:
kubernetes.io/ingress.class: \"nginx\"
kubernetes.io/tls-acme: "true"
ingress.kubernetes.io/rewrite-target: /
spec:
tls:
- secretName: store-tls
hosts:
- secondapi.azclitest.com
rules:
- host: secondapi.azclitest.com
http:
paths:
- path: /monitor
backend:
serviceName: monitor
servicePort: 80
" | kubectl apply --namespace a01-monitor-$branch -f -