#!/bin/bash set -e PLUGIN_COMPOSE=${PLUGIN_COMPOSE:-compose.yml} PLUGIN_HOST=${PLUGIN_HOST:-swarm.autonomic.zone} PLUGIN_PORT=${PLUGIN_PORT:-222} PLUGIN_PURGE=${PLUGIN_PURGE:-"false"} PLUGIN_USER=${PLUGIN_USER:-drone} export DOCKER_HOST="ssh://$PLUGIN_USER@$PLUGIN_HOST:$PLUGIN_PORT" generate_secrets() { echo "--- start secrets ---" # FIXME 3wc: use the yq docker image instead; couldn't easily get it working VERSION=3.4.0 BINARY=yq_linux_amd64 wget https://github.com/mikefarah/yq/releases/download/${VERSION}/${BINARY} -O /usr/bin/yq &&\ chmod +x /usr/bin/yq for SECRET in $(yq r "$PLUGIN_COMPOSE" 'secrets.*.name'); do eval "echo \"generating $SECRET\"" PW=$( "$HOME/.ssh/known_hosts" # shellcheck disable=SC2046,SC2006 eval `ssh-agent` echo "$PLUGIN_DEPLOY_KEY" | ssh-add - } run_stack_deploy() { echo "--- start docker info ---" docker version echo "--- end docker info ---" run_stack_deploy() { echo "--- start deploy ---" docker stack deploy -c "$PLUGIN_COMPOSE" "$PLUGIN_STACK" echo "--- end deploy ---" } run_stack_wait() { export DOCKER_HOST="ssh://$PLUGIN_USER@$PLUGIN_HOST:$PLUGIN_PORT" docker run --rm vitalets/docker-stack-wait-deploy | sed 's/True/true/' | bash /dev/stdin "$PLUGIN_STACK" } run_plugin() { echo "--- start deployment ---" load_deploy_key if [ -n "$PLUGIN_GENERATE_SECRETS" ]; then generate_secrets fi run_stack_deploy run_stack_wait echo "--- end deployment ---" } run_plugin