diff --git a/scripts/image_build.sh b/scripts/image_build.sh index 546c9f45..6664df72 100755 --- a/scripts/image_build.sh +++ b/scripts/image_build.sh @@ -13,6 +13,9 @@ # CD_DOCKER_PASSWORD # A DockerHub password to be used for uploading the build. # +# CD_DOCKER_REPO +# A DockerHub repository. By default the CD_REF_SLUG is also used as the docker repo. +# # CD_BUILD_ALL # As the build is supposed to be done only for master (for a nightly deployments) and for releases # (like 'release-2.0.5' for production deployments), it is additionally required to include this @@ -46,9 +49,12 @@ fi export CD_REF_SLUG=$1 export CD_REF_NAME=$2 export CD_COMMIT_SHA=$3 +if [ -z $CD_DOCKER_REPO ]; then + export CD_DOCKER_REPO=$CD_REF_SLUG +fi if [ "$CD_REF_NAME" != "master" ] && [[ "$CD_REF_NAME" != *"release"* ]] && [ -z $CD_BUILD_ALL ];then - echo "Docker image for $CD_REF_SLUG won't be built" + echo "#### Docker image for $CD_REF_SLUG won't be built" exit 0 fi @@ -58,27 +64,27 @@ if [[ "$CD_REF_NAME" == *"release"* ]]; then elif [ ! -z $CD_COMMIT_SHA ]; then sed -i "s/VERSION =.*/VERSION = \"$CD_REF_NAME ($(expr substr $CD_COMMIT_SHA 1 8))\"/g" config/initializers/version.rb fi + # Build the image -echo "Docker image $CD_REF_SLUG:$CD_REF_NAME is being built" -docker build -t $CD_REF_SLUG:$CD_REF_NAME . +echo "#### Docker image $CD_DOCKER_REPO:$CD_REF_NAME is being built" +docker build -t $CD_DOCKER_REPO:$CD_REF_NAME . if [ -z "$CD_DOCKER_USERNAME" ] || [ -z "$CD_DOCKER_PASSWORD" ]; then - echo "Docker image for $CD_REF_SLUG can't be published because CD_DOCKER_USERNAME or CD_DOCKER_PASSWORD are missing" + echo "#### Docker image for $CD_DOCKER_REPO can't be published because CD_DOCKER_USERNAME or CD_DOCKER_PASSWORD are missing" exit 0 fi # Publish the image docker login -u="$CD_DOCKER_USERNAME" -p="$CD_DOCKER_PASSWORD" -echo "Docker image $CD_REF_SLUG:$CD_REF_NAME is being published" -docker push $CD_REF_SLUG:$CD_REF_NAME +echo "#### Docker image $CD_DOCKER_REPO:$CD_REF_NAME is being published" +docker push $CD_DOCKER_REPO # Publish latest and v2 if it id a release -echo $build_digest if [[ "$CD_REF_NAME" == *"release"* ]]; then - docker_image_id=$(docker images | grep -E "^$CD_REF_SLUG.*$CD_REF_NAME" | awk -e '{print $3}') - docker tag $docker_image_id $CD_REF_SLUG:latest - docker push $CD_REF_SLUG:latest - docker tag $docker_image_id $CD_REF_SLUG:v2 - docker push $CD_REF_SLUG:v2 + docker_image_id=$(docker images | grep -E "^$CD_DOCKER_REPO.*$CD_REF_NAME" | awk -e '{print $3}') + docker tag $docker_image_id $CD_DOCKER_REPO:latest + docker push $CD_DOCKER_REPO:latest + docker tag $docker_image_id $CD_DOCKER_REPO:v2 + docker push $CD_DOCKER_REPO:v2 fi exit 0 diff --git a/scripts/image_deploy.sh b/scripts/image_deploy.sh index 1b1c1368..13f8d910 100755 --- a/scripts/image_deploy.sh +++ b/scripts/image_deploy.sh @@ -45,10 +45,10 @@ if [[ ($# == "--help") || $# == "-h" ]]; then fi if [ -z "$CD_DEPLOY_SCRIPT" ]; then - echo "Script for deployment is not defined, it has to be defined as an ENV variable. [e.g. CD_DEPLOY_SCRIPT=https://example.com/scripts/deploy.sh]" + echo "#### Script for deployment is not defined, it has to be defined as an ENV variable. [e.g. CD_DEPLOY_SCRIPT=https://example.com/scripts/deploy.sh]" exit 0 fi -echo "Script for deployment: $CD_DEPLOY_SCRIPT" +echo "#### Script for deployment: $CD_DEPLOY_SCRIPT" export CD_REF_SLUG=$1 export CD_REF_NAME=$2 @@ -56,20 +56,25 @@ export CD_COMMIT_SHA=$3 export CD_COMMIT_BEFORE_SHA=$4 if [ -z $CD_REF_SLUG ]; then - echo "Repository not included, it should have been passed as an argument. [e.g. bigbluebutton/greenlight]" + echo "#### Repository not included, it should have been passed as an argument. [e.g. bigbluebutton/greenlight]" exit 0 fi if [ -z $CD_REF_NAME ]; then - echo "Neither branch nor tag were included, the name should have been passed as an argument. [e.g. master|release-2.0.5]" + echo "#### Neither branch nor tag were included, the name should have been passed as an argument. [e.g. master|release-2.0.5]" exit 0 fi +if [ -z $CD_DOCKER_REPO ]; then + export CD_DOCKER_REPO=$CD_REF_SLUG +fi + if [ "$CD_REF_NAME" != "master" ] && [[ "$CD_REF_NAME" != *"release"* ]] && [ -z $CD_DEPLOY_ALL ];then - echo "Docker image for $CD_REF_SLUG won't be deployed. The conditions for running this build were not met." + echo "#### Docker image for $CD_DOCKER_REPO won't be deployed. The conditions for running this build were not met." exit 0 fi -echo "Docker image $CD_REF_SLUG:$CD_REF_NAME is being deployed." +echo "#### Docker image $CD_DOCKER_REPO:$CD_REF_NAME is being deployed" + # The actual script should be pulled from an external repository if [ ! -z $CD_GITHUB_OAUTH_TOKEN ]; then @@ -80,6 +85,6 @@ else curl -L $CD_DEPLOY_SCRIPT > deploy.sh fi chmod +x deploy.sh -./deploy.sh $CD_REF_SLUG $CD_REF_NAME $CD_COMMIT_SHA $CD_COMMIT_BEFORE_SHA +./deploy.sh $CD_DOCKER_REPO $CD_REF_NAME $CD_COMMIT_SHA $CD_COMMIT_BEFORE_SHA exit 0