Files
build-image/action.yaml
2025-04-14 11:36:00 +02:00

95 lines
2.7 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: 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: 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
${{ inputs.build_command }} save ${image} -o $$.image.tar
${{ inputs.tag_command }} load -i $$.image.tar
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