Skip to content

Commit

Permalink
Make script working for downstream.
Browse files Browse the repository at this point in the history
Signed-off-by: Oleksandr Andriienko <oandriie@redhat.com>
  • Loading branch information
AndrienkoAleksandr committed Jul 3, 2020
1 parent ef22bfd commit 39bceb3
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 23 deletions.
30 changes: 21 additions & 9 deletions olm/addDigests.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
#
# Copyright (c) 2019 Red Hat, Inc.
# Copyright (c) 2019-2020 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
Expand All @@ -10,6 +10,10 @@
# Contributors:
# Red Hat, Inc. - initial API and implementation

set +x
set -e

SCRIPTS_DIR=$(cd "$(dirname "$0")"; pwd)
BASE_DIR="$(pwd)"
QUIET=""

Expand All @@ -24,39 +28,47 @@ fi
command -v yq >/dev/null 2>&1 || { echo "yq is not installed. Aborting."; exit 1; }

usage () {
echo "Usage: $0 [-w WORKDIR] -s [SOURCE_PATH] -n [csv name] -v [VERSION] "
echo "Example: $0 -w $(pwd) -s eclipse-che-preview-openshift/deploy/olm-catalog/eclipse-che-preview-openshift -r "${CSV_NAME}.*${VERSION}.*.yaml" -n eclipse-che-preview-openshift -v 7.9.0"
echo "Example: $0 -w $(pwd) -s controller-manifests -n codeready-workspaces -v 2.1.0"
echo "Usage: $0 [-w WORKDIR] [-s SOURCE_PATH] -r [CSV_FILE_PATH_REGEXP] -t [IMAGE_TAG] "
echo "Example: $0 -w $(pwd) -r \"eclipse-che-preview-.*/eclipse-che-preview-.*\.v7.15.0.*yaml\" -t 7.15.0"
}

if [[ $# -lt 1 ]]; then usage; exit; fi

while [[ "$#" -gt 0 ]]; do
case $1 in
'-w') BASE_DIR="$2"; shift 1;;
'-v') VERSION="$2"; shift 1;;
'-r') CSV_FILE_NAME_REGEXP="$2"; shift 1;;
'-s') SRC_DIR="$2"; shift 1;;
'-t') IMAGE_TAG="$2"; shift 1;;
'-r') CSV_FILE_PATH_REGEXP="$2"; shift 1;;
'-q') QUIET="-q"; shift 0;;
'--help'|'-h') usage; exit;;
esac
shift 1
done

if [[ ! ${CSV_FILE_NAME_REGEXP} ]] || [[ ! $VERSION ]]; then usage; exit 1; fi
if [[ ! ${CSV_FILE_PATH_REGEXP} ]] || [[ ! $IMAGE_TAG ]]; then usage; exit 1; fi

CSV_FILES_DIR=${BASE_DIR}
if [ -n "${SRC_DIR}" ]; then
CSV_FILES_DIR="${BASE_DIR}/${SRC_DIR}"
fi
echo "Resolved CSV files dir: ${CSV_FILES_DIR}"

CSV_FILES=( $(find ${BASE_DIR}/ -regextype posix-egrep -regex "${BASE_DIR}/?${CSV_FILE_NAME_REGEXP}") )
echo "find ${CSV_FILES_DIR} -regextype posix-egrep -regex \"${CSV_FILES_DIR}/?${CSV_FILE_PATH_REGEXP}\""
CSV_FILES=( $(find ${CSV_FILES_DIR} -regextype posix-egrep -regex "${CSV_FILES_DIR}/?${CSV_FILE_PATH_REGEXP}") )
RELATED_IMAGE_PREFIX="RELATED_IMAGE_"

rm -Rf ${BASE_DIR}/generated/csv
mkdir -p ${BASE_DIR}/generated/csv
# Copy original csv files
for CSV_FILE in ${CSV_FILES[@]}
do
echo "CSV file: ${CSV_FILE}"
cp -pR ${CSV_FILE} ${BASE_DIR}/generated/csv
done

# Collect list digest only once to save time. We expected that digest list is the same for "openshift" and "kubernetes" platforms.
source ${BASE_DIR}/buildDigestMap.sh -w ${BASE_DIR} -c ${CSV_FILES[0]} -v ${VERSION} ${QUIET}
source ${SCRIPTS_DIR}/buildDigestMap.sh -w ${BASE_DIR} -c ${CSV_FILES[0]} -t ${IMAGE_TAG} ${QUIET}

if [[ ! "${QUIET}" ]]; then cat ${BASE_DIR}/generated/digests-mapping.txt; fi
for CSV_FILE in ${CSV_FILES[@]}
Expand Down
25 changes: 14 additions & 11 deletions olm/buildDigestMap.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
#
# Copyright (c) 2019 Red Hat, Inc.
# Copyright (c) 2019-2020 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
Expand All @@ -10,6 +10,7 @@
# Contributors:
# Red Hat, Inc. - initial API and implementation

SCRIPTS_DIR=$(cd "$(dirname "$0")"; pwd)
BASE_DIR="$1"
QUIET=""

Expand All @@ -25,8 +26,8 @@ command -v yq >/dev/null 2>&1 || { echo "yq is not installed. Aborting."; exit 1
command -v skopeo > /dev/null 2>&1 || { echo "skopeo is not installed. Aborting."; exit 1; }

usage () {
echo "Usage: $0 [-w WORKDIR] -c [/path/to/csv.yaml] "
echo "Example: $0 -w $(pwd) -c $(pwd)/generated/eclipse-che-preview-openshift/7.9.0/eclipse-che-preview-openshift.v7.9.0.clusterserviceversion.yaml"
echo "Usage: $0 [-w WORKDIR] -c [/path/to/csv.yaml] -t [IMAGE_TAG]"
echo "Example: $0 -w $(pwd) -c $(pwd)/olm/eclipse-che-preview-kubernetes/deploy/olm-catalog/eclipse-che-preview-kubernetes/7.9.0/eclipse-che-preview-kubernetes.v7.9.0.clusterserviceversion.yaml -t 7.9.0"
}

if [[ $# -lt 1 ]]; then usage; exit; fi
Expand All @@ -35,20 +36,20 @@ while [[ "$#" -gt 0 ]]; do
case $1 in
'-w') BASE_DIR="$2"; shift 1;;
'-c') CSV="$2"; shift 1;;
'-v') VERSION="$2"; shift 1;;
'-t') IMAGE_TAG="$2"; shift 1;;
'-q') QUIET="-q"; shift 0;;
'--help'|'-h') usage; exit;;
esac
shift 1
done

if [[ ! $CSV ]] || [[ ! $VERSION ]]; then usage; exit 1; fi
if [[ ! $CSV ]] || [[ ! $IMAGE_TAG ]]; then usage; exit 1; fi

mkdir -p ${BASE_DIR}/generated

echo "[INFO] Get images from CSV ${CSV}"

source ${BASE_DIR}/images.sh
source ${SCRIPTS_DIR}/images.sh

# todo create init method
setImagesFromDeploymentEnv
Expand All @@ -72,15 +73,17 @@ writeDigest() {
*@)
continue;;
*)
digest="$(skopeo inspect --tls-verify=false docker://${image} 2>/dev/null | jq -r '.Digest')"
# for other build methods or for falling back to other registries when not found, can apply transforms here
orig_image="${image}"
if [[ -x ${SCRIPTS_DIR}/buildDigestMapAlternateURLs.sh ]]; then
. ${SCRIPTS_DIR}/buildDigestMapAlternateURLs.sh
fi
if [[ ${digest} ]]; then
if [[ ! "${QUIET}" ]]; then echo -n "[INFO] Got digest"; fi
echo " $digest # ${image}"
else
# for other build methods or for falling back to other registries when not found, can apply transforms here
if [[ -x ${BASE_DIR}/buildDigestMapAlternateURLs.sh ]]; then
. ${BASE_DIR}/buildDigestMapAlternateURLs.sh
fi
image="${orig_image}"
digest="$(skopeo inspect --tls-verify=false docker://${image} 2>/dev/null | jq -r '.Digest')"
fi
if [[ -z ${digest} ]]; then
echo "==================== Failed to get digest for image: ${image}======================"
Expand Down
4 changes: 2 additions & 2 deletions olm/images.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
#
# Copyright (c) 2020 Red Hat, Inc.
# Copyright (c) 2019-2020 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
Expand Down Expand Up @@ -34,7 +34,7 @@ setDevfileRegistryList() {

setRegistryImages() {
registry="${1}"
registry="${registry/\@sha256:*/:${VERSION}}" # remove possible existing @sha256:... and use current version instead
registry="${registry/\@sha256:*/:${IMAGE_TAG}}" # remove possible existing @sha256:... and use current tag instead

echo -n "[INFO] Pull container ${registry} ..."
${PODMAN} pull ${registry} ${QUIET}
Expand Down
2 changes: 1 addition & 1 deletion olm/release-olm-files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,4 @@ cd "${CURRENT_DIR}"

source ${BASE_DIR}/addDigests.sh -w ${BASE_DIR} \
-r "eclipse-che-preview-.*\.v${RELEASE}.*yaml" \
-v ${RELEASE}
-t ${RELEASE}

0 comments on commit 39bceb3

Please sign in to comment.