-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
104 changed files
with
3,460 additions
and
2,981 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
name: 'execute_ec2' | ||
description: 'Execute commands on EC2 instance' | ||
inputs: | ||
instance_id: | ||
required: true | ||
description: "Instance ID to execute ssm commands on" | ||
command: | ||
required: true | ||
description: "Set of commands to execute on the instance" | ||
check_timeout: | ||
default: "10" | ||
description: "Timeout to check for output. After n seconds the output is printed from shell." | ||
total_timeout: | ||
description: "Total timeout for the command execution" | ||
default: "1800" | ||
|
||
outputs: | ||
cmd_result: | ||
description: "Output from executed command" | ||
value: ${{ steps.poll_output.outputs.cmd_result }} | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Execute_Command | ||
id: execute_cmd | ||
shell: bash | ||
run: | | ||
formatted_command=$(echo "${{ inputs.command }}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' -e 's/\n/ && /g') | ||
echo "Executing command: $formatted_command" | ||
COMMAND_ID=$(aws ssm send-command \ | ||
--instance-ids ${{ inputs.instance_id }} \ | ||
--document-name "AWS-RunShellScript" \ | ||
--parameters '{"commands":["'"$formatted_command"'"]}' \ | ||
--output text \ | ||
--query "Command.CommandId") | ||
echo "command_id=$COMMAND_ID" >> $GITHUB_OUTPUT | ||
continue-on-error: true | ||
|
||
- name: Poll command status and retrieve live logs | ||
id: poll_output | ||
shell: bash | ||
run: | | ||
start_time=$(date +%s) | ||
timeout=${{ inputs.total_timeout }} | ||
while true; do | ||
STATUS=$(aws ssm list-command-invocations \ | ||
--command-id ${{ steps.execute_cmd.outputs.command_id }} \ | ||
--details \ | ||
--query "CommandInvocations[0].Status" \ | ||
--output text) | ||
echo "Command Status: $STATUS" | ||
OUTPUT=$(aws ssm list-command-invocations \ | ||
--command-id ${{ steps.execute_cmd.outputs.command_id }} \ | ||
--details \ | ||
--query "CommandInvocations[0].CommandPlugins[0].Output" \ | ||
--output text) | ||
echo "Command Output: $OUTPUT" | ||
if [ "$STATUS" == "Success" ]; then | ||
echo "Command completed successfully." | ||
break | ||
elif [ "$STATUS" == "Failed" ] || [ "$STATUS" == "Cancelled" ]; then | ||
echo "Command failed with status: $STATUS" | ||
break | ||
else | ||
elapsed_time=$(( $(date +%s) - start_time )) | ||
if [ "$elapsed_time" -gt "$timeout" ]; then | ||
echo "Timeout reached. Command execution took more than $timeout seconds." | ||
exit 1 | ||
fi | ||
sleep ${{ inputs.check_timeout }} | ||
fi | ||
done | ||
echo "cmd_result=$(echo $OUTPUT)" >> $GITHUB_OUTPUT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.