forked from External/greenlight
CI Updates (#386)
* Fixed issue with pushing build to dockerhub * Fixed issue with pushing build to dockerhub
This commit is contained in:
parent
6f2eef7437
commit
a0036e244b
|
@ -13,6 +13,9 @@
|
||||||
# CD_DOCKER_PASSWORD
|
# CD_DOCKER_PASSWORD
|
||||||
# A DockerHub password to be used for uploading the build.
|
# 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
|
# CD_BUILD_ALL
|
||||||
# As the build is supposed to be done only for master (for a nightly deployments) and for releases
|
# 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
|
# (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_SLUG=$1
|
||||||
export CD_REF_NAME=$2
|
export CD_REF_NAME=$2
|
||||||
export CD_COMMIT_SHA=$3
|
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
|
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
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -58,27 +64,27 @@ if [[ "$CD_REF_NAME" == *"release"* ]]; then
|
||||||
elif [ ! -z $CD_COMMIT_SHA ]; 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
|
sed -i "s/VERSION =.*/VERSION = \"$CD_REF_NAME ($(expr substr $CD_COMMIT_SHA 1 8))\"/g" config/initializers/version.rb
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Build the image
|
# Build the image
|
||||||
echo "Docker image $CD_REF_SLUG:$CD_REF_NAME is being built"
|
echo "#### Docker image $CD_DOCKER_REPO:$CD_REF_NAME is being built"
|
||||||
docker build -t $CD_REF_SLUG:$CD_REF_NAME .
|
docker build -t $CD_DOCKER_REPO:$CD_REF_NAME .
|
||||||
|
|
||||||
if [ -z "$CD_DOCKER_USERNAME" ] || [ -z "$CD_DOCKER_PASSWORD" ]; then
|
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
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Publish the image
|
# Publish the image
|
||||||
docker login -u="$CD_DOCKER_USERNAME" -p="$CD_DOCKER_PASSWORD"
|
docker login -u="$CD_DOCKER_USERNAME" -p="$CD_DOCKER_PASSWORD"
|
||||||
echo "Docker image $CD_REF_SLUG:$CD_REF_NAME is being published"
|
echo "#### Docker image $CD_DOCKER_REPO:$CD_REF_NAME is being published"
|
||||||
docker push $CD_REF_SLUG:$CD_REF_NAME
|
docker push $CD_DOCKER_REPO
|
||||||
|
|
||||||
# Publish latest and v2 if it id a release
|
# Publish latest and v2 if it id a release
|
||||||
echo $build_digest
|
|
||||||
if [[ "$CD_REF_NAME" == *"release"* ]]; then
|
if [[ "$CD_REF_NAME" == *"release"* ]]; then
|
||||||
docker_image_id=$(docker images | grep -E "^$CD_REF_SLUG.*$CD_REF_NAME" | awk -e '{print $3}')
|
docker_image_id=$(docker images | grep -E "^$CD_DOCKER_REPO.*$CD_REF_NAME" | awk -e '{print $3}')
|
||||||
docker tag $docker_image_id $CD_REF_SLUG:latest
|
docker tag $docker_image_id $CD_DOCKER_REPO:latest
|
||||||
docker push $CD_REF_SLUG:latest
|
docker push $CD_DOCKER_REPO:latest
|
||||||
docker tag $docker_image_id $CD_REF_SLUG:v2
|
docker tag $docker_image_id $CD_DOCKER_REPO:v2
|
||||||
docker push $CD_REF_SLUG:v2
|
docker push $CD_DOCKER_REPO:v2
|
||||||
fi
|
fi
|
||||||
exit 0
|
exit 0
|
||||||
|
|
|
@ -45,10 +45,10 @@ if [[ ($# == "--help") || $# == "-h" ]]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$CD_DEPLOY_SCRIPT" ]; then
|
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
|
exit 0
|
||||||
fi
|
fi
|
||||||
echo "Script for deployment: $CD_DEPLOY_SCRIPT"
|
echo "#### Script for deployment: $CD_DEPLOY_SCRIPT"
|
||||||
|
|
||||||
export CD_REF_SLUG=$1
|
export CD_REF_SLUG=$1
|
||||||
export CD_REF_NAME=$2
|
export CD_REF_NAME=$2
|
||||||
|
@ -56,20 +56,25 @@ export CD_COMMIT_SHA=$3
|
||||||
export CD_COMMIT_BEFORE_SHA=$4
|
export CD_COMMIT_BEFORE_SHA=$4
|
||||||
|
|
||||||
if [ -z $CD_REF_SLUG ]; then
|
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
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z $CD_REF_NAME ]; then
|
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
|
exit 0
|
||||||
fi
|
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
|
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
|
exit 0
|
||||||
fi
|
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
|
# The actual script should be pulled from an external repository
|
||||||
if [ ! -z $CD_GITHUB_OAUTH_TOKEN ]; then
|
if [ ! -z $CD_GITHUB_OAUTH_TOKEN ]; then
|
||||||
|
@ -80,6 +85,6 @@ else
|
||||||
curl -L $CD_DEPLOY_SCRIPT > deploy.sh
|
curl -L $CD_DEPLOY_SCRIPT > deploy.sh
|
||||||
fi
|
fi
|
||||||
chmod +x deploy.sh
|
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
|
exit 0
|
||||||
|
|
Loading…
Reference in New Issue