Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

Add devfile commands to build/push/replace the devfile registry image #665

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
33 changes: 30 additions & 3 deletions .devfile-v2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
.Dockerfile
IMG_TAG
IMG_REG
IMG_ORG
2 changes: 1 addition & 1 deletion build/scripts/generate_devworkspace_templates.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
43 changes: 43 additions & 0 deletions patch-checluster.sh
Original file line number Diff line number Diff line change
@@ -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'
61 changes: 61 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -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