# Cleanup Images Template
.cleanup: 
    script:
        - |
            printf "%s\n" "- Removing Images -" \
            "${REGISTRY_URL}/${PROJECT_NAME}/${SERVICE_NAME}:${BRANCH_TAG}" \
            "${REGISTRY_URL}/${PROJECT_NAME}/${SERVICE_NAME}:${CI_COMMIT_SHORT_SHA}"
        - docker image rm --force "${REGISTRY_URL}/${PROJECT_NAME}/${SERVICE_NAME}:${BRANCH_TAG}" "${REGISTRY_URL}/${PROJECT_NAME}/${SERVICE_NAME}:${CI_COMMIT_SHORT_SHA}"
    rules:
        - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_COMMIT_MESSAGE =~ /\A(?i)-debug/'
          when: never
        - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
          when: always
        - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
          when: always