From 0f826d67bb4a17ab093d64f9971921534b7dd710 Mon Sep 17 00:00:00 2001 From: Aaron Louie Date: Wed, 13 May 2020 20:58:18 -0400 Subject: [PATCH 1/3] Builds RRT Docker image. Deploys to RRT instance. --- .travis.yml | 2 +- deploy.sh | 38 ++++++++++++++++++++++++++++++++------ 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5a8ebe0..6e9b25d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,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 eb95f96..4d2812e 100644 --- a/deploy.sh +++ b/deploy.sh @@ -1,12 +1,38 @@ #!/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-db" +DEPLOY_APP="db" +DEPLOY_GROUP=$(branch_to_deploy_group "$TRAVIS_BRANCH") +DEPLOY_STAGE=$(branch_to_deploy_stage "$TRAVIS_BRANCH") +DEPLOY_PATH="$DEPLOY_GROUP/$DEPLOY_STAGE/$DEPLOY_APP" +TAG=$(branch_to_tag "$TRAVIS_BRANCH") +COMMIT=${TRAVIS_COMMIT::8} + +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 + +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 -APP="db" -REPO="sartography/cr-connect-$APP" -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 @@ -18,4 +44,4 @@ sleep 30 # Notify UVA DCOS that Docker image has been updated echo "Refreshing DC/OS..." -aws sqs send-message --region "$AWS_DEFAULT_REGION" --queue-url "$AWS_SQS_URL" --message-body "crconnect/$TRAVIS_BRANCH/$APP" || exit 1 +aws sqs send-message --region "$AWS_DEFAULT_REGION" --queue-url "$AWS_SQS_URL" --message-body "$DEPLOY_PATH" || exit 1 From be325514f3af3718da01d0dcee8f745ed34ff39b Mon Sep 17 00:00:00 2001 From: Aaron Louie Date: Wed, 13 May 2020 21:02:07 -0400 Subject: [PATCH 2/3] Constructs deploy path after deploy stage name is defined --- deploy.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/deploy.sh b/deploy.sh index 4d2812e..ffef637 100644 --- a/deploy.sh +++ b/deploy.sh @@ -13,12 +13,12 @@ function branch_to_deploy_stage () { } REPO="sartography/cr-connect-db" +TAG=$(branch_to_tag "$TRAVIS_BRANCH") +COMMIT=${TRAVIS_COMMIT::8} + DEPLOY_APP="db" DEPLOY_GROUP=$(branch_to_deploy_group "$TRAVIS_BRANCH") DEPLOY_STAGE=$(branch_to_deploy_stage "$TRAVIS_BRANCH") -DEPLOY_PATH="$DEPLOY_GROUP/$DEPLOY_STAGE/$DEPLOY_APP" -TAG=$(branch_to_tag "$TRAVIS_BRANCH") -COMMIT=${TRAVIS_COMMIT::8} if [ "$DEPLOY_GROUP" == "rrt" ]; then IFS='/' read -ra ARR <<< "$TRAVIS_BRANCH" # Split branch on '/' character @@ -26,6 +26,7 @@ if [ "$DEPLOY_GROUP" == "rrt" ]; then 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" From fa55806cdc3180016e4c85f20bf821e4e5b8cf0d Mon Sep 17 00:00:00 2001 From: Aaron Louie Date: Thu, 14 May 2020 08:52:59 -0400 Subject: [PATCH 3/3] 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 ffef637..f47ec5b 100644 --- a/deploy.sh +++ b/deploy.sh @@ -14,7 +14,6 @@ function branch_to_deploy_stage () { REPO="sartography/cr-connect-db" TAG=$(branch_to_tag "$TRAVIS_BRANCH") -COMMIT=${TRAVIS_COMMIT::8} DEPLOY_APP="db" 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