From 9b5e594c4434b1e7093b9592e1e78c4c03b99624 Mon Sep 17 00:00:00 2001 From: "kube:admin" Date: Tue, 19 Jul 2022 16:18:12 +0000 Subject: [PATCH 1/5] Add devfile commands to build/push/replace the devfile registry image Signed-off-by: kube:admin --- .devfile-v2.yaml | 32 +++++++++++++++++++++++++++++--- patch-checluster.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 3 deletions(-) create mode 100755 patch-checluster.sh diff --git a/.devfile-v2.yaml b/.devfile-v2.yaml index 2e7ee0419..a79a04f5f 100644 --- a/.devfile-v2.yaml +++ b/.devfile-v2.yaml @@ -32,13 +32,39 @@ components: ephemeral: true commands: - - id: 1-build + - id: 1-build-metadata exec: commandLine: './build/dev/build-devfile-registry.sh' component: devtools - label: 1. build devfile-registry - - id: 2-start + label: 1. build devfile-registry index.json + - id: 2-start-locally exec: commandLine: './build/dev/start-devfile-registry.sh' component: che-devfile-registry-prod label: 2. start devfile-registry + - id: 3-build-image + exec: + commandLine: > + ([ ! -f ./IMG_REG ] && echo "File ./IMG_REG not found, please create one to specify the container registry (for example \"quay.io\")") || + ([ ! -f ./IMG_ORG ] && echo "File ./IMG_ORG not found, please create one to specify the container registry organization (for example \"eclipse\")") || + (date +%s > ./IMG_TAG; ./build.sh --tag $(cat ./IMG_TAG) --registry $(cat ./IMG_REG) --organization $(cat ./IMG_ORG)) + component: devtools + label: 3. build che-devfile-registry image + - id: 4-publish-image + exec: + commandLine: > + ([ ! -f ./IMG_REG ] && echo "File ./IMG_REG not found, please create one to specify the image registry (for example \"quay.io\")") || + ([ ! -f ./IMG_ORG ] && echo "File ./IMG_ORG not found, please create one to specify the image organization (for example \"eclipse\")") || + ([ ! -f ./IMG_TAG ] && echo "File ./IMG_TAG not found, please create one to specify the image tag (for example \"next\")") || + buildah push $(cat ./IMG_REG)/$(cat ./IMG_ORG)/che-devfile-registry:$(cat ./IMG_TAG) + component: devtools + label: 4. push che-devfile-registry image to a registry + - id: 5-replace-current-devfile-registry-image + exec: + commandLine: > + ([ ! -f ./IMG_REG ] && echo "File ./IMG_REG not found, please create one to specify the image registry (for example \"quay.io\")") || + ([ ! -f ./IMG_ORG ] && echo "File ./IMG_ORG not found, please create one to specify the image organization (for example \"eclipse\")") || + ([ ! -f ./IMG_TAG ] && echo "File ./IMG_TAG not found, please create one to specify the image tag (for example \"next\")") || + ./patch-checluster.sh $(cat ./IMG_REG)/$(cat ./IMG_ORG)/che-devfile-registry:$(cat ./IMG_TAG) + component: devtools + label: 5. replace devfile registry image on current cluster diff --git a/patch-checluster.sh b/patch-checluster.sh new file mode 100755 index 000000000..6b4945706 --- /dev/null +++ b/patch-checluster.sh @@ -0,0 +1,43 @@ +#!/bin/bash +# +# Copyright (c) 2018-2021 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/ +# +# SPDX-License-Identifier: EPL-2.0 +# +# Arguments +# $1 - the new devfile registry image +# + +set -e -u + +IMAGE=$1 +CHECLUSTER_NAME="$(kubectl get checluster --all-namespaces -o json | jq -r '.items[0].metadata.name')" +CHECLUSTER_NAMESPACE="$(kubectl get checluster --all-namespaces -o json | jq -r '.items[0].metadata.namespace')" + +TMPDIR="$(mktemp -d)" +trap 'rm -rf -- "$TMPDIR"' EXIT +cat << EOF > ${TMPDIR}/patch-file.yaml +spec: + components: + devfileRegistry: + deployment: + containers: + - name: devfile-registry + image: ${IMAGE} +EOF + +echo "Patching CheCluster ${CHECLUSTER_NAME} in namespace ${CHECLUSTER_NAMESPACE} to use ${IMAGE} as devfile registry image." +echo +echo "Original CheCluster .spec.components.devfileRegistry:" +kubectl get -n "${CHECLUSTER_NAMESPACE}" checluster "${CHECLUSTER_NAME}" -o json | jq '.spec.components.devfileRegistry' +echo +echo "Patch file:" +cat ${TMPDIR}/patch-file.yaml +echo +kubectl patch -n "${CHECLUSTER_NAMESPACE}" checluster "${CHECLUSTER_NAME}" --type merge --patch "$(cat ${TMPDIR}/patch-file.yaml)" +echo +echo "Patched CheCluster .spec.components.devfileRegistry:" +kubectl get -n "${CHECLUSTER_NAMESPACE}" checluster "${CHECLUSTER_NAME}" -o json | jq '.spec.components.devfileRegistry' From 230ac3d7793b5605cc29ad732d6c2f4253ec5d0f Mon Sep 17 00:00:00 2001 From: "kube:admin" Date: Thu, 21 Jul 2022 10:39:40 +0000 Subject: [PATCH 2/5] Fix shellcheck errors Signed-off-by: kube:admin --- patch-checluster.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/patch-checluster.sh b/patch-checluster.sh index 6b4945706..542a76369 100755 --- a/patch-checluster.sh +++ b/patch-checluster.sh @@ -19,7 +19,7 @@ CHECLUSTER_NAMESPACE="$(kubectl get checluster --all-namespaces -o json | jq -r TMPDIR="$(mktemp -d)" trap 'rm -rf -- "$TMPDIR"' EXIT -cat << EOF > ${TMPDIR}/patch-file.yaml +cat << EOF > "${TMPDIR}"/patch-file.yaml spec: components: devfileRegistry: @@ -35,9 +35,9 @@ echo "Original CheCluster .spec.components.devfileRegistry:" kubectl get -n "${CHECLUSTER_NAMESPACE}" checluster "${CHECLUSTER_NAME}" -o json | jq '.spec.components.devfileRegistry' echo echo "Patch file:" -cat ${TMPDIR}/patch-file.yaml +cat "${TMPDIR}"/patch-file.yaml echo -kubectl patch -n "${CHECLUSTER_NAMESPACE}" checluster "${CHECLUSTER_NAME}" --type merge --patch "$(cat ${TMPDIR}/patch-file.yaml)" +kubectl patch -n "${CHECLUSTER_NAMESPACE}" checluster "${CHECLUSTER_NAME}" --type merge --patch "$(cat "${TMPDIR}"/patch-file.yaml)" echo echo "Patched CheCluster .spec.components.devfileRegistry:" kubectl get -n "${CHECLUSTER_NAMESPACE}" checluster "${CHECLUSTER_NAME}" -o json | jq '.spec.components.devfileRegistry' From ae11215747259f4527cb3216e350f083d3d4015e Mon Sep 17 00:00:00 2001 From: "kube:admin" Date: Thu, 21 Jul 2022 18:33:14 +0000 Subject: [PATCH 3/5] tests with openshift registry --- .devfile-v2.yaml | 2 +- .gitignore | 3 + .../generate_devworkspace_templates.sh | 2 +- test.sh | 61 +++++++++++++++++++ 4 files changed, 66 insertions(+), 2 deletions(-) create mode 100755 test.sh diff --git a/.devfile-v2.yaml b/.devfile-v2.yaml index a79a04f5f..c4a3f306f 100644 --- a/.devfile-v2.yaml +++ b/.devfile-v2.yaml @@ -47,7 +47,7 @@ commands: commandLine: > ([ ! -f ./IMG_REG ] && echo "File ./IMG_REG not found, please create one to specify the container registry (for example \"quay.io\")") || ([ ! -f ./IMG_ORG ] && echo "File ./IMG_ORG not found, please create one to specify the container registry organization (for example \"eclipse\")") || - (date +%s > ./IMG_TAG; ./build.sh --tag $(cat ./IMG_TAG) --registry $(cat ./IMG_REG) --organization $(cat ./IMG_ORG)) + (date +%s > ./IMG_TAG; BUILDER=buildah ./build.sh --tag $(cat ./IMG_TAG) --registry $(cat ./IMG_REG) --organization $(cat ./IMG_ORG)) component: devtools label: 3. build che-devfile-registry image - id: 4-publish-image diff --git a/.gitignore b/.gitignore index 187ab9baf..d8ce3a459 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ .Dockerfile +IMG_TAG +IMG_REG +IMG_ORG diff --git a/build/scripts/generate_devworkspace_templates.sh b/build/scripts/generate_devworkspace_templates.sh index 780892528..f182ee4a9 100755 --- a/build/scripts/generate_devworkspace_templates.sh +++ b/build/scripts/generate_devworkspace_templates.sh @@ -41,7 +41,7 @@ do --output-file:"${dir}"/devworkspace-che-code-insiders.yaml \ --project."${name}={{ INTERNAL_URL }}/resources/v2/${name}.zip" - # When release is happend, we need to replace tags of images in che-theia editor + # When release is happening, we need to replace tags of images in che-theia editor if [ -n "$VERSION" ]; then cheTheia="quay.io/eclipse/che-theia" cheTheiaEndpointRuntimeBinary="${cheTheia}-endpoint-runtime-binary" diff --git a/test.sh b/test.sh new file mode 100755 index 000000000..289a18409 --- /dev/null +++ b/test.sh @@ -0,0 +1,61 @@ +#!/bin/bash +# +# Copyright (c) 2018-2021 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/ +# +# SPDX-License-Identifier: EPL-2.0 +# +# Arguments +# $1 - the new devfile registry image +# + +set -e -u + +IMG_REG_FILE="./IMG_REG" +IMG_ORG_FILE="./IMG_ORG" +IMG_TAG_FILE="./IMG_TAG" + +DEFAULT_REG="image-registry.openshift-image-registry.svc:5000" +DEFAULT_ORG=$(kubectl get namespaces -o json | jq -r '.items[0].metadata.name') +DEFAULT_TAG="custom" + +if [ ! -f "${IMG_REG_FILE}" ]; then + echo "${DEFAULT_REG}" > "${IMG_REG_FILE}" +fi +REG=$(cat "${IMG_REG_FILE}") + +if [ ! -f "{$IMG_ORG_FILE}" ]; then + echo "${DEFAULT_ORG}" > "${IMG_ORG_FILE}" +fi +ORG=$(cat "${IMG_ORG_FILE}") + +if [ ! -f "${IMG_TAG_FILE}" ]; then + echo "${DEFAULT_TAG}" > "${IMG_TAG_FILE}" +fi +TAG=$(cat "${IMG_TAG_FILE}") + +# 1. build +BUILDER=podman ./build.sh --tag "${TAG}" --registry "${REG}" --organization "${ORG}" + +# 2. push +USER=$(oc whoami | sed 's/://g') +PASSWORD=$(oc whoami -t) +CERT_DIR="/var/run/secrets/kubernetes.io/serviceaccount/" +podman login -u "${USER}" -p "${PASSWORD}" --cert-dir "${CERT_DIR}" "${REG}" +podman push --cert-dir "${CERT_DIR}" "${REG}"/"${ORG}"/che-devfile-registry:"${TAG}" + +# 3. run openshift +oc new-app -f deploy/openshift/che-devfile-registry.yaml \ + -p IMAGE="${REG}/${ORG}/che-devfile-registry" \ + -p IMAGE_TAG="${TAG}" \ + -p PULL_POLICY="Always" + +# 3. delete openshift +# oc delete deploymentconfigs/che-devfile-registry \ +# services/che-devfile-registry \ +# routes/che-devfile-registry \ +# configmaps/che-devfile-registry + +# 4. replace From 79df8d044f16dfd0bc1cc7a24a7cfa28ede75582 Mon Sep 17 00:00:00 2001 From: Mario Loriedo Date: Thu, 1 Sep 2022 16:58:09 +0000 Subject: [PATCH 4/5] Update devfile commands Signed-off-by: Mario Loriedo --- .devfile-v2.yaml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.devfile-v2.yaml b/.devfile-v2.yaml index c4a3f306f..fece65811 100644 --- a/.devfile-v2.yaml +++ b/.devfile-v2.yaml @@ -45,9 +45,10 @@ commands: - id: 3-build-image exec: commandLine: > - ([ ! -f ./IMG_REG ] && echo "File ./IMG_REG not found, please create one to specify the container registry (for example \"quay.io\")") || - ([ ! -f ./IMG_ORG ] && echo "File ./IMG_ORG not found, please create one to specify the container registry organization (for example \"eclipse\")") || - (date +%s > ./IMG_TAG; BUILDER=buildah ./build.sh --tag $(cat ./IMG_TAG) --registry $(cat ./IMG_REG) --organization $(cat ./IMG_ORG)) + read -p "ENTER the image registry (for example \"quay.io\")")" IMG_REG + read -p "ENTER the image organization (for example \"eclipse\")")" IMG_ORG + read -p "ENTER the image tag (for example \"next\")")" IMG_TAG + BUILDER=buildah ./build.sh --tag $IMG_TAG --registry $IMG_REG --organization $IMG_ORG component: devtools label: 3. build che-devfile-registry image - id: 4-publish-image From c296826924dc5ed6319a7205867f25240a4a48ab Mon Sep 17 00:00:00 2001 From: Mario Loriedo Date: Thu, 1 Sep 2022 17:56:02 +0000 Subject: [PATCH 5/5] Fixes to commands Signed-off-by: Mario Loriedo --- .devfile-v2.yaml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.devfile-v2.yaml b/.devfile-v2.yaml index fece65811..5cb6135d6 100644 --- a/.devfile-v2.yaml +++ b/.devfile-v2.yaml @@ -45,27 +45,27 @@ commands: - id: 3-build-image exec: commandLine: > - read -p "ENTER the image registry (for example \"quay.io\")")" IMG_REG - read -p "ENTER the image organization (for example \"eclipse\")")" IMG_ORG - read -p "ENTER the image tag (for example \"next\")")" IMG_TAG - BUILDER=buildah ./build.sh --tag $IMG_TAG --registry $IMG_REG --organization $IMG_ORG + read -p "ENTER the image registry (for example \"quay.io\"): " IMG_REG && + read -p "ENTER the image organization (for example \"eclipse\"): " IMG_ORG && + read -p "ENTER the image tag (for example \"next\"): " IMG_TAG && + BUILDER=buildah ./build.sh --tag ${IMG_TAG} --registry ${IMG_REG} --organization ${IMG_ORG} component: devtools label: 3. build che-devfile-registry image - id: 4-publish-image exec: commandLine: > - ([ ! -f ./IMG_REG ] && echo "File ./IMG_REG not found, please create one to specify the image registry (for example \"quay.io\")") || - ([ ! -f ./IMG_ORG ] && echo "File ./IMG_ORG not found, please create one to specify the image organization (for example \"eclipse\")") || - ([ ! -f ./IMG_TAG ] && echo "File ./IMG_TAG not found, please create one to specify the image tag (for example \"next\")") || - buildah push $(cat ./IMG_REG)/$(cat ./IMG_ORG)/che-devfile-registry:$(cat ./IMG_TAG) + read -p "ENTER the image registry (for example \"quay.io\"): " IMG_REG && + read -p "ENTER the image organization (for example \"eclipse\"): " IMG_ORG && + read -p "ENTER the image tag (for example \"next\"): " IMG_TAG && + buildah push ${IMG_REG}/${IMG_ORG}/che-devfile-registry:${IMG_TAG} component: devtools label: 4. push che-devfile-registry image to a registry - id: 5-replace-current-devfile-registry-image exec: commandLine: > - ([ ! -f ./IMG_REG ] && echo "File ./IMG_REG not found, please create one to specify the image registry (for example \"quay.io\")") || - ([ ! -f ./IMG_ORG ] && echo "File ./IMG_ORG not found, please create one to specify the image organization (for example \"eclipse\")") || - ([ ! -f ./IMG_TAG ] && echo "File ./IMG_TAG not found, please create one to specify the image tag (for example \"next\")") || - ./patch-checluster.sh $(cat ./IMG_REG)/$(cat ./IMG_ORG)/che-devfile-registry:$(cat ./IMG_TAG) + read -p "ENTER the image registry (for example \"quay.io\"): " IMG_REG && + read -p "ENTER the image organization (for example \"eclipse\"): " IMG_ORG && + read -p "ENTER the image tag (for example \"next\"): " IMG_TAG && + ./patch-checluster.sh ${IMG_REG}/${IMG_ORG}/che-devfile-registry:${IMG_TAG} component: devtools label: 5. replace devfile registry image on current cluster