From aca5cd1621ee5b5fa74f5e81f2fb5a2c217a83c5 Mon Sep 17 00:00:00 2001 From: Aaron Louie Date: Thu, 7 May 2020 17:03:57 -0400 Subject: [PATCH] Tags Docker image with branch, commit, and Travis build number. Deploys to appropriate DC/OS stage after successful Docker push. --- .travis.yml | 3 ++- deploy.sh | 23 ++++++++++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1e27130..36add64 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,7 +26,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 bb06229..527f6d6 100755 --- a/deploy.sh +++ b/deploy.sh @@ -1,9 +1,22 @@ #!/bin/bash # Build and push Docker image to Docker Hub -echo "$DOCKER_TOKEN" | docker login -u "$DOCKER_USERNAME" --password-stdin -docker build --no-cache -t sartography/protocol-builder-mock:latest . || exit 1; -docker push sartography/protocol-builder-mock:latest || exit 1; +echo "$DOCKER_TOKEN" | docker login -u "$DOCKER_USERNAME" --password-stdin || exit 1 +REPO="sartography/protocol-builder-mock" +TAG=$(if [ "$TRAVIS_BRANCH" == "master" ]; then echo "latest"; else echo "$TRAVIS_BRANCH" ; fi) +COMMIT=${TRAVIS_COMMIT::8} -# Notify UVA DCOS that Docker image has been updated -aws sqs send-message --queue-url 'https://queue.amazonaws.com/474683445819/dcos-refresh' --message-body 'crconnect/pb' || 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 push "$REPO" || exit 1 + +# Wait for Docker Hub +echo "Publishing to Docker Hub..." +sleep 30 + +# Notify DC/OS 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/protocol-builder-mock" || exit 1