问题
I'm using an IBM devops pipeline based on the Cloud Foundry template. The template gives you Blue-Green deployments.
My stage deploy script looks like this:
#!/bin/bash
cat << EOF > ${WORKSPACE}/manifest.yml
declared-services:
my_cloudant:
label: cloudantNoSQLDB
plan: Lite
my_messagehub:
label: messagehub
plan: standard
my_autoscaling:
label: Auto-Scaling
plan: free
my_availability_monitoring:
label: AvailabilityMonitoring
plan: Lite
applications:
- name: movie-recommend-demo
host: movie-recommend-demo
buildpack: https://github.com/cloudfoundry/python-buildpack.git#v1.5.18
memory: 128M
instances: 2
path: web_app
services:
- my_cloudant
- my_messagehub
- my_autoscaling
- my_availability_monitoring
timeout: 180
env:
# these are set in the devops stage ENVIRONMENT PROPERTIES
BI_HIVE_USERNAME: ${BI_HIVE_USERNAME}
BI_HIVE_PASSWORD: ${BI_HIVE_PASSWORD}
BI_HIVE_HOSTNAME: ${BI_HIVE_HOSTNAME}
EOF
# Push app
if ! cf app $CF_APP; then
cf push $CF_APP
else
OLD_CF_APP=${CF_APP}-OLD-$(date +"%s")
rollback() {
set +e
if cf app $OLD_CF_APP; then
cf logs $CF_APP --recent
cf delete $CF_APP -f
cf rename $OLD_CF_APP $CF_APP
fi
exit 1
}
set -e
trap rollback ERR
cf rename $CF_APP $OLD_CF_APP
cf push $CF_APP
cf delete $OLD_CF_APP -f
fi
# TODO:
# - Reconfigure Availability Monitoring on Green deployment
# - Reconfigure Autoscaling on Green deployment (https://console.bluemix.net/docs/cli/plugins/auto-scaling/index.html)
# Export app name and URL for use in later Pipeline jobs
export CF_APP_NAME="$CF_APP"
export APP_URL=http://$(cf app $CF_APP_NAME | grep urls: | awk '{print $2}')
# View logs
#cf logs "${CF_APP}" --recent
Before setting up and running the stage, I had availability monitoring setup on my cloud foundry app. Running the stage has caused my availability monitoring configuration to be deleted.
How can I automatically reconfigure the availability monitoring in the new 'green' deployment with the script?
I had a similar question for Auto Scaling, but there appears to be an API/CLI that I can use to reconfigure that service. However, I ran into a problem using cf oauth-token
回答1:
This is a current deficiency in the service that is actively being worked and should be available later this year. For now, the way to keep the configuration is to not delete the app but rather reuse 2 apps. This can become somewhat confusing as to which one has the tests even if you only bind the service to one app especially if you use the monitoring tab. What we do when selfmonitoring is create a dummy app in the space and bind the service to it (it doesn't need to even be running). We then use it to monitor the blue/green app(s). Here we also don't delete the app but just reuse the apps.
来源:https://stackoverflow.com/questions/44667141/how-to-programatically-reconfigure-availability-monitoring-in-devops-stage-for-b