generated from pmo-actions/healthchecks-ping
108 lines
3.4 KiB
YAML
108 lines
3.4 KiB
YAML
name: 'Build a docker image and tag it'
|
|
description: 'Build a docker image and tag it using podman or docker'
|
|
author: 'Eric Coissac'
|
|
|
|
inputs:
|
|
image_name:
|
|
description: 'name of the image'
|
|
required: true
|
|
image_tags:
|
|
description: 'tags added to the image'
|
|
required: true
|
|
registry_server:
|
|
description: 'Address of the image registry server'
|
|
required: false
|
|
default: "niepce.petite-maison-orange.fr"
|
|
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
|
|
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
|
|
|
|
- name: Set debug mode
|
|
if: ${{ inputs.debug == true }}
|
|
shell: bash
|
|
run: |
|
|
source "${{ github.action_path }}/../bashlib.sh"
|
|
export DEBUG="ON"
|
|
echo "DEBUG=ON" >> $GITEA_ENV
|
|
debug Debug switch on
|
|
|
|
- name: Tash description
|
|
shell: bash
|
|
run: |
|
|
source "${{ github.action_path }}/../bashlib.sh"
|
|
step "Image name" "${{ inputs.image_name }}"
|
|
step "Image tags" "${{ inputs.image_tags }}"
|
|
|
|
- name: Build the image
|
|
shell: bash
|
|
run: |
|
|
source "${{ github.action_path }}/../bashlib.sh"
|
|
|
|
check_command ${{ inputs.build_command }}
|
|
|
|
IFS=' ' read -r -a tags <<< "${{ inputs.image_tags }}"
|
|
debug "Tags parsed: ${tags[*]}"
|
|
|
|
sep=""
|
|
if [[ -n "${tags[0]}" ]] ; then
|
|
sep=":"
|
|
fi
|
|
|
|
image=${{ inputs.registry_server }}/${{ inputs.image_name }}${sep}${tags[0]}
|
|
${{ inputs.build_command }} build -t ${image} . \
|
|
|| error "Failed" "Cannot built the image ${{ inputs.image_name }}" \
|
|
&& success "Image build" "${{ inputs.image_name }}"
|
|
|
|
- name: tag images
|
|
shell: bash
|
|
run: |
|
|
source "${{ github.action_path }}/../bashlib.sh"
|
|
|
|
check_command ${{ inputs.tag_command }}
|
|
|
|
IFS=' ' read -r -a tags <<< "${{ inputs.image_tags }}"
|
|
|
|
sep=""
|
|
if [[ -n "${tags[0]}" ]] ; then
|
|
sep=":"
|
|
fi
|
|
|
|
image=${{ inputs.registry_server }}/${{ inputs.image_name }}${sep}${tags[0]}
|
|
|
|
if [[ "${{ inputs.build_command }}" != "${{ inputs.tag_command }}" ]] ; then
|
|
step "Transfer image" "From ${{ inputs.build_command }} to ${{ inputs.tag_command }}"
|
|
${{ inputs.build_command }} save ${image} -o $$.image.tar \
|
|
&& ${{ inputs.tag_command }} load -i $$.image.tar \
|
|
|| error "Transfert failed" "for image ${image} from ${{ inputs.build_command }} to ${{ inputs.tag_command }" \
|
|
&& success "Success" "Image transfer from ${{ inputs.build_command }} to ${{ inputs.tag_command }}"
|
|
rm -f $$.image.tar
|
|
fi
|
|
|
|
for tag in "${tags[@]:1}" ; do
|
|
${{ inputs.tag_command }} tag ${image} \
|
|
${{ inputs.registry_server }}/${{ inputs.image_name }}:${tag} \
|
|
|| error "Failed" "tagging of image ${{ inputs.image_name }}:${tag}" \
|
|
&& success "Image tagging" "${{ inputs.registry_server }}/${{ inputs.image_name }}:${tag}"
|
|
done
|
|
|
|
|
|
|
|
|