generated from pmo-actions/healthchecks-ping
152 lines
4.7 KiB
YAML
152 lines
4.7 KiB
YAML
name: 'Push a docker image to a registry server'
|
|
description: 'Push a docker image to a registry server using podman, docker, or skopeo'
|
|
author: 'Eric Coissac'
|
|
|
|
inputs:
|
|
image_name:
|
|
description: 'name of the image'
|
|
required: true
|
|
image_tags:
|
|
description: 'tags added to the image'
|
|
required: true
|
|
registry_login:
|
|
decription: "Is the action must take care to log to the registry"
|
|
required: false
|
|
default: false
|
|
type: boolean
|
|
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 }}
|
|
registry_server:
|
|
description: 'Address of the image registry server'
|
|
required: false
|
|
default: "niepce.petite-maison-orange.fr"
|
|
push_command:
|
|
description: 'Command used to push the image (docker|podman|skopeo)'
|
|
required: false
|
|
default: skopeo
|
|
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: Debug registry_login
|
|
shell: bash
|
|
run: |
|
|
source "${{ github.action_path }}/../bashlib.sh"
|
|
debug "Registry login is set to -${{ inputs.registry_login }}-"
|
|
|
|
|
|
- name: Log into the registry
|
|
if: inputs.registry_login == 'true'
|
|
uses: https://gargoton.petite-maison-orange.fr/pmo-actions/registry-login@main
|
|
with:
|
|
registry_command: ${{ inputs.push_command }}
|
|
registry_server: ${{ inputs.registry_server }}
|
|
registry_user: ${{ inputs.registry_user }}
|
|
registry_password: ${{ inputs.registry_password }}
|
|
debug: ${{ inputs.debug }}
|
|
|
|
- name: install skopeo
|
|
if: inputs.push_command == 'skopeo'
|
|
shell: bash
|
|
run: |
|
|
source "${{ github.action_path }}/../bashlib.sh"
|
|
step "Install software" "skopeo"
|
|
|
|
if command -v skopeo >/dev/null 2>&1; then
|
|
success "Already installed" "Skopeo found"
|
|
exit 0
|
|
fi
|
|
|
|
check_command apt-get
|
|
|
|
apt-get update
|
|
|
|
if apt-get -y install skopeo ; then
|
|
success "Success" "Skopeo installed"
|
|
else
|
|
error "Install failed" "Could not install Skopeo"
|
|
fi
|
|
|
|
- name: install podman
|
|
if: inputs.push_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
|
|
|
|
- name: Push the images to the serveur
|
|
shell: bash
|
|
run: |
|
|
source "${{ github.action_path }}/../bashlib.sh"
|
|
|
|
check_command ${{ inputs.push_command }}
|
|
|
|
IFS=' ' read -r -a tags <<< "${{ inputs.image_tags }}"
|
|
debug "Tags parsed: ${tags[*]}"
|
|
|
|
sep=""
|
|
if [[ -n "${tags[0]}" ]] ; then
|
|
sep=":"
|
|
fi
|
|
|
|
step "Start pushing" "${{ inputs.image_name }}"
|
|
|
|
for tag in "${tags[@]}" ; do
|
|
if [[ "${{ inputs.push_command }}" == "skopeo" ]] ; then
|
|
# Pour skopeo, on utilise 'copy' avec docker-daemon: comme source
|
|
source_image="docker-daemon:${{ inputs.registry_server }}/${{ inputs.image_name }}:${tag}"
|
|
dest_image="docker://${{ inputs.registry_server }}/${{ inputs.image_name }}:${tag}"
|
|
|
|
if skopeo copy "${source_image}" "${dest_image}" ; then
|
|
success "Image pushing" "${{ inputs.image_name }}:${tag}"
|
|
else
|
|
error "Failed" "pushing of image ${{ inputs.image_name }}:${tag}"
|
|
fi
|
|
else
|
|
# Pour podman ou docker, on utilise la syntaxe classique 'push'
|
|
if ${{ inputs.push_command }} push ${{ inputs.registry_server }}/${{ inputs.image_name }}:${tag} ; then
|
|
success "Image pushing" "${{ inputs.image_name }}:${tag}"
|
|
else
|
|
error "Failed" "pushing of image ${{ inputs.image_name }}:${tag}"
|
|
fi
|
|
fi
|
|
done
|
|
|