From 4df177e25c0105afa9ba7ab691c3553178a6ddce Mon Sep 17 00:00:00 2001 From: 3wc <3wc@doesthisthing.work> Date: Fri, 10 Dec 2021 22:22:35 +0200 Subject: [PATCH] Add `exec` option (for composer) --- README.md | 3 ++- plugin.sh | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b59110f..991f124 100644 --- a/README.md +++ b/README.md @@ -18,10 +18,11 @@ - **host** (default: `swarm.autonomic.zone`): Host to deploy to (don't include `ssh://`) - **port** (default: `222`): SSH port to connect to - **user** (default: `drone`): System user to connect via SSH with +- **exec** (default: none): Run a command in the container after copying ### Makes me sad they exist -- **chdir** (default: none): Add `-C` option to `tar` +- **chdir** (default: none): Add `-C` option to `tar`; i.e. change to a directory first ## Example diff --git a/plugin.sh b/plugin.sh index 679d694..dc00ab6 100755 --- a/plugin.sh +++ b/plugin.sh @@ -31,6 +31,7 @@ output_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) @@ -48,9 +49,13 @@ run_docker_cp() { 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