2025-04-14 16:02:21 +02:00
|
|
|
name: 'build-push-image'
|
|
|
|
|
description: 'Builds a container image, tags it, pushes to registry, and reports status to Healthchecks.io'
|
2025-04-14 14:29:16 +02:00
|
|
|
author: 'Eric Coissac'
|
|
|
|
|
|
|
|
|
|
inputs:
|
2025-04-14 15:09:53 +02:00
|
|
|
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
|
|
|
|
|
build_command:
|
|
|
|
|
description: 'Command used to build the image (docker|podman)'
|
|
|
|
|
required: false
|
|
|
|
|
default: docker
|
|
|
|
|
tag_command:
|
|
|
|
|
description: 'Command used to tag the image (docker|podman)'
|
|
|
|
|
required: false
|
|
|
|
|
default: podman
|
|
|
|
|
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'
|
2025-04-14 14:29:16 +02:00
|
|
|
check_server:
|
|
|
|
|
description: 'Address of the Healthchecks server'
|
2025-04-14 15:09:53 +02:00
|
|
|
required: false
|
|
|
|
|
default: 'https://haoma.petite-maison-orange.fr'
|
2025-04-14 14:29:16 +02:00
|
|
|
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: Load bash library
|
|
|
|
|
uses: https://gargoton.petite-maison-orange.fr/pmo-actions/bash-library@main
|
2025-04-14 15:09:53 +02:00
|
|
|
|
2025-04-14 16:10:10 +02:00
|
|
|
- name: Set debug mode
|
2025-04-14 16:12:10 +02:00
|
|
|
if: inputs.debug == 'true'
|
2025-04-14 16:10:10 +02:00
|
|
|
shell: bash
|
|
|
|
|
run: |
|
|
|
|
|
source "${{ github.action_path }}/../bashlib.sh"
|
|
|
|
|
export DEBUG="ON"
|
|
|
|
|
echo "DEBUG=ON" >> $GITHUB_ENV
|
|
|
|
|
debug Debug switch on
|
2025-04-14 16:10:54 +02:00
|
|
|
|
|
|
|
|
- name: Start the job
|
|
|
|
|
if: inputs.check_server != '' && inputs.check_uuid != ''
|
|
|
|
|
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 job for image ${{ inputs.image_name }}'
|
|
|
|
|
debug: ${{ inputs.debug }}
|
2025-04-14 16:13:39 +02:00
|
|
|
|
|
|
|
|
- name: Checkout and get version
|
|
|
|
|
id: get_version
|
|
|
|
|
uses: https://gargoton.petite-maison-orange.fr/pmo-actions/software-version@main
|
|
|
|
|
with:
|
|
|
|
|
git_checkout: true
|
|
|
|
|
version_file: ${{ inputs.version_file }}
|
|
|
|
|
debug: ${{ inputs.debug }}
|
|
|
|
|
|
2025-04-14 16:16:03 +02:00
|
|
|
- name: install podman
|
|
|
|
|
if: inputs.build_command == 'podman' || inputs.tag_command == 'podman'
|
|
|
|
|
shell: bash
|
|
|
|
|
run: |
|
|
|
|
|
source "${{ github.action_path }}/../bashlib.sh"
|
|
|
|
|
step "Install software" "podman"
|
|
|
|
|
|
|
|
|
|
if command -v podman >/dev/null 2>&1; then
|
|
|
|
|
success "Already installed" "Podman found"
|
|
|
|
|
exit 0
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
check_command apt-get
|
|
|
|
|
|
|
|
|
|
apt-get update
|
|
|
|
|
|
|
|
|
|
if apt-get -y install podman ; then
|
|
|
|
|
success "Success" "Podman installed"
|
|
|
|
|
else
|
|
|
|
|
error "Install failed" "Could not install Podman"
|
|
|
|
|
fi
|
|
|
|
|
|
2025-04-14 16:17:57 +02:00
|
|
|
- name: Build image starting
|
|
|
|
|
if: inputs.check_server != '' && inputs.check_uuid != ''
|
|
|
|
|
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: 'Buildind docker image for ${{ steps.get_version.outputs.version }}'
|
|
|
|
|
debug: ${{ inputs.debug }}
|
2025-04-14 16:20:49 +02:00
|
|
|
|
|
|
|
|
- name: Store tag version
|
|
|
|
|
shell: bash
|
|
|
|
|
run: |
|
|
|
|
|
echo "IMAGE_TAGS=${{ inputs.image_tags }}" >> $GITHUB_ENV
|
|
|
|
|
|
2025-04-14 16:23:42 +02:00
|
|
|
- name: Add PMO version tag
|
|
|
|
|
if: inputs.add_version_tag
|
|
|
|
|
run: |
|
|
|
|
|
source "${{ github.action_path }}/../bashlib.sh"
|
|
|
|
|
echo "IMAGE_TAGS=${{ env.IMAGE_TAGS }} pmo-${{ steps.get_version.outputs.version }}" >> $GITHUB_ENV
|
|
|
|
|
|
2025-04-14 16:27:12 +02:00
|
|
|
- name: Build and tag image
|
|
|
|
|
uses: https://gargoton.petite-maison-orange.fr/pmo-actions/build-image@main
|
|
|
|
|
with:
|
|
|
|
|
image_name: '${{ inputs.image_name }}'
|
|
|
|
|
image_tags: '${{ env.IMAGE_TAGS }}'
|
|
|
|
|
registry_server: '${{ inputs.registry_server }}'
|
|
|
|
|
build_command: '${{ inputs.build_command }}'
|
|
|
|
|
tag_command: '${{ inputs.tag_command }}'
|
|
|
|
|
debug: ${{ inputs.debug }}
|
|
|
|
|
|
2025-04-14 16:31:02 +02:00
|
|
|
- name: Canceled building
|
|
|
|
|
if: cancelled() && inputs.check_server != '' && inputs.check_uuid != ''
|
|
|
|
|
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: 'Building image cancelled for ${{ inputs.image_name }}'
|
|
|
|
|
debug: ${{ inputs.debug }}
|
|
|
|
|
|
|
|
|
|
- name: Build image failed
|
|
|
|
|
if: failure() && inputs.check_server != '' && inputs.check_uuid != ''
|
|
|
|
|
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: 'Failed to build docker image for ${{ inputs.image_name }}'
|
|
|
|
|
debug: ${{ inputs.debug }}
|
|
|
|
|
|
|
|
|
|
- name: Image built and tagged
|
|
|
|
|
if: inputs.check_server != '' && inputs.check_uuid != ''
|
|
|
|
|
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: 'Docker image for ${{ inputs.image_name }} built and tagged'
|
|
|
|
|
debug: ${{ inputs.debug }}
|
|
|
|
|
|
2025-04-14 16:33:53 +02:00
|
|
|
- name: Push image to registry
|
|
|
|
|
uses: https://gargoton.petite-maison-orange.fr/pmo-actions/push-image@main
|
|
|
|
|
with:
|
|
|
|
|
registry_login: true
|
|
|
|
|
image_name: '${{ inputs.image_name }}'
|
|
|
|
|
image_tags: '${{ env.IMAGE_TAGS }}'
|
|
|
|
|
registry_server: '${{ inputs.registry_server }}'
|
|
|
|
|
registry_user: '${{ inputs.registry_user }}'
|
|
|
|
|
registry_password: '${{ inputs.registry_password }}'
|
|
|
|
|
push_command: '${{ inputs.tag_command }}'
|
|
|
|
|
debug: ${{ inputs.debug }}
|
2025-04-14 16:23:42 +02:00
|
|
|
|
2025-04-14 16:45:51 +02:00
|
|
|
- name: Push image failed
|
|
|
|
|
if: failure() && inputs.check_server != '' && inputs.check_uuid != ''
|
|
|
|
|
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: 'Failed to push docker image for ${{ inputs.image_name }}'
|
|
|
|
|
debug: ${{ inputs.debug }}
|
|
|
|
|
|
|
|
|
|
- name: End of the image building
|
|
|
|
|
if: inputs.check_server != '' && inputs.check_uuid != ''
|
|
|
|
|
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: 'Docker image for ${{ inputs.image_name }}: task done'
|