Skip to content

Instantly share code, notes, and snippets.

@jimanx2
Last active July 15, 2021 08:42
Show Gist options
  • Select an option

  • Save jimanx2/d2973d0d9f21831a6e2bae8d100db025 to your computer and use it in GitHub Desktop.

Select an option

Save jimanx2/d2973d0d9f21831a6e2bae8d100db025 to your computer and use it in GitHub Desktop.
`conduct` bash script for working with multiple docker-compose.yaml file in one project
#!/bin/bash
# /usr/local/bin/conduct
pushd . > /dev/null 2>&1 && popd > /dev/null 2>&1
if [ -f .env ] && [ $(grep -U $'\x0D' .env | wc -l ) -gt 0 ]; then
echo "ERROR: .env contains CRLF!"
echo "Refusing to work."
exit 1
fi
if [ -f .env ]; then
source .env
fi
if [ ! -f .composes ]; then
echo "ERROR: .composes does not exist!"
echo "Refusing to work."
exit 1
fi
for COMPOSE in `cat .composes`; do
COMPOSES="$COMPOSES -f $BASE/$COMPOSE "
done
if [ $1 = "recreate" ]; then
docker-compose $COMPOSES up -d --force-recreate $2
elif [ $1 = "run" ]; then
shift
container=$1
shift
entrypoint=$1
shift
docker-compose $COMPOSES run --rm --user=root --entrypoint=$entrypoint $container $@
elif [ $1 = "debug-log" ]; then
shift
container=$1
logcmd=$(docker-compose $COMPOSES ps -q $container | xargs docker inspect --format "{{index .Config.Labels \"core.debug.log\"}}")
match=$(echo $logcmd | grep -oh -E "\`.+\`")
subcmd=${match:1:-1}
result=$(eval $subcmd)
logcmd=$(echo $logcmd | sed -s "s/$match/$result/g")
echo $logcmd
echo
docker-compose $COMPOSES exec $container $logcmd
elif [ $1 = "clean" ]; then
docker container prune -f
docker volume prune -f
else
docker-compose $COMPOSES $@
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment