This repository has been archived on 2021-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
stack-ssh-deploy/plugin.sh

43 lines
982 B
Bash
Executable File

#!/bin/bash
set -e
PLUGIN_COMPOSE=${PLUGIN_COMPOSE:-compose.yml}
PLUGIN_HOST=${PLUGIN_HOST:-swarm.autonomic.zone}
PLUGIN_PORT=${PLUGIN_PORT:-222}
PLUGIN_USER=${PLUGIN_USER:-drone}
load_deploy_key() {
mkdir -p "$HOME/.ssh/"
ssh-keyscan -p "$PLUGIN_PORT" "$PLUGIN_HOST" > "$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 ---"
docker \
-H "ssh://$PLUGIN_USER@$PLUGIN_HOST:$PLUGIN_PORT" \
stack deploy -c "$PLUGIN_COMPOSE" "$PLUGIN_STACK"
}
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 -x /dev/stdin "$PLUGIN_STACK"
}
run_plugin() {
echo "--- start deployment ---"
load_deploy_key
run_stack_deploy
run_stack_wait
echo "--- end deployment ---"
}
run_plugin