Skip to content

Instantly share code, notes, and snippets.

@ryanjbaxter
Last active May 16, 2018 20:14
Show Gist options
  • Select an option

  • Save ryanjbaxter/9ec2dd5de1b1279338bf to your computer and use it in GitHub Desktop.

Select an option

Save ryanjbaxter/9ec2dd5de1b1279338bf to your computer and use it in GitHub Desktop.

Revisions

  1. ryanjbaxter revised this gist Jun 1, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions bluegreen.sh
    Original file line number Diff line number Diff line change
    @@ -76,8 +76,8 @@ else
    fi

    echo "Pushing application"
    echo "app name ${CF_APP}"
    cf push "${APP_NAME}" "${CF_PUSH_ARGS}" --no-start

    cf push ${APP_NAME} ${CF_PUSH_ARGS} --no-start

    echo "Done pushing application"

  2. ryanjbaxter revised this gist Jun 1, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion bluegreen.sh
    Original file line number Diff line number Diff line change
    @@ -76,7 +76,7 @@ else
    fi

    echo "Pushing application"
    echo "app name ${APP_NAME}"
    echo "app name ${CF_APP}"
    cf push "${APP_NAME}" "${CF_PUSH_ARGS}" --no-start

    echo "Done pushing application"
  3. ryanjbaxter revised this gist Jun 1, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion bluegreen.sh
    Original file line number Diff line number Diff line change
    @@ -76,7 +76,7 @@ else
    fi

    echo "Pushing application"
    echo app name "${APP_NAME}"
    echo "app name ${APP_NAME}"
    cf push "${APP_NAME}" "${CF_PUSH_ARGS}" --no-start

    echo "Done pushing application"
  4. ryanjbaxter revised this gist Jun 1, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions bluegreen.sh
    Original file line number Diff line number Diff line change
    @@ -76,8 +76,8 @@ else
    fi

    echo "Pushing application"
    echo app name "{$APP_NAME}"
    cf push "{$APP_NAME}" "{$CF_PUSH_ARGS}" --no-start
    echo app name "${APP_NAME}"
    cf push "${APP_NAME}" "${CF_PUSH_ARGS}" --no-start

    echo "Done pushing application"

  5. ryanjbaxter revised this gist Jun 1, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions bluegreen.sh
    Original file line number Diff line number Diff line change
    @@ -76,8 +76,8 @@ else
    fi

    echo "Pushing application"

    cf push "$APP_NAME" "$CF_PUSH_ARGS" --no-start
    echo app name "{$APP_NAME}"
    cf push "{$APP_NAME}" "{$CF_PUSH_ARGS}" --no-start

    echo "Done pushing application"

  6. ryanjbaxter revised this gist Jun 1, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion bluegreen.sh
    Original file line number Diff line number Diff line change
    @@ -77,7 +77,7 @@ fi

    echo "Pushing application"

    cf push $APP_NAME $CF_PUSH_ARGS --no-start
    cf push "$APP_NAME" "$CF_PUSH_ARGS" --no-start

    echo "Done pushing application"

  7. ryanjbaxter revised this gist Apr 15, 2015. 1 changed file with 15 additions and 0 deletions.
    15 changes: 15 additions & 0 deletions bluegreen.sh
    Original file line number Diff line number Diff line change
    @@ -47,6 +47,21 @@
    # take the form host1:domain1,host2:domain2,domain3 #
    # 5. CF_PUSH_ARGS - a string of arguments to use when calling `cf push #
    # For example, pushing a specific artifact or setting the memory. #
    # #
    # #
    # To use this script in IBM DevOps Services paste the following Bash script in #
    # your Deploy stage. #
    # #
    # #!/bin/bash #
    # git clone https://gist.github.com/9ec2dd5de1b1279338bf.git deploy #
    # /bin/bash deploy/bluegreen.sh #
    # RESULT=$? #
    # #
    # if [ $RESULT -ne 0 ]; then #
    # echo -e "${red}Executed failed or had warnings ${no_color}" #
    # exit $RESULT #
    # fi #
    # echo -e "${green}Execution complete${no_label}" #
    # ******************************************************************************


  8. ryanjbaxter revised this gist Apr 14, 2015. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion bluegreen.sh
    Original file line number Diff line number Diff line change
    @@ -45,6 +45,8 @@
    # should take the form servicename1,servicename2 #
    # 4. ROUTES - Routes that should be mapped to the app. The value should #
    # take the form host1:domain1,host2:domain2,domain3 #
    # 5. CF_PUSH_ARGS - a string of arguments to use when calling `cf push #
    # For example, pushing a specific artifact or setting the memory. #
    # ******************************************************************************


    @@ -60,7 +62,7 @@ fi

    echo "Pushing application"

    cf push $APP_NAME -p ${CF_APP}.war -m 512M --no-start
    cf push $APP_NAME $CF_PUSH_ARGS --no-start

    echo "Done pushing application"

  9. ryanjbaxter revised this gist Apr 14, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion bluegreen.sh
    Original file line number Diff line number Diff line change
    @@ -62,7 +62,7 @@ echo "Pushing application"

    cf push $APP_NAME -p ${CF_APP}.war -m 512M --no-start

    echo "Done pushing application war"
    echo "Done pushing application"

    echo "Setting environment variables"

  10. ryanjbaxter revised this gist Apr 14, 2015. 1 changed file with 11 additions and 15 deletions.
    26 changes: 11 additions & 15 deletions bluegreen.sh
    Original file line number Diff line number Diff line change
    @@ -58,7 +58,7 @@ else
    export APP_NAME="${CF_APP}"
    fi

    echo "Pushing application war"
    echo "Pushing application"

    cf push $APP_NAME -p ${CF_APP}.war -m 512M --no-start

    @@ -75,20 +75,16 @@ done

    echo "Mapping routes in order to balance traffic between two instances"

    #if $EXISTS; then
    IFS=',' read -a routesarray <<< "$ROUTES"
    for element in "${routesarray[@]}"
    do
    if [[ $element == *":"* ]]; then
    IFS=':' read -a route <<< "$element"
    cf map-route $APP_NAME ${route[1]} -n ${route[0]}
    else
    cf map-route $APP_NAME $element
    fi
    done
    #else
    # echo "App did not pre-exist, no need to map route."
    #fi
    IFS=',' read -a routesarray <<< "$ROUTES"
    for element in "${routesarray[@]}"
    do
    if [[ $element == *":"* ]]; then
    IFS=':' read -a route <<< "$element"
    cf map-route $APP_NAME ${route[1]} -n ${route[0]}
    else
    cf map-route $APP_NAME $element
    fi
    done

    echo "Done mapping routes"

  11. ryanjbaxter revised this gist Apr 10, 2015. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion bluegreen.sh
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,7 @@
    #!/bin/bash

    #
    # This product includes software originally developed by IBM Corporation.
    #
    #
    # Copyright IBM Corp. 2015
    #
  12. ryanjbaxter revised this gist Apr 9, 2015. 1 changed file with 41 additions and 24 deletions.
    65 changes: 41 additions & 24 deletions bluegreen.sh
    Original file line number Diff line number Diff line change
    @@ -1,32 +1,49 @@
    #!/bin/bash

    # **********************************USAGE**************************************
    # This script will will do a blue/green deployment of an app to Cloud Foundry.
    # It assumes you are already logged in, if not make sure you run `cf login`
    # before executing this script.
    #
    # This scrip can do the following things
    # 1. Push the application
    # 2. Bind Services
    # 3. Set Environment Variables
    # 4. Map Routes
    # 5. Start the application
    # Copyright IBM Corp. 2015
    #
    # If a version of the application already exists in the org and space being
    # deployed to this script will deploy the new application under the name
    # <appName>-new. The routes mapped to the existing application will be mapped
    # to the new version. Then the old version of the application will be deleted
    # and the new version will be renamed to <appName>.
    # Licensed under the Apache License, Version 2.0 (the "License");
    # you may not use this file except in compliance with the License.
    # You may obtain a copy of the License at
    #
    # The scripts depends on a couple of environment variables being set.
    # 1. CF_APP - This environment variable is set by default in IBM DevOPs Services
    # 2. ENV_VARS - Environment variables to be set. The value should take the form
    # NAME1:value1,NAME2:value2
    # 3. SERVICES - Services that should be bound to the application. The value
    # should take the form servicename1,servicename2
    # 4. ROUTES - Routes that should be mapped to the app. The value should
    # take the form host1:domain1,host2:domain2,domain3
    # *****************************************************************************
    # http://www.apache.org/licenses/LICENSE-2.0
    #
    # Unless required by applicable law or agreed to in writing, software
    # distributed under the License is distributed on an "AS IS" BASIS,
    # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    # See the License for the specific language governing permissions and
    # limitations under the License.
    #

    # **********************************USAGE***************************************
    # This script will will do a blue/green deployment of an app to Cloud Foundry. #
    # It assumes you are already logged in, if not make sure you run `cf login` #
    # before executing this script. #
    # #
    # This scrip can do the following things #
    # 1. Push the application #
    # 2. Bind Services #
    # 3. Set Environment Variables #
    # 4. Map Routes #
    # 5. Start the application #
    # #
    # If a version of the application already exists in the org and space being #
    # deployed to this script will deploy the new application under the name #
    # <appName>-new. The routes mapped to the existing application will be mapped #
    # to the new version. Then the old version of the application will be deleted #
    # and the new version will be renamed to <appName>. #
    # #
    # The scripts depends on a couple of environment variables being set. #
    # 1. CF_APP - This environment variable is set by default in IBM DevOPs #
    # Services #
    # 2. ENV_VARS - Environment variables to be set. The value should take the #
    # form NAME1:value1,NAME2:value2 #
    # 3. SERVICES - Services that should be bound to the application. The value #
    # should take the form servicename1,servicename2 #
    # 4. ROUTES - Routes that should be mapped to the app. The value should #
    # take the form host1:domain1,host2:domain2,domain3 #
    # ******************************************************************************


    COMMAND="cf apps | grep -w --quiet ${CF_APP}"
  13. ryanjbaxter revised this gist Apr 9, 2015. 1 changed file with 13 additions and 13 deletions.
    26 changes: 13 additions & 13 deletions bluegreen.sh
    Original file line number Diff line number Diff line change
    @@ -56,7 +56,7 @@ done

    echo "Mapping routes in order to balance traffic between two instances"

    if $EXISTS; then
    #if $EXISTS; then
    IFS=',' read -a routesarray <<< "$ROUTES"
    for element in "${routesarray[@]}"
    do
    @@ -67,9 +67,9 @@ if $EXISTS; then
    cf map-route $APP_NAME $element
    fi
    done
    else
    echo "App did not pre-exist, no need to map route."
    fi
    #else
    # echo "App did not pre-exist, no need to map route."
    #fi

    echo "Done mapping routes"

    @@ -89,17 +89,17 @@ cf start $APP_NAME

    echo "Done starting application"

    #echo "Cleaning up old application"
    echo "Cleaning up old application"

    #if $EXISTS; then
    # cf delete -f ${CF_APP}
    # cf unmap-route $APP_NAME mybluemix.net -n $APP_NAME
    # cf rename $APP_NAME ${CF_APP}
    #else
    # echo "No cleanup needed, app did not exist"
    #fi
    if $EXISTS; then
    cf delete -f ${CF_APP}
    cf unmap-route $APP_NAME mybluemix.net -n $APP_NAME
    cf rename $APP_NAME ${CF_APP}
    else
    echo "No cleanup needed, app did not exist"
    fi

    #echo "Done cleaning up the old application"
    echo "Done cleaning up the old application"

    # view logs
    #cf logs "${CF_APP}" --recent
  14. ryanjbaxter revised this gist Apr 9, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion bluegreen.sh
    Original file line number Diff line number Diff line change
    @@ -60,7 +60,7 @@ if $EXISTS; then
    IFS=',' read -a routesarray <<< "$ROUTES"
    for element in "${routesarray[@]}"
    do
    if [[ $element == *":"* ]] then
    if [[ $element == *":"* ]]; then
    IFS=':' read -a route <<< "$element"
    cf map-route $APP_NAME ${route[1]} -n ${route[0]}
    else
  15. ryanjbaxter revised this gist Apr 9, 2015. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion bluegreen.sh
    Original file line number Diff line number Diff line change
    @@ -60,11 +60,12 @@ if $EXISTS; then
    IFS=',' read -a routesarray <<< "$ROUTES"
    for element in "${routesarray[@]}"
    do
    if [[ $element == *":"* ]]
    if [[ $element == *":"* ]] then
    IFS=':' read -a route <<< "$element"
    cf map-route $APP_NAME ${route[1]} -n ${route[0]}
    else
    cf map-route $APP_NAME $element
    fi
    done
    else
    echo "App did not pre-exist, no need to map route."
  16. ryanjbaxter revised this gist Apr 9, 2015. 1 changed file with 48 additions and 10 deletions.
    58 changes: 48 additions & 10 deletions bluegreen.sh
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,34 @@
    #!/bin/bash

    # **********************************USAGE**************************************
    # This script will will do a blue/green deployment of an app to Cloud Foundry.
    # It assumes you are already logged in, if not make sure you run `cf login`
    # before executing this script.
    #
    # This scrip can do the following things
    # 1. Push the application
    # 2. Bind Services
    # 3. Set Environment Variables
    # 4. Map Routes
    # 5. Start the application
    #
    # If a version of the application already exists in the org and space being
    # deployed to this script will deploy the new application under the name
    # <appName>-new. The routes mapped to the existing application will be mapped
    # to the new version. Then the old version of the application will be deleted
    # and the new version will be renamed to <appName>.
    #
    # The scripts depends on a couple of environment variables being set.
    # 1. CF_APP - This environment variable is set by default in IBM DevOPs Services
    # 2. ENV_VARS - Environment variables to be set. The value should take the form
    # NAME1:value1,NAME2:value2
    # 3. SERVICES - Services that should be bound to the application. The value
    # should take the form servicename1,servicename2
    # 4. ROUTES - Routes that should be mapped to the app. The value should
    # take the form host1:domain1,host2:domain2,domain3
    # *****************************************************************************


    COMMAND="cf apps | grep -w --quiet ${CF_APP}"

    if eval $COMMAND; then
    @@ -27,7 +57,15 @@ done
    echo "Mapping routes in order to balance traffic between two instances"

    if $EXISTS; then
    cf map-route $APP_NAME mybluemix.net -n $HOST
    IFS=',' read -a routesarray <<< "$ROUTES"
    for element in "${routesarray[@]}"
    do
    if [[ $element == *":"* ]]
    IFS=':' read -a route <<< "$element"
    cf map-route $APP_NAME ${route[1]} -n ${route[0]}
    else
    cf map-route $APP_NAME $element
    done
    else
    echo "App did not pre-exist, no need to map route."
    fi
    @@ -50,17 +88,17 @@ cf start $APP_NAME

    echo "Done starting application"

    echo "Cleaning up old application"
    #echo "Cleaning up old application"

    if $EXISTS; then
    cf delete -f ${CF_APP}
    cf unmap-route $APP_NAME mybluemix.net -n $APP_NAME
    cf rename $APP_NAME ${CF_APP}
    else
    echo "No cleanup needed, app did not exist"
    fi
    #if $EXISTS; then
    # cf delete -f ${CF_APP}
    # cf unmap-route $APP_NAME mybluemix.net -n $APP_NAME
    # cf rename $APP_NAME ${CF_APP}
    #else
    # echo "No cleanup needed, app did not exist"
    #fi

    echo "Done cleaning up the old application"
    #echo "Done cleaning up the old application"

    # view logs
    #cf logs "${CF_APP}" --recent
  17. ryanjbaxter revised this gist Apr 7, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion bluegreen.sh
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@ else
    export APP_NAME="${CF_APP}"
    fi

    echo "${green}Pushing application war${no_color}"
    echo "Pushing application war"

    cf push $APP_NAME -p ${CF_APP}.war -m 512M --no-start

  18. ryanjbaxter revised this gist Apr 7, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion bluegreen.sh
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@ else
    export APP_NAME="${CF_APP}"
    fi

    echo "${label_color}Pushing application war${no_color}"
    echo "${green}Pushing application war${no_color}"

    cf push $APP_NAME -p ${CF_APP}.war -m 512M --no-start

  19. ryanjbaxter revised this gist Apr 7, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion bluegreen.sh
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@ else
    export APP_NAME="${CF_APP}"
    fi

    echo "Pushing application war"
    echo "${label_color}Pushing application war${no_color}"

    cf push $APP_NAME -p ${CF_APP}.war -m 512M --no-start

  20. ryanjbaxter revised this gist Apr 7, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions bluegreen.sh
    Original file line number Diff line number Diff line change
    @@ -53,9 +53,9 @@ echo "Done starting application"
    echo "Cleaning up old application"

    if $EXISTS; then
    cf delete -f $APP_NAME_PREFIX
    cf delete -f ${CF_APP}
    cf unmap-route $APP_NAME mybluemix.net -n $APP_NAME
    cf rename $APP_NAME $APP_NAME_PREFIX
    cf rename $APP_NAME ${CF_APP}
    else
    echo "No cleanup needed, app did not exist"
    fi
  21. ryanjbaxter revised this gist Apr 7, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion bluegreen.sh
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,7 @@ fi

    echo "Pushing application war"

    cf push $APP_NAME -p $APP_NAME_PREFIX.war -m 512M --no-start
    cf push $APP_NAME -p ${CF_APP}.war -m 512M --no-start

    echo "Done pushing application war"

  22. ryanjbaxter revised this gist Apr 7, 2015. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions bluegreen.sh
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,12 @@
    #!/bin/bash
    COMMAND="cf apps | grep -w --quiet $APP_NAME_PREFIX"
    COMMAND="cf apps | grep -w --quiet ${CF_APP}"

    if eval $COMMAND; then
    export EXISTS=true
    export APP_NAME="$APP_NAME_PREFIX-new"
    export APP_NAME="${CF_APP}-new"
    else
    export EXISTS=false
    export APP_NAME="$APP_NAME_PREFIX"
    export APP_NAME="${CF_APP}"
    fi

    echo "Pushing application war"
  23. ryanjbaxter renamed this gist Apr 7, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  24. ryanjbaxter created this gist Apr 7, 2015.
    66 changes: 66 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,66 @@
    #!/bin/bash
    COMMAND="cf apps | grep -w --quiet $APP_NAME_PREFIX"

    if eval $COMMAND; then
    export EXISTS=true
    export APP_NAME="$APP_NAME_PREFIX-new"
    else
    export EXISTS=false
    export APP_NAME="$APP_NAME_PREFIX"
    fi

    echo "Pushing application war"

    cf push $APP_NAME -p $APP_NAME_PREFIX.war -m 512M --no-start

    echo "Done pushing application war"

    echo "Setting environment variables"

    IFS=',' read -a envvarsarray <<< "$ENV_VARS"
    for element in "${envvarsarray[@]}"
    do
    IFS=':' read -a envvar <<< "$element"
    cf set-env $APP_NAME ${envvar[0]} ${envvar[1]}
    done

    echo "Mapping routes in order to balance traffic between two instances"

    if $EXISTS; then
    cf map-route $APP_NAME mybluemix.net -n $HOST
    else
    echo "App did not pre-exist, no need to map route."
    fi

    echo "Done mapping routes"

    echo "Binding services"

    IFS=',' read -a servicesarray <<< "$SERVICES"
    for element in "${servicesarray[@]}"
    do
    cf bind-service $APP_NAME $element
    done

    echo "Done mapping services"

    echo "Starting application"

    cf start $APP_NAME

    echo "Done starting application"

    echo "Cleaning up old application"

    if $EXISTS; then
    cf delete -f $APP_NAME_PREFIX
    cf unmap-route $APP_NAME mybluemix.net -n $APP_NAME
    cf rename $APP_NAME $APP_NAME_PREFIX
    else
    echo "No cleanup needed, app did not exist"
    fi

    echo "Done cleaning up the old application"

    # view logs
    #cf logs "${CF_APP}" --recent