Created
January 11, 2019 09:05
-
-
Save FaKleiser/9a1f4212873c5bb9bf9a0857b10e2b29 to your computer and use it in GitHub Desktop.
Debug the manifest that would be generated by BOSH deployment scripts
This file contains 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
#!/bin/sh | |
# == Debug Manifest == | |
# This script allows to show interpolated manifests based on BOSH script files. | |
# | |
# Prerequisite: You have a script file that somewhere contains: | |
# bosh -e my-bosh-env deploy my-base-manifest.yml \ | |
# -o operations/expose-https.yml \ | |
# ... | |
# | |
# Then you can simply call this script that replaces [create-env|deploy|update-cloud-config] | |
# with `bosh int` to show the manifest that BOSH would be deploying. | |
# Find out more about `bosh int`: https://bosh.io/docs/cli-v2/#interpolate | |
# | |
# Usage: | |
# - Basic usage: | |
# debug-manifest.sh ./deploy-concourse.sh | |
# - Pass additional args to `bosh int`: | |
# debug-manifest.sh ./deploy-concourse.sh --path /instance_groups/name=worker | |
# | |
# For safety reasons, the script removes any `bosh alias-env` commands and | |
# empties `BOSH_ENVIRONMENT` before calling your script to prevent accidental | |
# deployments. | |
SCRIPT_TO_DEBUG=$1 | |
shift | |
BOSH_INT_ARGS="$@" | |
# check if script to debug exists | |
if [ -z ${SCRIPT_TO_DEBUG} ]; then | |
echo "Please provide a script to debug as argument" | |
exit 1 | |
fi | |
if [ ! -f ${SCRIPT_TO_DEBUG} ]; then | |
echo "The script ${SCRIPT_TO_DEBUG} is not a file!" | |
exit 1 | |
fi | |
# check if we find a BOSH command | |
if ! grep -qE "^bosh.* (deploy|update-cloud-config|create-env) " ${SCRIPT_TO_DEBUG}; then | |
echo "The given script ${SCRIPT_TO_DEBUG} seems not to contain a 'bosh [create-env|deploy|update-cloud-config]' command" | |
exit 1 | |
fi | |
# read script and replace BOSH command with `bosh int` | |
SAFE_BOSH_INT_ARGS=$(echo "${BOSH_INT_ARGS}" | sed -e 's/[\/&]/\\&/g') | |
SED_FIND='^(bosh.*) (deploy|update-cloud-config|create-env) ' | |
SED_REPLACE='\1 int '${SAFE_BOSH_INT_ARGS}' ' | |
SCRIPT_CONTENTS=$(cat ${SCRIPT_TO_DEBUG} | sed -r "s/${SED_FIND}/${SED_REPLACE}/g") | |
# remove --no-redact option (unsupported by `bosh int`) | |
SCRIPT_CONTENTS=$(echo "${SCRIPT_CONTENTS}" | sed 's/--no-redact //g') | |
# remove `bosh alias-env` commands (not relevant for interpolation) | |
SCRIPT_CONTENTS=$(echo "${SCRIPT_CONTENTS}" | sed 's/^bosh.* alias-env.*$//g') | |
# reset BOSH environment just in case | |
BOSH_ENVIRONMENT="" | |
# run bosh int | |
bash -c "${SCRIPT_CONTENTS}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment