#!/bin/bash set -e RENDER_PROFILE=prod sops decrypt $RENDER_PROFILE-config.enc.yaml > $RENDER_PROFILE-config.yaml dockerContext=$(docker context inspect default | jq -r .[0].Endpoints.docker.Host) if [[ $dockerContext == unix://* ]]; then # docker daemon runs on the same machine # use gomplate to render profiles docker run --rm -v .:/data hairyhenderson/gomplate:v4.3.1 --config /data/gomplate.yaml -c config=/data/$RENDER_PROFILE-config.yaml # invoke twice to fix file permission issue docker run --rm -v .:/data hairyhenderson/gomplate:v4.3.1 --config /data/gomplate.yaml -c config=/data/$RENDER_PROFILE-config.yaml else # docker won't work, possibly in ci curl -o /usr/local/bin/gomplate -sSL https://github.com/hairyhenderson/gomplate/releases/download/v4.3.1/gomplate_linux-amd64 chmod 755 /usr/local/bin/gomplate /usr/local/bin/gomplate --config gomplate-ci.yaml -c config=$RENDER_PROFILE-config.yaml fi rm -f $RENDER_PROFILE-config.yaml # check each profile to make sure they exists # and convert to the cli CONFIG_FILES=("-c" "docker-stack.base.yml") # preview the full stack echo "Stack config preview:" cmd=(docker stack config "${CONFIG_FILES[@]}") if "${cmd[@]}"; then echo "The above config will be used" else echo "Command failed!" exit 1 fi "${cmd[@]}" > compose.$RENDER_PROFILE.yaml rm -f docker-stack.*.yml