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