diff --git a/.devfile-v2.yaml b/.devfile-v2.yaml index 2e7ee0419..5cb6135d6 100644 --- a/.devfile-v2.yaml +++ b/.devfile-v2.yaml @@ -32,13 +32,40 @@ 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: > + 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: > + 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: > + 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 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/patch-checluster.sh b/patch-checluster.sh new file mode 100755 index 000000000..542a76369 --- /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' 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