171 lines
5.7 KiB
YAML
171 lines
5.7 KiB
YAML
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'
|
|
required: true
|
|
image_tags:
|
|
description: 'Space-separated list of tags to apply'
|
|
required: true
|
|
platforms:
|
|
description: 'Target platforms (e.g. linux/amd64,linux/arm64)'
|
|
required: false
|
|
default: linux/amd64
|
|
registry_server:
|
|
description: 'Registry server'
|
|
required: false
|
|
default: "niepce.petite-maison-orange.fr"
|
|
registry_user:
|
|
description: 'Registry username'
|
|
required: false
|
|
default: ${{ secrets.PMO_REGISTRY_USER }}
|
|
registry_password:
|
|
description: 'Registry password'
|
|
required: false
|
|
default: ${{ secrets.PMO_REGISTRY_PASSWORD }}
|
|
check_server:
|
|
description: 'Healthchecks.io base URL'
|
|
required: false
|
|
default: 'https://haoma.petite-maison-orange.fr'
|
|
check_uuid:
|
|
description: 'UUID of the healthcheck'
|
|
required: false
|
|
default: ''
|
|
debug:
|
|
description: 'Enable debug output'
|
|
required: false
|
|
default: false
|
|
type: boolean
|
|
|
|
runs:
|
|
using: "composite"
|
|
steps:
|
|
- 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
|
|
echo "HEALTHCHECK_ENABLED=true" >> $GITHUB_ENV
|
|
else
|
|
echo "HEALTHCHECK_ENABLED=false" >> $GITHUB_ENV
|
|
fi
|
|
|
|
- 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: "Starting multiarch build for ${{ inputs.image_name }}"
|
|
debug: ${{ inputs.debug }}
|
|
|
|
- name: Install podman
|
|
shell: bash
|
|
run: |
|
|
source "${{ github.action_path }}/../bashlib.sh"
|
|
if command -v podman >/dev/null; then
|
|
success "Already installed" "Podman is present"
|
|
else
|
|
check_command apt-get
|
|
apt-get update
|
|
apt-get -y install podman || error "Install failed" "Podman installation failed"
|
|
fi
|
|
|
|
- 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'
|
|
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: "Building OCI image for ${{ inputs.image_name }}"
|
|
debug: ${{ inputs.debug }}
|
|
|
|
- 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: log
|
|
check_message: "Image built and saved as OCI archive"
|
|
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: 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: "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 }}
|