Files

166 lines
5.5 KiB
YAML
Raw Permalink Normal View History

2025-06-12 18:46:57 +02:00
name: 'build-pushx-image'
description: 'Builds multi-arch OCI image with buildx and pushes with podman, reporting to Healthchecks.io'
author: 'Eric Coissac'
2025-06-12 18:41:54 +02:00
inputs:
image_name:
2025-06-12 18:46:57 +02:00
description: 'Name of the image'
2025-06-12 18:41:54 +02:00
required: true
image_tags:
2025-06-12 18:46:57 +02:00
description: 'Space-separated list of tags to apply'
2025-06-12 18:41:54 +02:00
required: true
2025-06-12 18:46:57 +02:00
platforms:
description: 'Target platforms (e.g. linux/amd64,linux/arm64)'
2025-06-12 18:41:54 +02:00
required: false
2025-06-12 18:46:57 +02:00
default: linux/amd64
2025-06-12 18:41:54 +02:00
registry_server:
2025-06-12 18:46:57 +02:00
description: 'Registry server'
2025-06-12 18:41:54 +02:00
required: false
default: "niepce.petite-maison-orange.fr"
registry_user:
2025-06-12 18:46:57 +02:00
description: 'Registry username'
2025-06-12 18:41:54 +02:00
required: false
default: ${{ secrets.PMO_REGISTRY_USER }}
registry_password:
2025-06-12 18:46:57 +02:00
description: 'Registry password'
2025-06-12 18:41:54 +02:00
required: false
default: ${{ secrets.PMO_REGISTRY_PASSWORD }}
check_server:
2025-06-12 18:46:57 +02:00
description: 'Healthchecks.io base URL'
2025-06-12 18:41:54 +02:00
required: false
default: 'https://haoma.petite-maison-orange.fr'
check_uuid:
2025-06-12 18:46:57 +02:00
description: 'UUID of the healthcheck'
2025-06-12 18:41:54 +02:00
required: false
default: ''
debug:
2025-06-12 18:46:57 +02:00
description: 'Enable debug output'
2025-06-12 18:41:54 +02:00
required: false
default: false
type: boolean
runs:
2025-06-12 18:46:57 +02:00
using: "composite"
2025-06-12 18:41:54 +02:00
steps:
2025-06-12 18:46:57 +02:00
- 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
2025-06-12 18:41:54 +02:00
shell: bash
run: |
if [[ "${{ inputs.check_server }}" != "" && "${{ inputs.check_uuid }}" != "" ]]; then
echo "HEALTHCHECK_ENABLED=true" >> $GITHUB_ENV
else
echo "HEALTHCHECK_ENABLED=false" >> $GITHUB_ENV
fi
2025-06-12 18:46:57 +02:00
- name: Healthcheck start
2025-06-12 18:41:54 +02:00
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
2025-06-12 18:46:57 +02:00
check_message: "Starting multiarch build for ${{ inputs.image_name }}"
2025-06-12 18:41:54 +02:00
debug: ${{ inputs.debug }}
2025-12-26 15:16:57 +01:00
- name: Install Podman
uses: https://gargoton.petite-maison-orange.fr/pmo-actions/install-container-tools@main
with:
tools: podman
debug: ${{ inputs.debug }}
2025-06-12 18:41:54 +02:00
2025-12-26 15:16:57 +01:00
2025-06-12 18:46:57 +02:00
- name: Login to registry with podman
shell: bash
run: |
echo "${{ inputs.registry_password }}" | podman login \
--username "${{ inputs.registry_user }}" \
--password-stdin \
"${{ inputs.registry_server }}"
- name: Healthcheck build step
if: env.HEALTHCHECK_ENABLED == 'true'
2025-06-12 18:41:54 +02:00
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
2025-06-12 18:46:57 +02:00
check_message: "Building OCI image for ${{ inputs.image_name }}"
2025-06-12 18:41:54 +02:00
debug: ${{ inputs.debug }}
2025-06-12 18:46:57 +02:00
- name: Build multiarch image with buildx
2025-06-12 18:41:54 +02:00
shell: bash
run: |
2025-06-12 18:46:57 +02:00
source "${{ github.action_path }}/../bashlib.sh"
mkdir -p oci_image
2025-06-12 18:41:54 +02:00
2025-06-12 18:46:57 +02:00
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}" \
.
2025-06-12 18:41:54 +02:00
done
2025-06-12 18:46:57 +02:00
- name: Healthcheck image built
if: env.HEALTHCHECK_ENABLED == 'true'
2025-06-12 18:41:54 +02:00
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
2025-06-12 18:46:57 +02:00
check_message: "Image built and saved as OCI archive"
2025-06-12 18:41:54 +02:00
debug: ${{ inputs.debug }}
2025-06-12 18:46:57 +02:00
- 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: Healthcheck success
if: env.HEALTHCHECK_ENABLED == 'true'
2025-06-12 18:41:54 +02:00
uses: https://gargoton.petite-maison-orange.fr/pmo-actions/healthchecks-ping@main
with:
check_server: ${{ inputs.check_server }}
check_uuid: ${{ inputs.check_uuid }}
2025-06-12 18:46:57 +02:00
check_command: stop
check_message: "Push complete for ${{ inputs.image_name }}"
2025-06-12 18:41:54 +02:00
debug: ${{ inputs.debug }}
2025-06-12 18:46:57 +02:00
- name: Healthcheck failure
if: failure() && env.HEALTHCHECK_ENABLED == 'true'
2025-06-12 18:41:54 +02:00
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
2025-06-12 18:46:57 +02:00
check_message: "Build or push failed for ${{ inputs.image_name }}"
2025-06-12 18:41:54 +02:00
debug: ${{ inputs.debug }}
2025-06-12 18:46:57 +02:00
- name: Healthcheck cancelled
if: cancelled() && env.HEALTHCHECK_ENABLED == 'true'
2025-06-12 18:41:54 +02:00
uses: https://gargoton.petite-maison-orange.fr/pmo-actions/healthchecks-ping@main
with:
check_server: ${{ inputs.check_server }}
check_uuid: ${{ inputs.check_uuid }}
2025-06-12 18:46:57 +02:00
check_command: fail
check_message: "Cancelled: build for ${{ inputs.image_name }}"
2025-06-12 18:41:54 +02:00
debug: ${{ inputs.debug }}