Actualiser action.yaml

This commit is contained in:
2025-04-14 11:16:56 +02:00
parent 5a9adae3b2
commit 6db4aa4aa9

View File

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