Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactors helm targets to avoid duplication and improve logging #2608

Merged
merged 2 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 40 additions & 20 deletions Common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,22 @@ HELM_TAG?=$(GIT_TAG)-$(GIT_HASH)
HELM_USE_UPSTREAM_IMAGE?=false
# HELM_DIRECTORY must be a relative path from project root to the directory that contains a chart
HELM_DIRECTORY?=.
HELM_DESTINATION_REPOSITORY?=$(IMAGE_COMPONENT)
HELM_IMAGE_LIST?=
HELM_DESTINATION_REPOSITORY?=$(HELM_CHART_NAME)
HELM_IMAGE_LIST?=$(IMAGE_COMPONENT)
HELM_GIT_CHECKOUT_TARGET?=$(HELM_SOURCE_REPOSITORY)/eks-anywhere-checkout-$(HELM_GIT_TAG)
HELM_GIT_PATCH_TARGET?=$(HELM_SOURCE_REPOSITORY)/eks-anywhere-helm-patched
PACKAGE_DEPENDENCIES?=
FORCE_JSON_SCHEMA_FILE?=
HELM_CHART_NAMES?=$(IMAGE_COMPONENT)

# *theory* for the enable_logging preqreq when targets are prereqs of other targets
# for some reason the logging_shell does not get set for the targets which are acting as prereqs
# so if you call helm/build it will only show the logging around helm/build, not all
# by also defining all the actual targets (removing the wildcard) it seems to help make
# figure something out so that the logging shell is properly set
# this is only an issue in the newer version of Make running in AL2/23 vs on mac
# $1 - helm action (copy|require|replace|build|push)
FULL_CHART_TARGETS=$(addsuffix /helm/$1,$(HELM_CHART_NAMES))
####################################################

#### HELPERS ########
Expand Down Expand Up @@ -560,10 +571,10 @@ ifneq ($(REPO_NO_CLONE),true)
$(REPO): | ensure-bash-version
@echo -e $(call TARGET_START_LOG)
ifneq ($(REPO_SPARSE_CHECKOUT),)
source $(BUILD_LIB)/common.sh && retry git clone --depth 1 --filter=blob:none --sparse -b $(GIT_TAG) $(CLONE_URL) $(REPO)
source $(BUILD_LIB)/common.sh && retry git clone --quiet --depth 1 --filter=blob:none --sparse -b $(GIT_TAG) $(CLONE_URL) $(REPO)
git -C $(REPO) sparse-checkout set $(REPO_SPARSE_CHECKOUT) --cone --skip-checks
else
source $(BUILD_LIB)/common.sh && retry git clone $(CLONE_URL) $(REPO)
source $(BUILD_LIB)/common.sh && retry git clone --quiet $(CLONE_URL) $(REPO)
endif
@echo -e $(call TARGET_END_LOG)
endif
Expand Down Expand Up @@ -598,7 +609,7 @@ $(REPO)/%ks-anywhere-go-mod-download: $(if $(PATCHES_DIR),$(GIT_PATCH_TARGET),$(
ifneq ($(REPO),$(HELM_SOURCE_REPOSITORY))
$(HELM_SOURCE_REPOSITORY):
@echo -e $(call TARGET_START_LOG)
source $(BUILD_LIB)/common.sh && retry git clone $(HELM_CLONE_URL) $(HELM_SOURCE_REPOSITORY)
source $(BUILD_LIB)/common.sh && retry git clone --quiet $(HELM_CLONE_URL) $(HELM_SOURCE_REPOSITORY)
@echo -e $(call TARGET_END_LOG)
endif

Expand All @@ -607,7 +618,7 @@ $(HELM_GIT_CHECKOUT_TARGET): | $(HELM_SOURCE_REPOSITORY)
@echo -e $(call TARGET_START_LOG)
@echo rm -f $(HELM_SOURCE_REPOSITORY)/eks-anywhere-*
(cd $(HELM_SOURCE_REPOSITORY) && $(BASE_DIRECTORY)/build/lib/wait_for_tag.sh $(HELM_GIT_TAG))
git -C $(HELM_SOURCE_REPOSITORY) checkout -f $(HELM_GIT_TAG)
git -C $(HELM_SOURCE_REPOSITORY) checkout --quiet -f $(HELM_GIT_TAG)
touch $@
@echo -e $(call TARGET_END_LOG)
endif
Expand Down Expand Up @@ -822,22 +833,31 @@ clean-job-caches: $(and $(findstring presubmit,$(JOB_TYPE)),$(filter true,$(PRUN
helm/pull: | $$(ENABLE_LOGGING)
@$(BUILD_LIB)/helm_pull.sh $(HELM_PULL_LOCATION) $(HELM_REPO_URL) $(HELM_PULL_NAME) $(REPO) $(HELM_DIRECTORY) $(CHART_VERSION) $(COPY_CRDS)

.PHONY: %/helm/copy %/helm/require %/helm/replace %/helm/build %/helm/push
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like this chunk

%/helm/copy %/helm/require %/helm/replace %/helm/build %/helm/push: HELM_CHART_NAME=$*

$(call FULL_CHART_TARGETS,copy) : %/helm/copy: $(LICENSES_TARGETS_FOR_PREREQ) $(if $(filter true,$(REPO_NO_CLONE)),,$(HELM_GIT_CHECKOUT_TARGET)) $(if $(wildcard $(PROJECT_ROOT)/helm/patches),$(HELM_GIT_PATCH_TARGET),) | ensure-helm ensure-skopeo $$(ENABLE_LOGGING)
@$(BUILD_LIB)/helm_copy.sh $(HELM_SOURCE_REPOSITORY) $(HELM_DESTINATION_REPOSITORY) $(HELM_DIRECTORY) $(OUTPUT_DIR)

$(call FULL_CHART_TARGETS,require) : %/helm/require: %/helm/copy | $$(ENABLE_LOGGING)
@$(BUILD_LIB)/helm_require.sh $(HELM_SOURCE_IMAGE_REPO) $(HELM_DESTINATION_REPOSITORY) $(OUTPUT_DIR) $(IMAGE_TAG) $(HELM_TAG) $(PROJECT_ROOT) $(LATEST) $(HELM_USE_UPSTREAM_IMAGE) "$(PACKAGE_DEPENDENCIES)" "$(FORCE_JSON_SCHEMA_FILE)" $(HELM_IMAGE_LIST)

$(call FULL_CHART_TARGETS,replace) : %/helm/replace: %/helm/require | $$(ENABLE_LOGGING)
@$(BUILD_LIB)/helm_replace.sh $(HELM_DESTINATION_REPOSITORY) $(OUTPUT_DIR)

$(call FULL_CHART_TARGETS,build) : %/helm/build: %/helm/replace | $$(ENABLE_LOGGING)
@$(BUILD_LIB)/helm_build.sh $(OUTPUT_DIR) $(HELM_DESTINATION_REPOSITORY)

$(call FULL_CHART_TARGETS,push) : %/helm/push: %/helm/build | $$(ENABLE_LOGGING)
@$(BUILD_LIB)/helm_push.sh $(IMAGE_REPO) $(HELM_DESTINATION_REPOSITORY) $(HELM_TAG) $(GIT_TAG) $(OUTPUT_DIR) $(LATEST)

# Build helm chart
.PHONY: helm/build
helm/build: $(LICENSES_TARGETS_FOR_PREREQ)
helm/build: $(if $(filter true,$(REPO_NO_CLONE)),,$(HELM_GIT_CHECKOUT_TARGET))
helm/build: $(if $(wildcard $(PROJECT_ROOT)/helm/patches),$(HELM_GIT_PATCH_TARGET),) | ensure-helm ensure-skopeo
@echo -e $(call TARGET_START_LOG)
$(BUILD_LIB)/helm_copy.sh $(HELM_SOURCE_REPOSITORY) $(HELM_DESTINATION_REPOSITORY) $(HELM_DIRECTORY) $(OUTPUT_DIR)
$(BUILD_LIB)/helm_require.sh $(HELM_SOURCE_IMAGE_REPO) $(HELM_DESTINATION_REPOSITORY) $(OUTPUT_DIR) $(IMAGE_TAG) $(HELM_TAG) $(PROJECT_ROOT) $(LATEST) $(HELM_USE_UPSTREAM_IMAGE) $(HELM_IMAGE_LIST)
$(BUILD_LIB)/helm_replace.sh $(HELM_DESTINATION_REPOSITORY) $(OUTPUT_DIR)
$(BUILD_LIB)/helm_build.sh $(OUTPUT_DIR) $(HELM_DESTINATION_REPOSITORY)
@echo -e $(call TARGET_END_LOG)
helm/build: $(foreach chart,$(HELM_CHART_NAMES),$(chart)/helm/build)

# Build helm chart and push to registry defined in IMAGE_REPO.
.PHONY: helm/push
helm/push: helm/build | ensure-helm $$(ENABLE_LOGGING)
@$(BUILD_LIB)/helm_push.sh $(IMAGE_REPO) $(HELM_DESTINATION_REPOSITORY) $(HELM_TAG) $(GIT_TAG) $(OUTPUT_DIR) $(LATEST)
helm/push: $(foreach chart,$(HELM_CHART_NAMES),$(chart)/helm/push)

#@ Fetch Binary Targets
.PHONY: handle-dependencies
Expand Down Expand Up @@ -972,16 +992,16 @@ patch-for-dep-update: checkout-repo
cmd=( ecr-public --region us-east-1 ); \
fi; \
repo=$(IMAGE_REPO_COMPONENT); \
if [ "$(IMAGE_NAME)" = "__helm__" ]; then \
repo="$(HELM_DESTINATION_REPOSITORY)"; \
if [[ "$(IMAGE_NAME)" = *"__helm__"* ]]; then \
repo="$(IMAGE_NAME:%/__helm__=%)"; \
fi; \
if ! aws $${cmd[*]} describe-repositories --repository-name "$$repo" > /dev/null 2>&1; then \
aws $${cmd[*]} create-repository --repository-name "$$repo"; \
fi;

.PHONY: create-ecr-repos
create-ecr-repos: # Create repos in ECR for project images for local testing
create-ecr-repos: $(foreach image,$(IMAGE_NAMES),$(image)/create-ecr-repo) $(if $(filter true,$(HAS_HELM_CHART)),__helm__/create-ecr-repo,)
create-ecr-repos: $(foreach image,$(IMAGE_NAMES),$(image)/create-ecr-repo) $(if $(filter true,$(HAS_HELM_CHART)),$(foreach chart,$(HELM_CHART_NAMES),$(chart)/__helm__/create-ecr-repo),)

.PHONY: var-value-%
var-value-%:
Expand Down
6 changes: 4 additions & 2 deletions build/lib/helm_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

set -x
set -o errexit
set -o nounset
set -o pipefail

SCRIPT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
source "${SCRIPT_ROOT}/common.sh"

OUTPUT_DIR="${1?First arguement is output directory}"
HELM_DESTINATION_REPOSITORY="${2?Second argument is helm destination repository}"
CHART_NAME=$(basename ${HELM_DESTINATION_REPOSITORY})
Expand All @@ -26,4 +28,4 @@ CHART_NAME=$(basename ${HELM_DESTINATION_REPOSITORY})
# Build
#
cd ${OUTPUT_DIR}/helm
helm package "${CHART_NAME}"
build::common::echo_and_run helm package "${CHART_NAME}"
8 changes: 4 additions & 4 deletions build/lib/helm_copy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

set -x

set -o errexit
set -o nounset
set -o pipefail
Expand All @@ -33,6 +33,6 @@ source "${SCRIPT_ROOT}/common.sh"
#
# Copy
#
mkdir -p ${DEST_DIR}
rsync -a --exclude .git "${SOURCE_DIR}" "${DEST_DIR}"
build::non-golang::copy_licenses ${HELM_SOURCE_REPOSITORY} $DEST_DIR/LICENSES/github.com/${HELM_SOURCE_REPOSITORY}
build::common::echo_and_run mkdir -p ${DEST_DIR}
build::common::echo_and_run rsync -a --exclude .git "${SOURCE_DIR}" "${DEST_DIR}"
build::common::echo_and_run build::non-golang::copy_licenses ${HELM_SOURCE_REPOSITORY} $DEST_DIR/LICENSES/github.com/${HELM_SOURCE_REPOSITORY}
24 changes: 16 additions & 8 deletions build/lib/helm_push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

set -x
set -o errexit
set -o nounset
set -o pipefail
Expand Down Expand Up @@ -47,26 +46,35 @@ export HELM_REGISTRY_CONFIG="${DOCKER_CONFIG}/config.json"
export HELM_EXPERIMENTAL_OCI=1
TMPFILE=$(mktemp /tmp/helm-output.XXXXXX)
function cleanup() {
if [[ "${IMAGE_REGISTRY}" == *"public.ecr.aws"* ]]; then
echo "If authentication failed: aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws"
if grep -q "blobs/uploads/\": EOF" $TMPFILE ; then
echo "******************************************************"
echo "Ensure container registry and repository exists!!"
echo "Try running make create-ecr-repos to create ecr repositories in your aws account."
echo "******************************************************"
else
echo "If authentication failed: aws ecr get-login-password --region \${AWS_REGION} | docker login --username AWS --password-stdin ${IMAGE_REGISTRY}"
cat $TMPFILE
if [[ "${IMAGE_REGISTRY}" == *"public.ecr.aws"* ]]; then
echo "If authentication failed: aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws"
else
echo "If authentication failed: aws ecr get-login-password --region \${AWS_REGION} | docker login --username AWS --password-stdin ${IMAGE_REGISTRY}"
fi
fi
rm -f "${TMPFILE}"
}

trap cleanup err
trap "rm -f $TMPFILE" exit
helm push ${CHART_FILE} oci://${IMAGE_REGISTRY}/${HELM_DESTINATION_OWNER} | tee ${TMPFILE}
echo "($(pwd)) \$ helm push ${CHART_FILE} oci://${IMAGE_REGISTRY}/${HELM_DESTINATION_OWNER}"
helm push ${CHART_FILE} oci://${IMAGE_REGISTRY}/${HELM_DESTINATION_OWNER} 2> ${TMPFILE}
DIGEST=$(grep Digest $TMPFILE | $SED -e 's/Digest: //')

# Adds a 2nd tag to the helm chart for the bundle-release jobs.
if [[ "${IMAGE_REGISTRY}" != *"public.ecr.aws"* ]]; then
MANIFEST=$(aws ecr batch-get-image --repository-name "$HELM_DESTINATION_REPOSITORY" --image-ids imageTag=${SEMVER} --query "images[].imageManifest" --output text)
MANIFEST=$(aws ecr batch-get-image --repository-name "$HELM_DESTINATION_REPOSITORY" --image-ids imageDigest=${DIGEST} --query "images[].imageManifest" --output text)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see an issue with this update, though didn't find an example to validate the output of it. So just double check to be safe.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call out, i tried this one manually locally since presubmits do not actually push.

export AWS_PAGER=""
aws ecr put-image --repository-name ${HELM_DESTINATION_REPOSITORY} --image-tag ${SEMVER_GIT_TAG}-${LATEST_TAG}-helm --image-manifest "$MANIFEST" --image-manifest-media-type "application/vnd.oci.image.manifest.v1+json"
build::common::echo_and_run aws ecr put-image --repository-name ${HELM_DESTINATION_REPOSITORY} --image-tag ${SEMVER_GIT_TAG}-${LATEST_TAG}-helm --image-manifest "$MANIFEST" --image-manifest-media-type "application/vnd.oci.image.manifest.v1+json"
fi

DIGEST=$(grep Digest $TMPFILE | $SED -e 's/Digest: //')
{
set +x
echo
Expand Down
5 changes: 2 additions & 3 deletions build/lib/helm_replace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

set -x
set -o errexit
set -o nounset
set -o pipefail
Expand All @@ -36,12 +35,12 @@ TEMPLATE_DIR=helm/templates
SEDFILE=${OUTPUT_DIR}/helm/sedfile
for file in Chart.yaml values.yaml
do
$SED -f ${SEDFILE} -i ${DEST_DIR}/${file}
build::common::echo_and_run $SED -f ${SEDFILE} -i ${DEST_DIR}/${file}
done

if [ -d ${OUTPUT_DIR}/helm/${CHART_NAME}/crds ]; then
for file in crds/*.yaml
do
$SED -f ${SEDFILE} -i ${DEST_DIR}/${file}
build::common::echo_and_run $SED -f ${SEDFILE} -i ${DEST_DIR}/${file}
done
fi
107 changes: 84 additions & 23 deletions build/lib/helm_require.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

set -x
set -e
set -o errexit
set -o nounset
Expand All @@ -27,13 +26,19 @@ HELM_TAG="${5?Fifth argument is helm tag}"
PROJECT_ROOT="${6?Sixth argument is project root}"
LATEST="${7?Seventh argument is latest tag}"
HELM_USE_UPSTREAM_IMAGE="${8?Eigth argument is bool determining whether to use cached upstream images}"
HELM_IMAGE_LIST="${@:9}"
PACKAGE_DEPENDENCIES="${9?Ninth argument is optional project dependencies}"
FORCE_JSON_SCHEMA_FILE="${10?Tenth argument is optional schema file}"
HELM_IMAGE_LIST="${@:11}"

CHART_NAME=$(basename ${HELM_DESTINATION_REPOSITORY})
DEST_DIR=${OUTPUT_DIR}/helm/${CHART_NAME}
SCRIPT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
PACKAGE_DEPENDENCIES=${PACKAGE_DEPENDENCIES:=""}
FORCE_JSON_SCHEMA_FILE=${FORCE_JSON_SCHEMA_FILE:=""}
source "${SCRIPT_ROOT}/common.sh"

if ! aws sts get-caller-identity &> /dev/null; then
echo "The AWS cli is used to find the ECR registries and repos for the current AWS account please login!"
exit 1;
fi

#
# Image tags
Expand All @@ -52,55 +57,108 @@ JSON_SCHEMA_FILE=$PROJECT_ROOT/helm/schema.json
SEDFILE=${OUTPUT_DIR}/helm/sedfile
export IMAGE_TAG
export HELM_TAG
export HELM_REGISTRY=$(aws ecr-public describe-registries --region us-east-1 --output text --query 'registries[*].registryUri')
export HELM_REGISTRY=$(aws ecr-public describe-registries --region us-east-1 --output text --query 'registries[*].registryUri' 2> /dev/null)
envsubst <$PROJECT_ROOT/helm/sedfile.template >${SEDFILE}
# Semver requires that our version begin with a digit, so strip the v.
echo "s,version: v,version: ,g" >>${SEDFILE}
for IMAGE in ${HELM_IMAGE_LIST:-}
do
if [ "${IMAGE}" == "${HELM_DESTINATION_REPOSITORY}" ] || [ "${IMAGE_TAG}" != "${HELM_TAG}" ]
then

# query ecr for the shasum of the image tagged with ${TAG}
function get_image_shasum() {
local -r image=$1
local -r tag=$2

local image_shasum=
if [ "${HELM_USE_UPSTREAM_IMAGE}" = true ]; then
image_shasum=$(${SCRIPT_ROOT}/image_shasum.sh ${IMAGE_REGISTRY} ${image} ${tag})
elif [ "${JOB_TYPE:-}" = "presubmit" ]; then
image_shasum=${LATEST}
fi

if [[ -z ${image_shasum} ]] && aws --region us-east-1 ecr-public describe-repositories --repository-names ${image} &> /dev/null; then
image_shasum=$(build::common::echo_and_run ${SCRIPT_ROOT}/image_shasum.sh ${HELM_REGISTRY} ${image} ${tag})
fi

if [[ -z ${image_shasum} ]] && aws ecr describe-repositories --repository-names ${image} &> /dev/null; then
image_shasum=$(build::common::echo_and_run ${SCRIPT_ROOT}/image_shasum.sh ${IMAGE_REGISTRY} ${image} ${tag})
fi

if [[ -n ${image_shasum} ]]; then
echo ${image_shasum}
else
echo "${image} does not exist in ECR Public or Private"
exit 1
fi
}

# query ecr for the image by latest tag and find the first non-latest tag the image is also tagged with
function get_image_tag_not_latest() {
local -r image=$1
local -r tag=$2

local use_tag=
if [ "${JOB_TYPE:-}" = "presubmit" ]; then
use_tag=${tag}
fi

if [[ -z ${use_tag} ]] && aws --region us-east-1 ecr-public describe-repositories --repository-names ${image} &> /dev/null; then
use_tag=$(build::common::echo_and_run aws --region us-east-1 ecr-public describe-images --repository-name ${image} --image-ids imageTag=${tag} --query 'imageDetails[0].imageTags' --output yaml 2> /dev/null | grep -v ${tag} | head -1| sed -e 's/- //')
fi

if [[ -z ${use_tag} ]] && aws ecr describe-repositories --repository-names ${image} &> /dev/null; then
use_tag=$(build::common::echo_and_run aws ecr describe-images --repository-name ${image} --image-id imageTag=${tag} --query 'imageDetails[0].imageTags' --output yaml 2> /dev/null | grep -v ${tag} | head -1| sed -e 's/- //')
fi

if [[ -n ${use_tag} ]]; then
echo ${use_tag}
else
echo "${image}@${tag} does not exist in ECR Public or Private"
exit 1
fi
}

for IMAGE in ${HELM_IMAGE_LIST:-}; do
# if its the image(s) built from this project, use the image_tag
# otherwise its an image from a different project so use latest to trigger finding the latest image
if [ "${IMAGE}" = "${HELM_DESTINATION_REPOSITORY}" ] || [ "${IMAGE_TAG}" != "${HELM_TAG}" ]; then
TAG="${IMAGE_TAG}"
else
TAG="${LATEST}"
fi
IMAGE_SHASUM=$(${SCRIPT_ROOT}/image_shasum.sh ${HELM_REGISTRY} ${IMAGE} ${TAG}) ||
IMAGE_SHASUM=$(${SCRIPT_ROOT}/image_shasum.sh ${IMAGE_REGISTRY} ${IMAGE} ${TAG})

IMAGE_SHASUM=$(get_image_shasum ${IMAGE} ${TAG})

echo "s,{{${IMAGE}}},${IMAGE_SHASUM},g" >>${SEDFILE}
if [ "${TAG}" == "latest" ]
then
USE_TAG=$(aws --region us-east-1 ecr-public describe-images --repository-name ${IMAGE} --image-ids imageTag=latest --query 'imageDetails[0].imageTags' --output yaml | grep -v latest | head -1| sed -e 's/- //') ||
USE_TAG=$(aws ecr describe-images --repository-name ${IMAGE} --image-id imageTag=latest --query 'imageDetails[0].imageTags' --output yaml | grep -v latest | head -1| sed -e 's/- //') ||
USE_TAG="latest"
if [ "${TAG}" = "${LATEST}" ]; then
USE_TAG=$(get_image_tag_not_latest ${IMAGE} ${LATEST})
else
USE_TAG=$TAG
fi

# If HELM_USE_UPSTREAM_IMAGE is true, we are using images from upstream.
# Though we pull images directly from upstream for build tooling checks (i.e.
# get images shasums), we will use cached images in the helm charts. Cached
# images follow the convention of ${PROJECT_NAME}/${UPSTREAM_IMAGE_NAME}.
if [ "${HELM_USE_UPSTREAM_IMAGE}" == true ]
then
if [ "${HELM_USE_UPSTREAM_IMAGE}" == true ]; then
PROJECT_NAME=$(echo "$HELM_DESTINATION_REPOSITORY" | awk -F "/" '{print $1}')
IMAGE_REPO="${PROJECT_NAME}/${IMAGE}"
else
IMAGE_REPO="${IMAGE}"
fi

cat >>${REQUIRES_FILE} <<!
- repository: ${IMAGE_REPO}
tag: ${USE_TAG}
digest: ${IMAGE_SHASUM}
!
done

if [ -n "${FORCE_JSON_SCHEMA_FILE}" ]
then
if [ -n "${FORCE_JSON_SCHEMA_FILE}" ]; then
JSON_SCHEMA_FILE=${FORCE_JSON_SCHEMA_FILE}
fi

if [ -f ${JSON_SCHEMA_FILE} ]
then
JSON_SCHEMA=$(cat ${JSON_SCHEMA_FILE} | gzip | base64 | tr -d '\n')
if [ -f ${JSON_SCHEMA_FILE} ]; then
echo "Using schema file: ${JSON_SCHEMA_FILE}"
JSON_SCHEMA=$(cat ${JSON_SCHEMA_FILE} | gzip -n | base64 | tr -d '\n')
cat >>${REQUIRES_FILE} <<!
schema: ${JSON_SCHEMA}
!
Expand All @@ -112,3 +170,6 @@ if [ -n "${PACKAGE_DEPENDENCIES}" ]; then
echo " - ${dep}"
done >> ${REQUIRES_FILE}
fi

build::common::echo_and_run cat ${SEDFILE}
build::common::echo_and_run cat ${REQUIRES_FILE}
Loading