#!/usr/bin/env bash
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"

trigger-builder-pack-builder-release() {
  declare desc="builder-pack builder-release plugin trigger"
  declare trigger="builder-release"
  declare BUILDER_TYPE="$1" APP="$2" IMAGE_TAG="$3"

  if [[ "$BUILDER_TYPE" != "pack" ]]; then
    return
  fi

  plugn trigger pre-release-pack "$APP" "$IMAGE_TAG"

  local IMAGE=$(get_app_image_name "$APP" "$IMAGE_TAG")
  docker-image-labeler relabel --label=com.dokku.image-stage=release --label=com.dokku.app-name=$APP --label=org.label-schema.schema-version=1.0 --label=org.label-schema.vendor=dokku --label=dokku "$IMAGE"
  plugn trigger post-release-builder "$BUILDER_TYPE" "$APP" "$IMAGE"
}

trigger-builder-pack-builder-release "$@"
