diff --git a/.travis.yml b/.travis.yml index 913400c6..fba238f6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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: diff --git a/config/default.py b/config/default.py index 0e9c3a28..41a24949 100644 --- a/config/default.py +++ b/config/default.py @@ -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) + diff --git a/config/testing.py b/config/testing.py index 295156ce..823a0178 100644 --- a/config/testing.py +++ b/config/testing.py @@ -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" diff --git a/config/travis-testing.py b/config/travis-testing.py index 6231533d..b0da6538 100644 --- a/config/travis-testing.py +++ b/config/travis-testing.py @@ -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" diff --git a/crc/__init__.py b/crc/__init__.py index 25f1326e..e91b3143 100644 --- a/crc/__init__.py +++ b/crc/__init__.py @@ -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() diff --git a/crc/api/user.py b/crc/api/user.py index 411d87cb..83245d19 100644 --- a/crc/api/user.py +++ b/crc/api/user.py @@ -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) diff --git a/deploy.sh b/deploy.sh index 04533e71..a1c5da4b 100755 --- a/deploy.sh +++ b/deploy.sh @@ -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