generated from pmo-actions/healthchecks-ping
Actualiser action.yaml
This commit is contained in:
96
action.yaml
96
action.yaml
@@ -3,20 +3,24 @@ description: 'Description de l action'
|
|||||||
author: 'Eric Coissac'
|
author: 'Eric Coissac'
|
||||||
|
|
||||||
inputs:
|
inputs:
|
||||||
check_server:
|
image_name:
|
||||||
description: 'Address of the Healthchecks server'
|
description: 'name of the image'
|
||||||
required: true
|
required: true
|
||||||
check_uuid:
|
image_tags:
|
||||||
description: 'Deuxième paramètre'
|
description: 'tags added to the image'
|
||||||
required: true
|
required: true
|
||||||
check_command:
|
registry_server:
|
||||||
description: 'Command to sen to the server can be nothing, start, log or fail'
|
description: 'Address of the image registry server'
|
||||||
required: false
|
required: false
|
||||||
default: 'stop'
|
default: "niepce.petite-maison-orange.fr"
|
||||||
check_message:
|
build_command:
|
||||||
description: 'Message to log with the ping'
|
description: 'Command used to build the image (docker|podman)'
|
||||||
required: false
|
required: false
|
||||||
default: ''
|
default: docker
|
||||||
|
tag_command:
|
||||||
|
description: 'Command used to tag the image (docker|podman)'
|
||||||
|
required: false
|
||||||
|
default: podman
|
||||||
debug:
|
debug:
|
||||||
description: 'Run the action in debug mode'
|
description: 'Run the action in debug mode'
|
||||||
required: false
|
required: false
|
||||||
@@ -36,54 +40,46 @@ runs:
|
|||||||
echo "DEBUG=ON" >> $GITEA_ENV
|
echo "DEBUG=ON" >> $GITEA_ENV
|
||||||
debug Debug switch on
|
debug Debug switch on
|
||||||
|
|
||||||
- name: Ping the server
|
- name: Build the image
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
source "${{ github.action_path }}/bashlib.sh"
|
source "${{ github.action_path }}/bashlib.sh"
|
||||||
|
|
||||||
check_command curl
|
check_command ${{ inputs.build_command }}
|
||||||
|
|
||||||
SERVER="${{ inputs.check_server }}"
|
tags=(${{ inputs.image_tags }})
|
||||||
HEALTHPOINT="${{ inputs.check_server }}/ping/${{ inputs.check_uuid }}"
|
sep=""
|
||||||
OPTIONS="-fsS -m 10 --retry 5"
|
if [[ -n "${tags[0]}" ]] ; then
|
||||||
MESSAGE="${{ inputs.check_message }}"
|
sep=":"
|
||||||
COMMAND="${{ inputs.check_command }}"
|
fi
|
||||||
|
|
||||||
CURL_DATA=()
|
image=${{ inputs.registry_server }}/${{ inputs.image_name }}${sep}${tags[0]}
|
||||||
if [[ -n "$MESSAGE" ]]; then
|
${{ inputs.build_command }} build -t ${image} . \
|
||||||
CURL_DATA+=(--data-raw "$MESSAGE")
|
|| error "Failed" "Cannot built the image ${{ inputs.image_name }}" \
|
||||||
|
&& success "Image build" "${{ inputs.image_name }}"
|
||||||
|
|
||||||
|
-name: tag images
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
source "${{ github.action_path }}/bashlib.sh"
|
||||||
|
tags=(${{ inputs.image_tags }})
|
||||||
|
|
||||||
|
check_command ${{ inputs.tag_command }}
|
||||||
|
|
||||||
|
image=${{ inputs.registry_server }}/${{ inputs.image_name }}${sep}${tags[0]}
|
||||||
|
|
||||||
|
if [[ "${{ inputs.build_command }}" != "${{ inputs.tag_command }}" ]] ; then
|
||||||
|
${{ inputs.build_command }} save ${image} -o $$.image.tar
|
||||||
|
${{ inputs.tag_command }} load -i $$.image.tar
|
||||||
|
rm -f $$.image.tar
|
||||||
fi
|
fi
|
||||||
|
|
||||||
case "$COMMAND" in
|
for tag in "${tags[@]:1}" ; do
|
||||||
start|log|fail)
|
${{ inputs.tag_command }} tag ${image} \
|
||||||
URL="${HEALTHPOINT}/$COMMAND"
|
${{ inputs.registry_server }}/${{ inputs.image_name }}:${tag} \
|
||||||
;;
|
|| error "Failed" "tagging of image ${{ inputs.image_name }}:${tag}" \
|
||||||
|
&& success "Image tagging" "${{ inputs.registry_server }}/${{ inputs.image_name }}:${tag}"
|
||||||
stop)
|
done
|
||||||
URL="${HEALTHPOINT}"
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
error Error "Invalid command: $COMMAND (must be start|log|fail|stop)"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
curl_cmd=(
|
|
||||||
curl
|
|
||||||
$OPTIONS
|
|
||||||
"${CURL_DATA[@]}"
|
|
||||||
"$URL"
|
|
||||||
)
|
|
||||||
|
|
||||||
debug "Run command" "${curl_cmd[*]}"
|
|
||||||
|
|
||||||
result=$("${curl_cmd[@]}") \
|
|
||||||
&& success "Success" "$COMMAND ping sent to ${SERVER}" \
|
|
||||||
|| error "Error" "$COMMAND ping to ${SERVER} failed ${result}"
|
|
||||||
|
|
||||||
if [[ "$COMMAND" == "fail" ]] ; then
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
exit 0
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user