Merge pull request #46 from sartography/dev

Dev
This commit is contained in:
Aaron Louie 2020-05-14 15:35:45 -04:00 committed by GitHub
commit 477d1216ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 50 additions and 16 deletions

View File

@ -37,7 +37,7 @@ deploy:
skip_cleanup: true
on:
all_branches: true
condition: $TRAVIS_BRANCH =~ ^(testing|staging|master)$
condition: $TRAVIS_BRANCH =~ ^(dev|testing|demo|training|staging|master|rrt\/.*)$
notifications:
email:

View File

@ -1,4 +1,5 @@
import os
import re
from os import environ
basedir = os.path.abspath(os.path.dirname(__file__))
@ -6,7 +7,7 @@ basedir = os.path.abspath(os.path.dirname(__file__))
JSON_SORT_KEYS = False # CRITICAL. Do not sort the data when returning values to the front end.
NAME = "CR Connect Workflow"
CORS_ENABLED = False
CORS_ALLOW_ORIGINS = re.split(r',\s*', environ.get('CORS_ALLOW_ORIGINS', default="localhost:4200, localhost:5002"))
DEVELOPMENT = environ.get('DEVELOPMENT', default="true") == "true"
TESTING = environ.get('TESTING', default="false") == "true"
PRODUCTION = (environ.get('PRODUCTION', default="false") == "true") or (not DEVELOPMENT and not TESTING)
@ -26,6 +27,7 @@ FRONTEND_AUTH_CALLBACK = environ.get('FRONTEND_AUTH_CALLBACK', default="http://l
SWAGGER_AUTH_KEY = environ.get('SWAGGER_AUTH_KEY', default="SWAGGER")
#: Default attribute map for single signon.
SSO_LOGIN_URL = '/login'
SSO_ATTRIBUTE_MAP = {
'eppn': (False, 'eppn'), # dhf8r@virginia.edu
'uid': (True, 'uid'), # dhf8r
@ -48,7 +50,10 @@ LDAP_URL = environ.get('LDAP_URL', default="ldap.virginia.edu")
LDAP_TIMEOUT_SEC = environ.get('LDAP_TIMEOUT_SEC', default=3)
print('=== USING DEFAULT CONFIG: ===')
print('DB_HOST = ', DB_HOST)
print('CORS_ALLOW_ORIGINS = ', CORS_ALLOW_ORIGINS)
print('DEVELOPMENT = ', DEVELOPMENT)
print('TESTING = ', TESTING)
print('PRODUCTION = ', PRODUCTION)
print('PB_BASE_URL = ', PB_BASE_URL)
print('LDAP_URL = ', LDAP_URL)

View File

@ -2,7 +2,6 @@ import os
basedir = os.path.abspath(os.path.dirname(__file__))
NAME = "CR Connect Workflow"
CORS_ENABLED = False
DEVELOPMENT = True
TESTING = True
SQLALCHEMY_DATABASE_URI = "postgresql://crc_user:crc_pass@localhost:5432/crc_test"

View File

@ -2,7 +2,6 @@ import os
basedir = os.path.abspath(os.path.dirname(__file__))
NAME = "CR Connect Workflow"
CORS_ENABLED = False
DEVELOPMENT = True
TESTING = True
SQLALCHEMY_DATABASE_URI = "postgresql://postgres:@localhost:5432/crc_test"

View File

@ -4,9 +4,10 @@ import os
import connexion
from flask_cors import CORS
from flask_marshmallow import Marshmallow
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from flask_sqlalchemy import SQLAlchemy
from flask_sso import SSO
logging.basicConfig(level=logging.INFO)
connexion_app = connexion.FlaskApp(__name__)
@ -36,7 +37,12 @@ from crc import models
from crc import api
connexion_app.add_api('api.yml')
# Convert list of allowed origins to list of regexes
origins_re = [r"^https?:\/\/%s(.*)" % o.replace('.', '\.') for o in app.config['CORS_ALLOW_ORIGINS']]
logging.getLogger('flask_cors').level = logging.DEBUG
cors = CORS(connexion_app.app)
# cors = CORS(connexion_app.app, origins=origins_re)
@app.cli.command()

View File

@ -1,3 +1,5 @@
import json
import connexion
from flask import redirect, g
@ -33,6 +35,7 @@ def get_current_user():
@sso.login_handler
def sso_login(user_info):
app.logger.info("Login from Shibboleth happening. " + json.dump(user_info))
# TODO: Get redirect URL from Shibboleth request header
_handle_login(user_info)

View File

@ -1,22 +1,44 @@
#!/bin/bash
function branch_to_tag () {
if [ "$1" == "latest" ]; then echo "production"; else echo "$1" ; fi
}
function branch_to_deploy_group() {
if [[ $1 =~ ^(rrt\/.*)$ ]]; then echo "rrt"; else echo "crconnect" ; fi
}
function branch_to_deploy_stage () {
if [ "$1" == "master" ]; then echo "production"; else echo "$1" ; fi
}
REPO="sartography/cr-connect-workflow"
TAG=$(branch_to_tag "$TRAVIS_BRANCH")
DEPLOY_APP="backend"
DEPLOY_GROUP=$(branch_to_deploy_group "$TRAVIS_BRANCH")
DEPLOY_STAGE=$(branch_to_deploy_stage "$TRAVIS_BRANCH")
if [ "$DEPLOY_GROUP" == "rrt" ]; then
IFS='/' read -ra ARR <<< "$TRAVIS_BRANCH" # Split branch on '/' character
TAG=$(branch_to_tag "rrt_${ARR[1]}")
DEPLOY_STAGE=$(branch_to_deploy_stage "${ARR[1]}")
fi
DEPLOY_PATH="$DEPLOY_GROUP/$DEPLOY_STAGE/$DEPLOY_APP"
echo "REPO = $REPO"
echo "TAG = $TAG"
echo "DEPLOY_PATH = $DEPLOY_PATH"
# Build and push Docker image to Docker Hub
echo "$DOCKER_TOKEN" | docker login -u "$DOCKER_USERNAME" --password-stdin || exit 1
REPO="sartography/cr-connect-workflow"
TAG=$(if [ "$TRAVIS_BRANCH" == "master" ]; then echo "latest"; else echo "$TRAVIS_BRANCH" ; fi)
COMMIT=${TRAVIS_COMMIT::8}
docker build -f Dockerfile -t "$REPO:$COMMIT" . || exit 1
docker tag "$REPO:$COMMIT" "$REPO:$TAG" || exit 1
docker tag "$REPO:$COMMIT" "$REPO:travis-$TRAVIS_BUILD_NUMBER" || exit 1
docker build -f Dockerfile -t "$REPO:$TAG" . || exit 1
docker push "$REPO" || exit 1
# Wait for Docker Hub
echo "Publishing to Docker Hub..."
sleep 30
# Notify DC/OS that Docker image has been updated
# Notify UVA DCOS that Docker image has been updated
echo "Refreshing DC/OS..."
STAGE=$(if [ "$TRAVIS_BRANCH" == "master" ]; then echo "production"; else echo "$TRAVIS_BRANCH" ; fi)
echo "STAGE = $STAGE"
aws sqs send-message --region "$AWS_DEFAULT_REGION" --queue-url "$AWS_SQS_URL" --message-body "crconnect/$STAGE/backend" || exit 1
aws sqs send-message --region "$AWS_DEFAULT_REGION" --queue-url "$AWS_SQS_URL" --message-body "$DEPLOY_PATH" || exit 1