Last active
January 25, 2018 09:59
-
-
Save sathlan/e8b688522acd2352fb8db39489f6f213 to your computer and use it in GitHub Desktop.
Debug tripleo docker-puppet error.
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
#!/usr/bin/bash | |
set -eu | |
IMAGE="${1:?'Provide a image name'}" | |
# Next line was first seen used under the magic finger of dciabrin and we shall love him for that forever. | |
CMD=$(docker inspect --format='{{range .Config.Env}} -e "{{.}}" {{end}} {{range .Mounts}} -v {{.Source}}:{{.Destination}}{{if .Mode}}:{{.Mode}}{{end}}{{end}} -ti {{.Config.Image}}' docker-puppet-${IMAGE} ) | |
echo "Command to use to re-run manually:\ndocker run -u root --net=host ${CMD}\n" | |
if [ ! -e /var/lib/docker-puppet/docker-puppet.sh.orig ]; then | |
sed -i.orig -e \ | |
's/puppet apply *--detailed-exitcodes/puppet apply --debug --detailed-exitcodes/' \ | |
/var/lib/docker-puppet/docker-puppet.sh | |
fi | |
puppet_config=$(cat /var/lib/docker-puppet/docker-puppet.json | \ | |
jq -r 'map(select(.config_volume == "'${IMAGE}'")) | | |
.[0].step_config') | |
echo "====> PUPPET configuration start for ${IMAGE}" | |
echo "${puppet_config}" | |
echo | |
echo "====> PUPPET configuration end " | |
IMAGE_ID=$(docker ps -a | awk '/'${IMAGE}'$/{print $1}') | |
EXPECTED_TMP_PUPPET_CONF=$(docker inspect ${IMAGE_ID} | \ | |
jq -r '.[] | .HostConfig | .Binds | | |
map(select(. | contains("config.pp"))) | .[0]' | \ | |
cut -d: -f1) | |
if [ -e "${EXPECTED_TMP_PUPPET_CONF}" -a ! -e "${EXPECTED_TMP_PUPPET_CONF}.orig" ]; then | |
mv "${EXPECTED_TMP_PUPPET_CONF}" "${EXPECTED_TMP_PUPPET_CONF}.orig" | |
fi | |
echo "${puppet_config}" > "${EXPECTED_TMP_PUPPET_CONF}" | |
echo "Starting the container ${IMAGE_ID} to debug ${IMAGE} using ${EXPECTED_TMP_PUPPET_CONF}" | |
docker start -ai $IMAGE_ID &> ${IMAGE}.log | |
echo "Log are in ${IMAGE}.log" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment