#!/bin/bash set -e set -o pipefail PLUGIN_SOURCE=${PLUGIN_SOURCE:-.} PLUGIN_HOST=${PLUGIN_HOST:-swarm.autonomic.zone} PLUGIN_PORT=${PLUGIN_PORT:-222} PLUGIN_USER=${PLUGIN_USER:-drone} PLUGIN_DEST=${PLUGIN_DEST:?dest is not set} REMOTE_DOCKER_HOST="ssh://$PLUGIN_USER@$PLUGIN_HOST:$PLUGIN_PORT" load_deploy_key() { echo "--- start ssh key load ---" 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 - echo "--- end ssh key load ---" } output_versions(){ echo "--- start versions" docker version echo "--- end versions" } run_docker_cp() { echo "--- start deploy ---" CONTAINER=$(docker -H "$REMOTE_DOCKER_HOST" container ls \ --format "table {{.ID}},{{.Names}}" \ | grep "${PLUGIN_SERVICE}" | cut -d',' -f1) if [ -z "$CONTAINER" ]; then echo "ERROR: can't find container for $PLUGIN_SERVICE" return 1 fi CD="" if [ -n "$PLUGIN_CHDIR" ]; then CD="-C $PLUGIN_CHDIR" fi echo "Copying $PLUGIN_SOURCE" # shellcheck disable=SC2086 tar cf - $CD $PLUGIN_SOURCE | docker -H "$REMOTE_DOCKER_HOST" cp - $CONTAINER:$PLUGIN_DEST if [ -n "$PLUGIN_EXEC" ]; then docker -H "$REMOTE_DOCKER_HOST" exec "$CONTAINER" sh -c "$PLUGIN_EXEC" fi echo "--- end deploy ---" } run_plugin() { echo "--- start docker-cp-deploy ---" load_deploy_key output_versions run_docker_cp echo "--- end docker-cp-deploy ---" } run_plugin