Actualiser action.yaml

This commit is contained in:
2025-06-12 18:46:57 +02:00
parent ad46658b99
commit 11157b87be

View File

@@ -1,59 +1,60 @@
name: build-push-multiarch-image name: 'build-pushx-image'
description: Build multiarch OCI image with buildx and push with podman, with healthchecks support description: 'Builds multi-arch OCI image with buildx and pushes with podman, reporting to Healthchecks.io'
author: 'Eric Coissac'
inputs: inputs:
image_name: image_name:
description: 'name of the image' description: 'Name of the image'
required: true required: true
image_tags: image_tags:
description: 'tags added to the image' description: 'Space-separated list of tags to apply'
required: true required: true
add_version_tag: platforms:
description: 'should I add a tag corresponding to the version of the packaged software' description: 'Target platforms (e.g. linux/amd64,linux/arm64)'
required: false required: false
default: true default: linux/amd64
version_tag_prefix:
description: 'Prefix added to the version to build the version tag'
required: false
default: 'pmo'
no_cache:
description: 'Do we desactivate cache during image duilding'
required: false
default: false
registry_server: registry_server:
description: 'Address of the image registry server' description: 'Registry server'
required: false required: false
default: "niepce.petite-maison-orange.fr" default: "niepce.petite-maison-orange.fr"
registry_user: registry_user:
description: 'User used for the connection to the image registry' description: 'Registry username'
required: false required: false
default: ${{ secrets.PMO_REGISTRY_USER }} default: ${{ secrets.PMO_REGISTRY_USER }}
registry_password: registry_password:
description: 'Password used for the connection to the image registry' description: 'Registry password'
required: false required: false
default: ${{ secrets.PMO_REGISTRY_PASSWORD }} default: ${{ secrets.PMO_REGISTRY_PASSWORD }}
version_file:
description: 'Name of the file containing the version number'
required: false
default: 'software_version.txt'
check_server: check_server:
description: 'Address of the Healthchecks server' description: 'Healthchecks.io base URL'
required: false required: false
default: 'https://haoma.petite-maison-orange.fr' default: 'https://haoma.petite-maison-orange.fr'
check_uuid: check_uuid:
description: 'Deuxième paramètre' description: 'UUID of the healthcheck'
required: false required: false
default: '' default: ''
debug: debug:
description: 'Run the action in debug mode' description: 'Enable debug output'
required: false required: false
default: false default: false
type: boolean type: boolean
runs: runs:
using: 'composite' using: "composite"
steps: steps:
- name: Set healthcheck enabled flag - name: Load bash library
uses: https://gargoton.petite-maison-orange.fr/pmo-actions/bash-library@main
- name: Enable debug
if: inputs.debug == 'true'
shell: bash
run: |
export DEBUG=ON
echo "DEBUG=ON" >> $GITHUB_ENV
source "${{ github.action_path }}/../bashlib.sh"
debug "Debug mode enabled"
- name: Set healthcheck flag
shell: bash shell: bash
run: | run: |
if [[ "${{ inputs.check_server }}" != "" && "${{ inputs.check_uuid }}" != "" ]]; then if [[ "${{ inputs.check_server }}" != "" && "${{ inputs.check_uuid }}" != "" ]]; then
@@ -62,99 +63,108 @@ runs:
echo "HEALTHCHECK_ENABLED=false" >> $GITHUB_ENV echo "HEALTHCHECK_ENABLED=false" >> $GITHUB_ENV
fi fi
- name: Start job - name: Healthcheck start
if: env.HEALTHCHECK_ENABLED == 'true' if: env.HEALTHCHECK_ENABLED == 'true'
uses: https://gargoton.petite-maison-orange.fr/pmo-actions/healthchecks-ping@main uses: https://gargoton.petite-maison-orange.fr/pmo-actions/healthchecks-ping@main
with: with:
check_server: ${{ inputs.check_server }} check_server: ${{ inputs.check_server }}
check_uuid: ${{ inputs.check_uuid }} check_uuid: ${{ inputs.check_uuid }}
check_command: start check_command: start
check_message: 'Start building multiarch image for ${{ inputs.image_name }}' check_message: "Starting multiarch build for ${{ inputs.image_name }}"
debug: ${{ inputs.debug }} debug: ${{ inputs.debug }}
- name: Build image with buildx - name: Install podman
shell: bash shell: bash
run: | run: |
set -e source "${{ github.action_path }}/../bashlib.sh"
image_base="${{ inputs.registry_server }}/${{ inputs.image_name }}" if command -v podman >/dev/null; then
tag="$(echo ${{ inputs.image_tags }} | cut -d' ' -f1)" success "Already installed" "Podman is present"
buildx_tag="${image_base}:${tag}"
if docker buildx build --platform "${{ inputs.platforms }}" --file "${{ inputs.dockerfile }}" --output=type=oci,dest=image.oci -t "${buildx_tag}" "${{ inputs.context }}" ; then
echo "Build succeeded"
else else
echo "Build failed" >&2 check_command apt-get
exit 1 apt-get update
apt-get -y install podman || error "Install failed" "Podman installation failed"
fi fi
# Pas besoin de healthcheck ping ici, on le fait dans les étapes suivantes
- name: Notify build succeeded - name: Login to registry with podman
if: success() && env.HEALTHCHECK_ENABLED == 'true'
uses: https://gargoton.petite-maison-orange.fr/pmo-actions/healthchecks-ping@main
with:
check_server: ${{ inputs.check_server }}
check_uuid: ${{ inputs.check_uuid }}
check_command: log
check_message: 'Build finished for ${{ inputs.image_name }}'
debug: ${{ inputs.debug }}
- name: Push image with podman
shell: bash shell: bash
run: | run: |
set -e echo "${{ inputs.registry_password }}" | podman login \
image_base="${{ inputs.registry_server }}/${{ inputs.image_name }}" --username "${{ inputs.registry_user }}" \
tags=(${{ inputs.image_tags }}) --password-stdin \
"${{ inputs.registry_server }}"
# Login si demandé - name: Healthcheck build step
if [[ "${{ inputs.registry_user }}" != "" ]]; then if: env.HEALTHCHECK_ENABLED == 'true'
podman login "${{ inputs.registry_server }}" -u "${{ inputs.registry_user }}" -p "${{ inputs.registry_password }}"
fi
# Charger image OCI locale
podman load -i image.oci
# Pousser chaque tag
for tag in "${tags[@]}"; do
podman push "${{ inputs.registry_server }}/${{ inputs.image_name }}:${tag}"
done
# Pareil, pas de healthcheck ici
- name: Notify push succeeded
if: success() && env.HEALTHCHECK_ENABLED == 'true'
uses: https://gargoton.petite-maison-orange.fr/pmo-actions/healthchecks-ping@main uses: https://gargoton.petite-maison-orange.fr/pmo-actions/healthchecks-ping@main
with: with:
check_server: ${{ inputs.check_server }} check_server: ${{ inputs.check_server }}
check_uuid: ${{ inputs.check_uuid }} check_uuid: ${{ inputs.check_uuid }}
check_command: log check_command: log
check_message: 'Push finished for ${{ inputs.image_name }}' check_message: "Building OCI image for ${{ inputs.image_name }}"
debug: ${{ inputs.debug }} debug: ${{ inputs.debug }}
- name: Notify job failed - name: Build multiarch image with buildx
if: failure() && env.HEALTHCHECK_ENABLED == 'true' shell: bash
run: |
source "${{ github.action_path }}/../bashlib.sh"
mkdir -p oci_image
for tag in ${{ inputs.image_tags }}; do
step "Building image" "Tag: $tag"
docker buildx build \
--platform ${{ inputs.platforms }} \
--output=type=oci,dest=oci_image/${tag}.tar \
--tag "${{ inputs.registry_server }}/${{ inputs.image_name }}:${tag}" \
.
done
- name: Healthcheck image built
if: env.HEALTHCHECK_ENABLED == 'true'
uses: https://gargoton.petite-maison-orange.fr/pmo-actions/healthchecks-ping@main uses: https://gargoton.petite-maison-orange.fr/pmo-actions/healthchecks-ping@main
with: with:
check_server: ${{ inputs.check_server }} check_server: ${{ inputs.check_server }}
check_uuid: ${{ inputs.check_uuid }} check_uuid: ${{ inputs.check_uuid }}
check_command: fail check_command: log
check_message: 'Job failed for ${{ inputs.image_name }}' check_message: "Image built and saved as OCI archive"
debug: ${{ inputs.debug }} debug: ${{ inputs.debug }}
- name: Notify job cancelled - name: Push images with podman
if: cancelled() && env.HEALTHCHECK_ENABLED == 'true' shell: bash
uses: https://gargoton.petite-maison-orange.fr/pmo-actions/healthchecks-ping@main run: |
with: source "${{ github.action_path }}/../bashlib.sh"
check_server: ${{ inputs.check_server }} for tag in ${{ inputs.image_tags }}; do
check_uuid: ${{ inputs.check_uuid }} step "Pushing image" "Tag: $tag"
check_command: fail podman push \
check_message: 'Job cancelled for ${{ inputs.image_name }}' oci-archive:oci_image/${tag}.tar \
debug: ${{ inputs.debug }} docker://${{ inputs.registry_server }}/${{ inputs.image_name }}:${tag}
done
- name: Notify job done - name: Healthcheck success
if: env.HEALTHCHECK_ENABLED == 'true' if: env.HEALTHCHECK_ENABLED == 'true'
uses: https://gargoton.petite-maison-orange.fr/pmo-actions/healthchecks-ping@main uses: https://gargoton.petite-maison-orange.fr/pmo-actions/healthchecks-ping@main
with: with:
check_server: ${{ inputs.check_server }} check_server: ${{ inputs.check_server }}
check_uuid: ${{ inputs.check_uuid }} check_uuid: ${{ inputs.check_uuid }}
check_command: stop check_command: stop
check_message: 'Job done for ${{ inputs.image_name }}' check_message: "Push complete for ${{ inputs.image_name }}"
debug: ${{ inputs.debug }}
- name: Healthcheck failure
if: failure() && env.HEALTHCHECK_ENABLED == 'true'
uses: https://gargoton.petite-maison-orange.fr/pmo-actions/healthchecks-ping@main
with:
check_server: ${{ inputs.check_server }}
check_uuid: ${{ inputs.check_uuid }}
check_command: fail
check_message: "Build or push failed for ${{ inputs.image_name }}"
debug: ${{ inputs.debug }}
- name: Healthcheck cancelled
if: cancelled() && env.HEALTHCHECK_ENABLED == 'true'
uses: https://gargoton.petite-maison-orange.fr/pmo-actions/healthchecks-ping@main
with:
check_server: ${{ inputs.check_server }}
check_uuid: ${{ inputs.check_uuid }}
check_command: fail
check_message: "Cancelled: build for ${{ inputs.image_name }}"
debug: ${{ inputs.debug }} debug: ${{ inputs.debug }}