GRN2-159: Changed the inception of the version tag (#573)

This commit is contained in:
Jesus Federico 2019-06-21 09:36:52 -04:00 committed by GitHub
parent 790a0365c5
commit f5c33e9306
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 14 deletions

View File

@ -20,7 +20,7 @@ jobs:
- stage: build - stage: build
name: build docker image name: build docker image
script: bash scripts/image_build.sh $TRAVIS_REPO_SLUG $TRAVIS_BRANCH $TRAVIS_COMMIT script: bash scripts/image_build.sh $TRAVIS_REPO_SLUG
if: env(CD_BUILD_IGNORE) IS NOT present AND type NOT IN (pull_request) AND env(CD_DOCKER_USERNAME) IS present AND env(CD_DOCKER_PASSWORD) IS present if: env(CD_BUILD_IGNORE) IS NOT present AND type NOT IN (pull_request) AND env(CD_DOCKER_USERNAME) IS present AND env(CD_DOCKER_PASSWORD) IS present
notifications: notifications:

View File

@ -11,6 +11,8 @@ RUN mkdir -p $RAILS_ROOT
WORKDIR $RAILS_ROOT WORKDIR $RAILS_ROOT
# Set environment variables. # Set environment variables.
ARG version_code
ENV VERSION_CODE=$version_code
ENV RAILS_ENV production ENV RAILS_ENV production
# Adding project files. # Adding project files.

View File

@ -2,6 +2,6 @@
module Greenlight module Greenlight
class Application class Application
VERSION = "2" VERSION = ENV["VERSION_CODE"] || "2"
end end
end end

View File

@ -23,19 +23,17 @@
# as part of the development process. # as part of the development process.
# #
echo "v2019022601"
display_usage() { display_usage() {
echo "This script should be used as part of a CI strategy." echo "This script should be used as part of a CI strategy."
echo -e "Usage:\n build_image.sh [ARGUMENTS]" echo -e "Usage:\n build_image.sh [ARGUMENTS]"
echo -e "\nMandatory arguments \n" echo -e "\nMandatory arguments \n"
echo -e " repo_slug The git repository (e.g. bigbluebutton/greenlight)" echo -e " repo_slug The git repository (e.g. bigbluebutton/greenlight)"
echo -e "\nOptional arguments \n"
echo -e " branch | tag The branch (e.g. master | release-2.0.5)" echo -e " branch | tag The branch (e.g. master | release-2.0.5)"
echo -e " commit_sha The sha for the current commit (e.g. 750615dd479c23c8873502d45158b10812ea3274)"
} }
# if less than two arguments supplied, display usage # if less than two arguments supplied, display usage
if [ $# -le 1 ]; then if [ $# -le 0 ]; then
display_usage display_usage
exit 1 exit 1
fi fi
@ -48,13 +46,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 if [ -z $CD_REF_NAME ]; then
if [ -z $CD_DOCKER_REPO ]; then export CD_REF_NAME=$(git branch | grep \* | cut -d ' ' -f2)
export CD_DOCKER_REPO=$CD_REF_SLUG
fi fi
if [ "$CD_REF_NAME" != "master" ] && [[ "$CD_REF_NAME" != *"release"* ]] && ( [ -z "$CD_BUILD_ALL" ] || [ "$CD_BUILD_ALL" != "true" ] ); then if [ "$CD_REF_NAME" != "master" ] && [[ "$CD_REF_NAME" != *"release"* ]] && ( [ -z "$CD_BUILD_ALL" ] || [ "$CD_BUILD_ALL" != "true" ] ); then
echo "#### Docker image for $CD_REF_SLUG won't be built" echo "#### Docker image for $CD_REF_SLUG:$CD_REF_NAME won't be built"
exit 0 exit 0
fi fi
@ -62,14 +59,17 @@ fi
sed -i "/^group :production do/a\ \ gem 'sqlite3', '~> 1.3.6'" Gemfile sed -i "/^group :production do/a\ \ gem 'sqlite3', '~> 1.3.6'" Gemfile
# Set the version tag when it is a release or the commit sha was included. # Set the version tag when it is a release or the commit sha was included.
if [[ "$CD_REF_NAME" == *"release"* ]]; then if [[ "$CD_REF_NAME" == *"release"* ]]; then
sed -i "s/VERSION =.*/VERSION = \"${CD_REF_NAME:8}\"/g" config/initializers/version.rb export CD_VERSION_CODE=${CD_REF_NAME:8}
elif [ ! -z $CD_COMMIT_SHA ]; then else
sed -i "s/VERSION =.*/VERSION = \"$CD_REF_NAME ($(expr substr $CD_COMMIT_SHA 1 8))\"/g" config/initializers/version.rb export CD_VERSION_CODE="$CD_REF_NAME ($(expr substr $(git rev-parse HEAD) 1 7))"
fi fi
# Build the image # Build the image
if [ -z $CD_DOCKER_REPO ]; then
export CD_DOCKER_REPO=$CD_REF_SLUG
fi
echo "#### Docker image $CD_DOCKER_REPO:$CD_REF_NAME is being built" echo "#### Docker image $CD_DOCKER_REPO:$CD_REF_NAME is being built"
docker build -t $CD_DOCKER_REPO:$CD_REF_NAME . docker build --build-arg version_code=${CD_VERSION_CODE} -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_DOCKER_REPO can't be published because CD_DOCKER_USERNAME or CD_DOCKER_PASSWORD are missing (Ignore this warning if running outside a CD/CI environment)" echo "#### Docker image for $CD_DOCKER_REPO can't be published because CD_DOCKER_USERNAME or CD_DOCKER_PASSWORD are missing (Ignore this warning if running outside a CD/CI environment)"