3 Commits
v3 ... main

Author SHA1 Message Date
ad80faf177 Try other variation with quotes 2024-11-03 14:25:46 +01:00
b7354a0c33 Try without quotes 2024-11-03 14:13:49 +01:00
428522f85d Support custom actions 2024-11-03 13:27:34 +01:00
2 changed files with 23 additions and 2 deletions

View File

@ -25,8 +25,14 @@ inputs:
description: Use swarm mode instead of docker compose description: Use swarm mode instead of docker compose
default: "false" default: "false"
required: true required: true
custom_container_action:
description: "Run a custom action"
required: false
custom_container_action_target:
description: "Target container for action"
required: false
action: action:
description: Action, i.e., "up" or "down" description: Action, i.e., "up" or "down", or "custom"
default: "up" default: "up"
required: true required: true
docker_compose_project: docker_compose_project:
@ -49,3 +55,5 @@ runs:
DOCKER_COMPOSE_FILENAME: ${{ inputs.docker_compose_filename }} DOCKER_COMPOSE_FILENAME: ${{ inputs.docker_compose_filename }}
DEPLOY_ACTION: ${{ inputs.action }} DEPLOY_ACTION: ${{ inputs.action }}
SWARM_MODE: ${{ inputs.swarm_mode }} SWARM_MODE: ${{ inputs.swarm_mode }}
CUSTOM_ACTION: ${{ inputs.custom_container_action }}
CUSTOM_ACTION_TARGET: ${{ inputs.custom_container_action_target }}

View File

@ -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. # 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\"" 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\" run --rm $CUSTOM_ACTION_TARGET $CUSTOM_ACTION"
}
deploy() { deploy() {
local remote_command local remote_command
@ -67,9 +70,19 @@ deploy() {
if [ "$DEPLOY_ACTION" == "up" ]; then if [ "$DEPLOY_ACTION" == "up" ]; then
log "Deploying docker compose project ${DOCKER_COMPOSE_PROJECT}." log "Deploying docker compose project ${DOCKER_COMPOSE_PROJECT}."
remote_command=$(compose_up) remote_command=$(compose_up)
else elif [ "$DEPLOY_ACTION" == "down" ]; then
log "Removing docker compose project ${DOCKER_COMPOSE_PROJECT}." log "Removing docker compose project ${DOCKER_COMPOSE_PROJECT}."
remote_command=$(compose_down) 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
fi fi
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \ ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \