From 3420bf96b652e8a4326e15b6db5bfbe0cd6330fb Mon Sep 17 00:00:00 2001 From: Pudong Zheng Date: Wed, 24 Apr 2024 14:53:36 +0000 Subject: [PATCH] add ide configmap patch --- dev/preview/workflow/preview/deploy-gitpod.sh | 21 ++++++-------- .../workflow/preview/patch-ide-configmap.js | 29 +++++++++++++++++++ dev/preview/workflow/preview/post-process.sh | 15 ++++++++++ 3 files changed, 53 insertions(+), 12 deletions(-) create mode 100644 dev/preview/workflow/preview/patch-ide-configmap.js diff --git a/dev/preview/workflow/preview/deploy-gitpod.sh b/dev/preview/workflow/preview/deploy-gitpod.sh index 8dd5bf78cbaf83..5dc37134ab0363 100755 --- a/dev/preview/workflow/preview/deploy-gitpod.sh +++ b/dev/preview/workflow/preview/deploy-gitpod.sh @@ -11,9 +11,6 @@ source "$(realpath "${SCRIPT_PATH}/../lib/common.sh")" # shellcheck source=../lib/k8s-util.sh source "$(realpath "${SCRIPT_PATH}/../lib/k8s-util.sh")" -DEV_KUBE_PATH="${DEV_KUBE_PATH:-/home/gitpod/.kube/config}" -DEV_KUBE_CONTEXT="${DEV_KUBE_CONTEXT:-dev}" - PREVIEW_NAME="${PREVIEW_NAME:-$(previewctl get name)}" PREVIEW_K3S_KUBE_PATH="${PREVIEW_K3S_KUBECONFIG_PATH:-/home/gitpod/.kube/config}" PREVIEW_K3S_KUBE_CONTEXT="${PREVIEW_K3S_KUBE_CONTEXT:-$PREVIEW_NAME}" @@ -31,15 +28,15 @@ GITPOD_WITH_DEDICATED_EMU="${GITPOD_WITH_DEDICATED_EMU:-false}" PREVIEW_GCP_PROJECT="gitpod-dev-preview" -# if [[ "${VERSION:-}" == "" ]]; then -# if [[ ! -f /tmp/local-dev-version ]]; then -# log_error "VERSION is not set and no fallback version exists in /tmp/local-dev-version." -# log_info "Please run leeway run dev/preview:build or set VERSION" -# exit 1 -# fi -# VERSION="$(cat /tmp/local-dev-version)" -# log_info "VERSION is not set - using value from /tmp/local-dev-version which is $VERSION" -# fi +if [[ "${VERSION:-}" == "" ]]; then + if [[ ! -f /tmp/local-dev-version ]]; then + log_error "VERSION is not set and no fallback version exists in /tmp/local-dev-version." + log_info "Please run leeway run dev/preview:build or set VERSION" + exit 1 + fi + VERSION="$(cat /tmp/local-dev-version)" + log_info "VERSION is not set - using value from /tmp/local-dev-version which is $VERSION" +fi INSTALLER_CONFIG_PATH="${INSTALLER_CONFIG_PATH:-$(mktemp "/tmp/XXXXXX.gitpod.config.yaml")}" INSTALLER_RENDER_PATH="k8s.yaml" # k8s.yaml is hardcoded in post-prcess.sh - we can fix that later. diff --git a/dev/preview/workflow/preview/patch-ide-configmap.js b/dev/preview/workflow/preview/patch-ide-configmap.js new file mode 100644 index 00000000000000..88468a008db6c8 --- /dev/null +++ b/dev/preview/workflow/preview/patch-ide-configmap.js @@ -0,0 +1,29 @@ +const fs = require("fs"); +let json = JSON.parse(fs.readFileSync(process.argv[2]).toString()); + +function replaceImage(image) { + return image.replace("gitpod-dev-artifact", "gitpod-core-dev"); +} + +for (let ide in json.ideOptions.options) { + if (["clion", "goland", "intellij", "phpstorm", "pycharm", "rider", "rubymine", "webstorm"].includes(ide)) { + json.ideOptions.options[ide].latestImage = replaceImage(json.ideOptions.options[ide].latestImage); + json.ideOptions.options[ide].versions = json.ideOptions.options[ide].versions?.map((version) => { + version.image = replaceImage(version.image); + return version; + }); + } + if (["code", "code1_85"].includes(ide)) { + json.ideOptions.options[ide].image = replaceImage(json.ideOptions.options[ide].image); + json.ideOptions.options[ide].versions = json.ideOptions.options[ide].versions?.map((version) => { + version.image = replaceImage(version.image); + return version; + }); + } + if (["intellij-previous"].includes(ide)) { + json.ideOptions.options[ide].image = replaceImage(json.ideOptions.options[ide].image); + json.ideOptions.options[ide].imageLayers = json.ideOptions.options[ide].imageLayers.map((i) => replaceImage(i)); + } +} + +fs.writeFileSync(process.argv[2], JSON.stringify(json)); diff --git a/dev/preview/workflow/preview/post-process.sh b/dev/preview/workflow/preview/post-process.sh index de5c62cd3ec56f..2f7782e1d3c5ed 100755 --- a/dev/preview/workflow/preview/post-process.sh +++ b/dev/preview/workflow/preview/post-process.sh @@ -18,6 +18,8 @@ REG_DAEMON_PORT="31750" DEV_BRANCH=$1 SMITH_TOKEN=$2 +SCRIPT_PATH=$(realpath "$(dirname "$0")") + if [[ -z ${REG_DAEMON_PORT} ]] || [[ -z ${DEV_BRANCH} ]] || [[ -z ${SMITH_TOKEN} ]]; then echo "One or more input params were invalid: ${REG_DAEMON_PORT} ${DEV_BRANCH} ${SMITH_TOKEN}" exit 1 @@ -143,6 +145,19 @@ while [ "$documentIndex" -le "$DOCS" ]; do yq m -x -i k8s.yaml -d "$documentIndex" /tmp/"$NAME"overrides.yaml fi + # overrides for ide-config configmap + if [[ "ide-config" == "$NAME" ]] && [[ "$KIND" == "ConfigMap" ]]; then + WORK="overrides for $NAME $KIND" + echo "$WORK" + touch /tmp/"$NAME"-overrides.yaml + + yq r k8s.yaml -d "$documentIndex" data | yq prefix - data > /tmp/"$NAME"-overrides.yaml + yq r /tmp/"$NAME"-overrides.yaml 'data.[config.json]' > /tmp/"$NAME"-overrides.json + node "$SCRIPT_PATH/patch-ide-configmap.js" /tmp/"$NAME"-overrides.json + yq w -i /tmp/"$NAME"-overrides.yaml "data.[config.json]" -- "$(< /tmp/"$NAME"-overrides.json)" + yq m -x -i k8s.yaml -d "$documentIndex" /tmp/"$NAME"-overrides.yaml + fi + # override details for Minio if [[ "minio" == "$NAME" ]] && [[ "$KIND" == "Deployment" ]]; then WORK="overrides for $NAME $KIND"