Skip to content

Instantly share code, notes, and snippets.

@JensRantil
Last active August 25, 2017 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JensRantil/c8757d607b379d3256299fd32a373a35 to your computer and use it in GitHub Desktop.
Save JensRantil/c8757d607b379d3256299fd32a373a35 to your computer and use it in GitHub Desktop.
Masterless CI of Salt.
#!/bin/bash
set -eu
MINIONID="$1"
SYNCMODULESLOG=$(mktemp)
SHOWTOPLOG=$(mktemp)
PILLARITEMSLOG=$(mktemp)
SHOWHIGHSTATELOG=$(mktemp)
# `--force-color` below is needed since we are writing output to a file.
# Without this, custom execution modules (and other execution modules for that matter) will not be synced when executing `state.show_highstate` below.
salt-call --force-color --local --retcode-passthrough --id="$MINIONID" saltutil.sync_modules &> "$SYNCMODULESLOG" &
# Must be run before `state.show_highstate`. There's a race condition between them. Alternative is to use two different IPC sockets in the future.
salt-call --force-color --local --retcode-passthrough --id="$MINIONID" state.show_top &> "$SHOWTOPLOG" &
# Wait for all jobs above to finish.
EXITCODE=0
wait %1 || EXITCODE=$?
wait %2 || EXITCODE=$?
# Run these in parallel to speed things up.
salt-call --force-color --local --retcode-passthrough --id="$MINIONID" pillar.items &> "$PILLARITEMSLOG" &
salt-call --force-color --local --retcode-passthrough --id="$MINIONID" state.show_highstate &> "$SHOWHIGHSTATELOG" &
# Wait for all jobs above to finish.
wait %1 || EXITCODE=$?
wait %2 || EXITCODE=$?
if [ $EXITCODE -ne 0 ]
then
echo "--- salt $MINIONID saltutil.sync_modules"
cat "$SYNCMODULESLOG"
echo "--- salt $MINIONID state.show_top"
cat "$SHOWTOPLOG"
echo "--- salt $MINIONID pillar.items"
cat "$PILLARITEMSLOG"
echo "--- salt $MINIONID state.show_highstate"
cat "$SHOWHIGHSTATELOG"
else
echo "Calculating highstate $MINIONID succeeded."
fi
rm "$SYNCMODULESLOG"
rm "$SHOWTOPLOG"
rm "$PILLARITEMSLOG"
rm "$SHOWHIGHSTATELOG"
exit $EXITCODE
#!/bin/bash
set -eu
find . -name top.sls -exec grep --no-filename '^ # CI example:' {} + | sed 's/.*# CI example: //' | sort | uniq | while read -r MINIONID
do
./salt-dry-run-single.sh "$MINIONID"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment