From b72bc07ec4ed73668866e917fb697f0d6aa1d26e Mon Sep 17 00:00:00 2001 From: Aaron Louie Date: Wed, 13 May 2020 21:15:13 -0400 Subject: [PATCH 1/2] Builds RRT Docker image. Deploys to RRT instance. --- .travis.yml | 2 +- deploy.sh | 42 ++++++++++++++++++++++++++++++++++-------- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index e99f0dfc..fba238f6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -37,7 +37,7 @@ deploy: skip_cleanup: true on: all_branches: true - condition: $TRAVIS_BRANCH =~ ^(dev|testing|demo|training|staging|master)$ + condition: $TRAVIS_BRANCH =~ ^(dev|testing|demo|training|staging|master|rrt\/.*)$ notifications: email: diff --git a/deploy.sh b/deploy.sh index 04533e71..d597f52c 100755 --- a/deploy.sh +++ b/deploy.sh @@ -1,11 +1,39 @@ #!/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") +COMMIT=${TRAVIS_COMMIT::8} + +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 "COMMIT = $COMMIT" +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 @@ -15,8 +43,6 @@ docker push "$REPO" || exit 1 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 From 1511b6fe0d1b9962cff68ef77b9254b3fa93ca4e Mon Sep 17 00:00:00 2001 From: Aaron Louie Date: Thu, 14 May 2020 08:52:05 -0400 Subject: [PATCH 2/2] Only creates Docker tag for branch --- deploy.sh | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/deploy.sh b/deploy.sh index d597f52c..a1c5da4b 100755 --- a/deploy.sh +++ b/deploy.sh @@ -14,7 +14,6 @@ function branch_to_deploy_stage () { REPO="sartography/cr-connect-workflow" TAG=$(branch_to_tag "$TRAVIS_BRANCH") -COMMIT=${TRAVIS_COMMIT::8} DEPLOY_APP="backend" DEPLOY_GROUP=$(branch_to_deploy_group "$TRAVIS_BRANCH") @@ -29,14 +28,11 @@ fi DEPLOY_PATH="$DEPLOY_GROUP/$DEPLOY_STAGE/$DEPLOY_APP" echo "REPO = $REPO" echo "TAG = $TAG" -echo "COMMIT = $COMMIT" 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 -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