diff --git a/action.yml b/action.yml index f667612..8f01301 100644 --- a/action.yml +++ b/action.yml @@ -25,8 +25,14 @@ inputs: description: Use swarm mode instead of docker compose default: "false" required: true + custom_container_action: + description: "Run a custom action" + required: false + custom_container_action_target: + description: "Target container for action" + required: false action: - description: Action, i.e., "up" or "down" + description: Action, i.e., "up" or "down", or "custom" default: "up" required: true docker_compose_project: @@ -49,3 +55,5 @@ runs: DOCKER_COMPOSE_FILENAME: ${{ inputs.docker_compose_filename }} DEPLOY_ACTION: ${{ inputs.action }} SWARM_MODE: ${{ inputs.swarm_mode }} + CUSTOM_ACTION: ${{ inputs.custom_container_action }} + CUSTOM_ACTION_TARGET: ${{ inputs.custom_container_action_target }} diff --git a/entrypoint.sh b/entrypoint.sh index af10996..c99fe2c 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -52,6 +52,9 @@ stack_down() { # It is not at all necessary to transfer and unpack the workspace here, but I'll do it anyway for simplicity's sake. echo "set -e ; log() { echo '>> [remote]' \$@ ; } ; cleanup() { log 'Removing workspace...'; rm -rf \"\$HOME/workspace\" ; } ; log 'Creating workspace directory...' ; mkdir -p \"\$HOME/workspace/$DOCKER_COMPOSE_PROJECT\" ; trap cleanup EXIT ; log 'Unpacking workspace...' ; tar -C \"\$HOME/workspace/$DOCKER_COMPOSE_PROJECT\" -xjv ; log 'Launching docker stack rm...' ; cd \"\$HOME/workspace/$DOCKER_COMPOSE_PROJECT\" ; docker stack rm \"$DOCKER_COMPOSE_PROJECT\"" } +custom_action() { + echo "set -e ; log() { echo '>> [remote]' \$@ ; } ; cleanup() { log 'Removing workspace...'; rm -rf \"\$HOME/workspace\" ; } ; log 'Creating workspace directory...' ; mkdir -p \"\$HOME/workspace\" ; trap cleanup EXIT ; log 'Unpacking workspace...' ; tar -C \"\$HOME/workspace\" -xjv ; log 'Launching docker compose...' ; cd \"\$HOME/workspace\" ; docker compose -f \"$DOCKER_COMPOSE_FILENAME\" -p \"$DOCKER_COMPOSE_PROJECT\" pull ; docker compose -f \"$DOCKER_COMPOSE_FILENAME\" -p \"$DOCKER_COMPOSE_PROJECT\" run --rm \"$CUSTOM_ACTION_TARGET\" \"$CUSTOM_ACTION\"" +} deploy() { local remote_command @@ -67,9 +70,19 @@ deploy() { if [ "$DEPLOY_ACTION" == "up" ]; then log "Deploying docker compose project ${DOCKER_COMPOSE_PROJECT}." remote_command=$(compose_up) - else + elif [ "$DEPLOY_ACTION" == "down" ]; then log "Removing docker compose project ${DOCKER_COMPOSE_PROJECT}." remote_command=$(compose_down) + elif [ "$DEPLOY_ACTION" == "custom" ]; then + if [ -z "$CUSTOM_ACTION" ] || [ -z "$CUSTOM_ACTION_TARGET" ]; then + echo "ERROR: You must set custom_container_action and custom_container_action_target" + exit 1 + fi + log "Running custom action on project ${DOCKER_COMPOSE_PROJECT}:" + log "Action: ${CUSTOM_ACTION}" + log "Target: ${CUSTOM_ACTION_TARGET}" + remote_command=$(custom_action) + fi fi ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \