Support removing a stack before deploying
continuous-integration/drone/push Build is passing Details
continuous-integration/drone Build is failing Details

This commit is contained in:
decentral1se 2021-06-05 08:33:03 +02:00
parent 563356b8b8
commit 3fb617a797
Signed by: decentral1se
GPG Key ID: 92DAD76BD9567B8A
2 changed files with 18 additions and 1 deletions

View File

@ -20,6 +20,7 @@ This is meant to be used as a [Drone plugin](http://plugins.drone.io/).
- **port** (default: `222`): SSH port to connect to
- **user** (default: `drone`): System user to connect via SSH with
- **networks** (default:): Try and auto-create these networks first
- **rm**: (default: `false`): Remove the stack before deploying it
### Dangerous options, unwise outside CI

View File

@ -7,6 +7,7 @@ PLUGIN_HOST=${PLUGIN_HOST:-swarm.autonomic.zone}
PLUGIN_PORT=${PLUGIN_PORT:-222}
PLUGIN_PURGE=${PLUGIN_PURGE:-"false"}
PLUGIN_USER=${PLUGIN_USER:-drone}
PLUGIN_RM=${PLUGIN_RM:-"false"}
REMOTE_DOCKER_HOST="ssh://$PLUGIN_USER@$PLUGIN_HOST:$PLUGIN_PORT"
@ -67,13 +68,23 @@ run_stack_deploy() {
}
run_stack_wait() {
export DOCKER_HOST="$REMOTE_DOCKER_HOST"
export DOCKER_HOST="$REMOTE_DOCKER_HOST"
docker run --rm vitalets/docker-stack-wait-deploy \
| sed 's/True/true/' \
| bash /dev/stdin "$PLUGIN_STACK"
unset DOCKER_HOST
}
run_stack_rm() {
echo "--- start stack rm ---"
docker -H "$REMOTE_DOCKER_HOST" stack rm "$PLUGIN_STACK"
# See https://github.com/moby/moby/issues/30942#issuecomment-540699206
until [ -z "$(docker -H "$REMOTE_DOCKER_HOST" stack ps "$PLUGIN_STACK" -q)" ]; do sleep 1; done
echo "--- end stack rm ---"
}
run_purge() {
echo "--- start purge ---"
docker -H "$REMOTE_DOCKER_HOST" stack rm "$PLUGIN_STACK"
@ -100,7 +111,12 @@ run_plugin() {
generate_secrets
fi
if [ "$PLUGIN_RM" == "true" ]; then
run_stack_rm
fi
run_stack_deploy
run_stack_wait
if [ "$PLUGIN_PURGE" == "true" ]; then