Created
February 11, 2016 23:41
-
-
Save bbertka/1434a48f31c1b8d3ea57 to your computer and use it in GitHub Desktop.
Matt Stine - Enabling Continuous Delivery Scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://www.youtube.com/watch?v=0EZ_JOavLjM | |
#cassandra-demo-integration-tests/configure | |
export VCAP_APPLICATION=“” | |
export REQUIRED_SERVICE_INSTANCES=“p-cassandra:multi-tenant:int-test-cassandra” | |
. test_service_instances | |
./gradlew clean integrationTest | |
Script 2: | |
# cassandra-demo-build-artifact/configure | |
# SWITCHES | |
-Pbuildversion=$BUILD_NUMBER | |
# TASKS | |
clean assemble | |
Script 3: | |
#cassandra-demo-deploy/configure | |
import jenkins.model.* | |
import hudson.model.* | |
def getAllBuildNumbers(Job job) { | |
def buildNumbers = [] | |
(job.getBuilds()).each { build -> | |
buildNumbers.add(build.getDisplayName().substring(1)) | |
} | |
return buildNumbers | |
} | |
def buildJob = Jenkins.instance.getItemByFullName(‘cassandra-demo-build-artifact’); | |
return getAllBuildNumbers(buildJob) | |
Script 4: | |
#cassandra-demo-deploy/configure | |
# LOGIN TO PIVOTAL CF | |
cf login -a https://api.cf.deepsouthcloud.com -u mstine -p ${CF_PASSWORD} -o mstine-org -s development —skip-ssl-validation | |
# DETERMINE CURRENTLY DEPLOYED VERSION OF APP | |
DEPLOYED_VERSION_CMD=$(CF_COLOR=false cf apps | grep ‘cassandra-demo-‘ | cut -d” “ -f1) | |
DEPLOYED_VERSION=“$DEPLOYED_VERSION_CMD" | |
# DETERMINE VERSION FOR NEW PRIVATE ROUTE | |
ROUTE_VERSION=$(echo “${BUILD_VERSION}” | cut -d”.” -f1-3 | tr ‘.’ ‘-‘) | |
echo “Deployed Version: $DEPLOYED_VERSION” | |
echo “Route Version: $ROUTE_VERSION” | |
# PUSH THE APP | |
cf push “cassandra-demo-$BUILD_VERSION” -i 1 -m 512M -n “cassandra-demo-$ROUTE_VERSION” -d cf.deepsouthcloud.com -p artifacts/cassandra-demo-${BUILD_VERSION}.jar —no-manifest —no-start | |
# BIND THE CASSANDRA SERVICE | |
cf bind-service “cassandra-demo-$BUILD_VERSION” my-cassandra | |
# START THE APP | |
cf start “cassandra-demo-$BUILD_VERSION” | |
# MAP THE PUBLIC ROUTE | |
cf map-route “cassandra-demo-${BUILD_VERSION}” cf.deepsouthcloud.com -n cassandra-demo | |
# SCALE UP FOR REDUNDANCY | |
cf scale cassandra-demo-${BUILD_VERSION} -i 2 | |
# PERFORM ZERO-DOWNTIME CUTOVER TO NEW VERSION | |
if [ ! -z “$DEPLOYED_VERSION” -a “$DEPLOYED_VERSION” != “ “ -a “$DEPLOYED_VERSION” != “cassandra-demo-${BUILD_VERSION}” ]; then | |
echo “Performing zero-downtime cutover to $BUILD_VERSION | |
while read line | |
do | |
if [ ! -z “$line” -a “$line” != “ “ -a “$line” != “cassandra-demo-${BUILD_VERSION}” ]; then | |
echo “Scaling down, unmapping and removing $line” | |
# SCALE DOWN OLD VERSION | |
cf scale “$line” -i 1 | |
# UNMAP PUBLIC ROUTE FROM OLD VERSION | |
cf unmap-route “$line” cf.deepsouthcloud.com -n cassandra-demo | |
# DELETE OLD VERSION | |
cf delete “$line” -f | |
else | |
echo “Skipping $line” | |
fi | |
done <<EOF | |
$DEPLOYED_VERSION | |
EOF | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment