Summary Table

Categories Total Count
PII 0
URL 0
DNS 0
EKL 0
IP 0
PORT 0
VsID 0
CF 0
AI 0
VPD 0
PL 0
Other 0

File Content

#!/bin/bash

printf "\n\n\n\n**** RUNNING BUILD ********************\n\n"
APPDATE=`date "+%B %d, %Y"`

if [ -z $APP_NAME ] || [ -z $APP_VERSION ]; then
source app.env
fi

if [ -z $BUILD_NUMBER ]; then
BUILD_NUMBER="SNAPSHOT"
fi

if [ -z $JOB_NAME ]; then
JOB_NAME=$APP_NAME
fi

if [ -z $STAGING_DIR ]; then
printf "STAGING_DIR not specified, defaulting to dist/\n";
STAGING_DIR="dist"
else
STAGING_DIR=$(echo ${STAGING_DIR} | sed 's:/*$::')
printf "Using staging directory '$STAGING_DIR'\n";
fi

if [ -d $STAGING_DIR ] && [ $STAGING_DIR != "." ]; then
printf "Cleaning staging directory...\n"
rm -r $STAGING_DIR
else
printf "No staging directory to be cleaned at ${STAGING_DIR}\n"
fi

if [ -z $BUILD_DIR ]; then
printf "Artifact directory 'BUILD_DIR' not specified, defaulting to build/\n";
BUILD_DIR="build"
else
BUILD_DIR=$(echo ${BUILD_DIR} | sed 's:/*$::')
printf "Using build directory '$BUILD_DIR'\n";
fi

if [ -d $BUILD_DIR ] && [ $BUILD_DIR != "." ]; then
printf "Cleaning build directory...\n"
rm -r $BUILD_DIR
else
printf "No build directory to be cleaned at ${BUILD_DIR}\n"
fi

if [ -z ${DTR_PREFIX// }${DTR_ORG// } ]; then
printf "Both DTR_PREFIX and DTR_ORG not set, pointing Docker images to dev\n"
DTR_PREFIX=dev
fi

if [ -f $JOB_NAME*.tar.gz ]; then
printf "Cleaning old build artifacts from workspace root\n"
rm $JOB_NAME*.tar.gz
fi

cp package.json package.json.bak
./packageBuilder.js $APP_NAME $APP_VERSION

# Dependency Check
printf "\n\n**** Mandatory: Dependency Checks ********************\n"

# Determine where the script is located
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
# if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
done
scriptPath="$( cd -P "$( dirname "$SOURCE" )" && pwd )"

# Set GEM_HOME location to local, project directory
WORKSPACE="$scriptPath"
export GEM_HOME=$WORKSPACE/.gems
export GEM_PATH=$GEM_HOME:$GEM_PATH
export PATH=$GEM_HOME/bin:$WORKSPACE/bin:$PATH

npm config set registry http://registry.npmjs.org/
npm config set strict-ssl false

#npm config set ca null
export GIT_SSL_NO_VERIFY=true
export NODE_TLS_REJECT_UNAUTHORIZED=0

npm install || { echo "FATAL: Failed on 'npm install'";
rm package.json
mv package.json.bak package.json
exit 1;
}

gem install bundler || { echo "FATAL: Failed on 'gem install bundler'";
# restore the changed files
rm package.json
mv package.json.bak package.json
exit 1;
}

bundle update || { echo "FATAL: Failed on 'bundle update'";
# restore the changed files
rm package.json
mv package.json.bak package.json
exit 1;
}

bundle install || { echo "FATAL: Failed on 'bundle install'";
# restore the changed files
rm package.json
mv package.json.bak package.json
exit 1;
}

if [ "$BUILD_NUMBER" = "SNAPSHOT" ]; then
grunt build:dev --baseUrl="../.." --contextVersion="${CONTEXT_VERSION}" || { echo "FATAL: Failed on 'grunt build:dev'";
# restore the changed files
rm package.json
mv package.json.bak package.json
exit 1;
}
else
grunt build:dist --baseUrl="../.." --contextVersion="${CONTEXT_VERSION}" || { echo "FATAL: Failed on 'grunt build:dist'";
# restore the changed files
rm package.json
mv package.json.bak package.json
exit 1;
}
fi

# Unit Tests

if [ ! $# -eq 0 ] && [ "$1" = "skipTests" ]; then
printf "\n\n**** Skipping: Testing ********************\n"
else
printf "\n\n**** Mandatory: Testing ********************\n**** To Skip tests pass 'skipTests' as an argument ********************\n"
grunt karma || { echo "FATAL: Failed on 'grunt karma'";
# restore the changed files
rm package.json
mv package.json.bak package.json
exit 1;
}
fi

# Build Artifact Production
printf "\n\n**** Optional: Producing Build Artifacts ********************\n\n"

# remove temp package.json and replace it with our backup
rm package.json
mv package.json.bak package.json

# copy docker files
mkdir -p $BUILD_DIR
mkdir -p $STAGING_DIR

if [ $STAGING_DIR != "dist" ]; then
# Need to move the grunt output from dist (where grunt puts it) to staging
# This is a hack, ideally grunt just builds to the right directory
cp -R dist/* $STAGING_DIR
fi

cp app.yml $STAGING_DIR
cp app.env $STAGING_DIR
cp .dockerignore $STAGING_DIR
cp Dockerfile $STAGING_DIR
cp docker-compose.yml $STAGING_DIR
cp docker-compose-beta.yml $STAGING_DIR
cp docker-compose-fortify.yml $STAGING_DIR
cp server-default.conf $STAGING_DIR

# Set DTR for Docker - Perform against ALL Dockerfiles in your project
/usr/bin/perl -i -pe "s|%%DTR_PREFIX%%|$DTR_PREFIX|g" $STAGING_DIR/Dockerfile || { echo "FATAL: Could not set DTR Prefix"; exit 1; }
/usr/bin/perl -i -pe "s|%%DTR_ORG%%|$DTR_ORG|g" $STAGING_DIR/Dockerfile || { echo "FATAL: Could not set DTR Ogranization"; exit 1; }
/usr/bin/perl -i -pe "s|%%CONTEXT_ROOT%%|$CONTEXT_ROOT|g" $STAGING_DIR/Dockerfile || { echo "FATAL: Could not set Context Root"; exit 1; }
/usr/bin/perl -i -pe "s|%%CONTEXT_ROOT_BETA%%|$CONTEXT_ROOT_BETA|g" $STAGING_DIR/Dockerfile || { echo "FATAL: Could not set Context Root"; exit 1; }
/usr/bin/perl -i -pe "s|%%CONTEXT_VERSION%%|$CONTEXT_VERSION|g" $STAGING_DIR/Dockerfile || { echo "FATAL: Could not set Context Version"; exit 1; }

#rm "${BUILD_DIR}/_temp-resource-directory.json"

ARTIFACT="${BUILD_DIR}/${JOB_NAME}.BUILD-${BUILD_NUMBER}.tar.gz"
printf "Building application artifact ${ARTIFACT}...\n\n"
tar -C $STAGING_DIR -zcvf $ARTIFACT . || { echo "FATAL: Failed on 'Artifact tar''"; exit 1; }
cp $ARTIFACT .

printf "\n\n\n\n**** COMPLETED BUILD ********************\n\n"