Files
build-image/action.yaml

97 lines
2.9 KiB
YAML
Raw Normal View History

2025-04-14 11:26:34 +02:00
name: 'Build a docker image and tag it'
description: 'Build a docker image and tag it using podman or docker'
2025-04-14 10:57:40 +02:00
author: 'Eric Coissac'
inputs:
2025-04-14 11:16:56 +02:00
image_name:
description: 'name of the image'
2025-04-14 10:57:40 +02:00
required: true
2025-04-14 11:16:56 +02:00
image_tags:
description: 'tags added to the image'
2025-04-14 10:57:40 +02:00
required: true
2025-04-14 11:16:56 +02:00
registry_server:
description: 'Address of the image registry server'
2025-04-14 10:57:40 +02:00
required: false
2025-04-14 11:16:56 +02:00
default: "niepce.petite-maison-orange.fr"
build_command:
description: 'Command used to build the image (docker|podman)'
2025-04-14 10:57:40 +02:00
required: false
2025-04-14 11:16:56 +02:00
default: docker
tag_command:
description: 'Command used to tag the image (docker|podman)'
required: false
default: podman
2025-04-14 10:57:40 +02:00
debug:
description: 'Run the action in debug mode'
required: false
default: false
type: boolean
runs:
using: 'composite'
2025-04-14 11:29:42 +02:00
2025-04-14 10:57:40 +02:00
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
2025-04-14 11:16:56 +02:00
- name: Build the image
2025-04-14 10:57:40 +02:00
shell: bash
run: |
source "${{ github.action_path }}/bashlib.sh"
2025-04-14 11:16:56 +02:00
check_command ${{ inputs.build_command }}
2025-04-14 10:57:40 +02:00
2025-04-14 11:36:00 +02:00
IFS=' ' read -r -a tags <<< "${{ inputs.image_tags }}"
debug "Tags parsed: ${tags[*]}"
2025-04-14 11:16:56 +02:00
sep=""
if [[ -n "${tags[0]}" ]] ; then
sep=":"
fi
2025-04-14 10:57:40 +02:00
2025-04-14 11:16:56 +02:00
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 }}"
2025-04-14 10:57:40 +02:00
2025-04-14 11:29:42 +02:00
- name: tag images
2025-04-14 11:36:00 +02:00
shell: bash
run: |
2025-04-14 11:16:56 +02:00
source "${{ github.action_path }}/bashlib.sh"
2025-04-14 11:36:00 +02:00
2025-04-14 11:16:56 +02:00
check_command ${{ inputs.tag_command }}
2025-04-14 10:57:40 +02:00
2025-04-14 11:36:00 +02:00
IFS=' ' read -r -a tags <<< "${{ inputs.image_tags }}"
sep=""
if [[ -n "${tags[0]}" ]] ; then
sep=":"
fi
2025-04-14 11:16:56 +02:00
image=${{ inputs.registry_server }}/${{ inputs.image_name }}${sep}${tags[0]}
2025-04-14 10:57:40 +02:00
2025-04-14 11:16:56 +02:00
if [[ "${{ inputs.build_command }}" != "${{ inputs.tag_command }}" ]] ; then
2025-04-14 11:41:26 +02:00
step "Transfer image" "From ${{ inputs.build_command }} to ${{ inputs.tag_command }}"
2025-04-14 11:16:56 +02:00
${{ inputs.build_command }} save ${image} -o $$.image.tar
${{ inputs.tag_command }} load -i $$.image.tar
rm -f $$.image.tar
2025-04-14 11:41:26 +02:00
&& success "Success" "Image transfer from ${{ inputs.build_command }} to ${{ inputs.tag_command }}"
2025-04-14 10:57:40 +02:00
fi
2025-04-14 11:16:56 +02:00
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
2025-04-14 10:57:40 +02:00