-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add image replacement script for addon task
Add a config map to collect image replacement environmnent variables for openshift platform Add a script to find latest release tag of a step image, find its sha and replace it in openshift deploment files Signed-off-by: Nikhil Thomas <[email protected]>
- Loading branch information
1 parent
018bea9
commit aaff3b1
Showing
5 changed files
with
132 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
IMAGE_ADDONS_PARAM_BUILDER_IMAGE=registry.redhat.io/rhel8/buildah:"sha256:508f9275a14e9a87a16a4984d9f7743de9c8a9f56abd62c2a2750690c50ed270" | ||
IMAGE_ADDONS_PARAM_KN_IMAGE=registry.redhat.io/openshift-serverless-1/client-kn-rhel8:"sha256:b8b992e36f76d80b1daeed0532adf94b1ce570a6aaef1dbcc2a28c666f8cd296" | ||
IMAGE_ADDONS_SKOPEO_COPY=registry.redhat.io/rhel8/skopeo:"sha256:45b9c6e95aa1a3b19679b5c45f44f028e457608f7f64bd9aba76f12bc192611e" | ||
|
||
IMAGE_ADDONS_GENERATE=registry.redhat.io/ocp-tools-4-tech-preview/source-to-image-rhel8:"sha256:98d8cb3a255641ca6a1bce854e5e2460c20de9fb9b28e3cc67eb459f122873dd" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Copyright 2022 The Tekton Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: tekton-task-image-replacement | ||
labels: | ||
operator.tekton.dev/release: devel | ||
|
||
data: | ||
IMAGE_ADDONS_PARAM_BUILDER_IMAGE= | ||
IMAGE_ADDONS_PARAM_KN_IMAGE= | ||
IMAGE_ADDONS_SKOPEO_COPY= | ||
|
||
IMAGE_ADDONS_GENERATE= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#!/usr/bin/env bash | ||
set -e -u -o pipefail | ||
|
||
declare -r SCRIPT_NAME=$(basename "$0") | ||
declare -r SCRIPT_DIR=$(cd $(dirname "$0") && pwd) | ||
declare -r USERNAME=${REGISTRY_USER} | ||
declare -r PASSWORD=${REGISTRY_PASSWORD} | ||
|
||
log() { | ||
local level=$1; shift | ||
echo -e "$level: $@" | ||
} | ||
|
||
|
||
err() { | ||
log "ERROR" "$@" >&2 | ||
} | ||
|
||
info() { | ||
log "INFO" "$@" | ||
} | ||
|
||
die() { | ||
local code=$1; shift | ||
local msg="$@"; shift | ||
err $msg | ||
exit $code | ||
} | ||
|
||
usage() { | ||
local msg="$1" | ||
cat <<-EOF | ||
Error: $msg | ||
USAGE: | ||
REGISTRY_USER=<registry user name> REGISTRY_PASSWORD=<registry password> $SCRIPT_NAME | ||
Example: | ||
REGISTRY_USER=johnsmith REGISTRY_PASSWORD=pass123 $SCRIPT_NAME | ||
EOF | ||
exit 1 | ||
} | ||
|
||
#declare -r CATALOG_VERSION="release-v0.7" | ||
|
||
declare -A IMAGES=( | ||
["buildah"]="registry.redhat.io/rhel8/buildah" | ||
["kn"]="registry.redhat.io/openshift-serverless-1/client-kn-rhel8" | ||
["skopeo-copy"]="registry.redhat.io/rhel8/skopeo" | ||
["s2i"]="registry.redhat.io/ocp-tools-4-tech-preview/source-to-image-rhel8" | ||
) | ||
|
||
find_latest_versions() { | ||
local image_registry=${1:-""} | ||
local latest_version="" | ||
podman search --list-tags ${image_registry} | grep -v NAME | sort -r | tr -s ' ' | cut -d ' ' -f 2 | head -n 1 | ||
|
||
} | ||
|
||
find_sha_from_tag() { | ||
local image_url=${1:-""} | ||
podman run docker.io/mplatform/manifest-tool:v2.0.0 --username=${USERNAME} --password=${PASSWORD} inspect $image_url --raw | jq '.digest' | ||
} | ||
|
||
update_image_sha() { | ||
local image_prefix=${1:-""} | ||
shift | ||
local image_sha=${1:-""} | ||
shift | ||
echo replacemnet var = ${image_prefix} | ||
sed -i -E 's@('${image_prefix}').*@\1:'${image_sha}'@' config/openshift/base/.env | ||
} | ||
|
||
|
||
main() { | ||
|
||
for image in ${!IMAGES[@]}; do | ||
latest_version=$(find_latest_versions ${IMAGES[$image]}) | ||
echo latest_version=$latest_version | ||
image_url="${IMAGES[$image]}":"${latest_version}" | ||
echo $image_url | ||
image_sha=$(find_sha_from_tag "${image_url}") | ||
echo image_sha=${image_sha} | ||
update_image_sha "${IMAGES[$image]}" $image_sha | ||
|
||
done | ||
|
||
return $? | ||
} | ||
|
||
main "$@" |