name: 'build-push-image' description: 'Builds a container image, tags it, pushes to registry, and reports status to Healthchecks.io' author: 'Eric Coissac' inputs: 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 version_tag_prefix: description: 'Prefix added to the version to build the version tag' required: false default: 'pmo' build_command: description: 'Command used to build the image (docker|podman)' required: false default: docker no_cache: description: 'Do we desactivate cache during image building' required: false default: false tag_command: description: 'Command used to tag the image (docker|podman)' required: false default: docker push_command: description: 'Command used to push the image (docker|podman|skopeo)' required: false default: skopeo 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' check_server: description: 'Address of the Healthchecks server' required: false default: 'https://haoma.petite-maison-orange.fr' 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 - name: Set debug mode if: inputs.debug == 'true' shell: bash run: | source "${{ github.action_path }}/../bashlib.sh" export DEBUG="ON" echo "DEBUG=ON" >> $GITHUB_ENV debug Debug switch on - name: Set healthcheck enabled flag shell: bash run: | if [[ "${{ inputs.check_server }}" != "" && "${{ inputs.check_uuid }}" != "" ]]; then echo "HEALTHCHECK_ENABLED=true" >> $GITHUB_ENV else echo "HEALTHCHECK_ENABLED=false" >> $GITHUB_ENV fi - name: Start the job if: env.HEALTHCHECK_ENABLED == 'true' 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 }} - 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 }} - name: Install container tool (push) if: inputs.push_command == 'skopeo' || inputs.push_command == 'podman' uses: https://gargoton.petite-maison-orange.fr/pmo-actions/install-container-tools@main with: tools: ${{ inputs.push_command }} debug: ${{ inputs.debug }} - name: Install container tool (tag) if: inputs.tag_command == 'skopeo' || inputs.tag_command == 'podman' uses: https://gargoton.petite-maison-orange.fr/pmo-actions/install-container-tools@main with: tools: ${{ inputs.tag_command }} debug: ${{ inputs.debug }} - name: Build image starting if: env.HEALTHCHECK_ENABLED == 'true' 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 }} - name: Store tag version shell: bash run: | echo "IMAGE_TAGS=${{ inputs.image_tags }}" >> $GITHUB_ENV - name: Add PMO version tag if: inputs.add_version_tag == 'true' run: | source "${{ github.action_path }}/../bashlib.sh" if [[ -n '${{ inputs.version_tag_prefix }}' ]] ; then prefix="${{ inputs.version_tag_prefix }}-" else prefix="" fi echo "IMAGE_TAGS=${{ env.IMAGE_TAGS }} ${prefix}${{ steps.get_version.outputs.version }}" >> $GITHUB_ENV - 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 }}' no_cache: '${{ inputs.no_cache }}' tag_command: '${{ inputs.tag_command }}' debug: ${{ inputs.debug }} - name: Canceled building if: cancelled() && env.HEALTHCHECK_ENABLED == 'true' 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() && env.HEALTHCHECK_ENABLED == 'true' 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: env.HEALTHCHECK_ENABLED == 'true' 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 }} - 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.push_command }}' debug: ${{ inputs.debug }} - name: Push image failed if: failure() && env.HEALTHCHECK_ENABLED == 'true' 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: env.HEALTHCHECK_ENABLED == 'true' 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'