Ajouter action.yaml
This commit is contained in:
160
action.yaml
Normal file
160
action.yaml
Normal file
@@ -0,0 +1,160 @@
|
||||
name: build-push-multiarch-image
|
||||
description: Build multiarch OCI image with buildx and push with podman, with healthchecks support
|
||||
|
||||
inputs:
|
||||
image_name:
|
||||
description: 'name of the image'
|
||||
required: true
|
||||
image_tags:
|
||||
description: 'tags added to the image'
|
||||
required: true
|
||||
add_version_tag:
|
||||
description: 'should I add a tag corresponding to the version of the packaged software'
|
||||
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
|
||||
registry_server:
|
||||
description: 'Address of the image registry server'
|
||||
required: false
|
||||
default: "niepce.petite-maison-orange.fr"
|
||||
registry_user:
|
||||
description: 'User used for the connection to the image registry'
|
||||
required: false
|
||||
default: ${{ secrets.PMO_REGISTRY_USER }}
|
||||
registry_password:
|
||||
description: 'Password used for the connection to the image registry'
|
||||
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'
|
||||
required: false
|
||||
default: 'https://haoma.petite-maison-orange.fr'
|
||||
check_uuid:
|
||||
description: 'Deuxième paramètre'
|
||||
required: false
|
||||
default: ''
|
||||
debug:
|
||||
description: 'Run the action in debug mode'
|
||||
required: false
|
||||
default: false
|
||||
type: boolean
|
||||
|
||||
runs:
|
||||
using: 'composite'
|
||||
steps:
|
||||
- name: Set healthcheck enabled 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: Start job
|
||||
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 }}'
|
||||
debug: ${{ inputs.debug }}
|
||||
|
||||
- name: Build image with buildx
|
||||
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"
|
||||
else
|
||||
echo "Build failed" >&2
|
||||
exit 1
|
||||
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
|
||||
shell: bash
|
||||
run: |
|
||||
set -e
|
||||
image_base="${{ inputs.registry_server }}/${{ inputs.image_name }}"
|
||||
tags=(${{ inputs.image_tags }})
|
||||
|
||||
# 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'
|
||||
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 }}'
|
||||
debug: ${{ inputs.debug }}
|
||||
|
||||
- name: Notify job failed
|
||||
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: 'Job failed for ${{ inputs.image_name }}'
|
||||
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: Notify job done
|
||||
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 }}'
|
||||
debug: ${{ inputs.debug }}
|
||||
Reference in New Issue
Block a user