From 827e840103231e09e0451020f033ddd58cfcceae Mon Sep 17 00:00:00 2001 From: Aaron Louie Date: Thu, 7 May 2020 10:15:14 -0400 Subject: [PATCH 1/2] Builds and deploys Docker image if build passes on testing, staging, or master branches --- .travis.yml | 6 +++++- deploy.sh | 13 +++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index e947cddf..ca5f11f2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,6 +24,9 @@ install: env: - PB_BASE_URL='http://workflow.sartography.com:5001/pb/' + global: + - COMMIT=${TRAVIS_COMMIT::8} + script: - pipenv run coverage run -m pytest - pipenv run coverage xml -i @@ -36,7 +39,8 @@ deploy: script: bash deploy.sh skip_cleanup: true on: - branch: master + all_branches: true + condition: $TRAVIS_BRANCH =~ ^(testing|staging|master)$ notifications: email: diff --git a/deploy.sh b/deploy.sh index a40d2d82..aa52808d 100755 --- a/deploy.sh +++ b/deploy.sh @@ -2,13 +2,18 @@ # Build and push Docker image to Docker Hub echo "$DOCKER_TOKEN" | docker login -u "$DOCKER_USERNAME" --password-stdin -docker build --no-cache -t sartography/cr-connect-backend:latest . || exit 1; -docker push sartography/cr-connect-backend:latest || exit 1; +REPO="sartography/cr-connect-workflow" +TAG=$(if [ "$TRAVIS_BRANCH" == "master" ]; then echo "latest"; else echo "$TRAVIS_BRANCH" ; fi) +docker build -f Dockerfile -t "$REPO:$COMMIT" . +docker tag "$REPO:$COMMIT" "$REPO:$TAG" +docker tag "$REPO:$COMMIT" "$REPO:travis-$TRAVIS_BUILD_NUMBER" +docker push "$REPO" # Wait for Docker Hub echo "Publishing to Docker Hub..." sleep 30 -# Notify UVA DCOS that Docker image has been updated +# Notify DC/OS that Docker image has been updated echo "Refreshing DC/OS..." -aws sqs send-message --queue-url 'https://queue.amazonaws.com/474683445819/dcos-refresh' --message-body 'crconnect/backend' || exit 1; +STAGE=$(if [ "$TRAVIS_BRANCH" == "master" ]; then echo "production"; else echo "$TRAVIS_BRANCH" ; fi) +aws sqs send-message --region "$AWS_DEFAULT_REGION" --queue-url "$AWS_SQS_URL" --message-body "crconnect/$STAGE/backend" From 26251a199f818bb5c76cd3e2018f65dcd9986949 Mon Sep 17 00:00:00 2001 From: Aaron Louie Date: Thu, 7 May 2020 10:25:06 -0400 Subject: [PATCH 2/2] Moves commit variable into deploy script --- .travis.yml | 3 --- deploy.sh | 1 + 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index ca5f11f2..913400c6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,9 +24,6 @@ install: env: - PB_BASE_URL='http://workflow.sartography.com:5001/pb/' - global: - - COMMIT=${TRAVIS_COMMIT::8} - script: - pipenv run coverage run -m pytest - pipenv run coverage xml -i diff --git a/deploy.sh b/deploy.sh index aa52808d..86845e93 100755 --- a/deploy.sh +++ b/deploy.sh @@ -4,6 +4,7 @@ echo "$DOCKER_TOKEN" | docker login -u "$DOCKER_USERNAME" --password-stdin 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" . docker tag "$REPO:$COMMIT" "$REPO:$TAG" docker tag "$REPO:$COMMIT" "$REPO:travis-$TRAVIS_BUILD_NUMBER"