From 46ef921a9880583fe1e41364c474092ed1a812cc Mon Sep 17 00:00:00 2001 From: KingsonKai <562419972@qq.com> Date: Fri, 2 Jun 2023 17:25:49 +0800 Subject: [PATCH] enhancement: Optimize deployment scripts and support local deployment --- chaosmeta-inject-operator/build/build.sh | 3 +- .../build/deploy/deploy.sh | 43 ++++++++++++++----- .../build/deploy/undeploy.sh | 34 +++++++++++++-- 3 files changed, 65 insertions(+), 15 deletions(-) diff --git a/chaosmeta-inject-operator/build/build.sh b/chaosmeta-inject-operator/build/build.sh index 1b4e768..fe4bb6c 100644 --- a/chaosmeta-inject-operator/build/build.sh +++ b/chaosmeta-inject-operator/build/build.sh @@ -2,7 +2,8 @@ set -e -ROOT_PATH=$(dirname $(readlink -f $0))/.. +BASE_DIR=`cd $(dirname $0); pwd` +ROOT_PATH=${BASE_DIR}/.. echo "${ROOT_PATH}" kubectl create configmap chaosmeta-inject-config --from-file="${ROOT_PATH}"/config/chaosmeta-inject.json -n chaosmeta diff --git a/chaosmeta-inject-operator/build/deploy/deploy.sh b/chaosmeta-inject-operator/build/deploy/deploy.sh index fc9f5d2..9b0be5b 100644 --- a/chaosmeta-inject-operator/build/deploy/deploy.sh +++ b/chaosmeta-inject-operator/build/deploy/deploy.sh @@ -1,19 +1,42 @@ #!/bin/bash set -e + +NOW_DIR=`cd $(dirname $0); pwd` VERSION=$1 +if [ -z "$VERSION" ]; then + echo "version is empty" + exit 1 +fi +echo "version: ${VERSION}" + +function downloadfile() { + url=$1 + filename=$2 + echo "download from: ${url}" + if [ ! -e "${filename}" ]; then + curl -o "${filename}" "${url}" + fi + echo "download success: ${filename}" +} -ROOT_PATH=$(dirname $(readlink -f $0))/chaosmeta_build -echo "${ROOT_PATH}" -mkdir -p "${ROOT_PATH}"/build -mkdir -p "${ROOT_PATH}"/config -mkdir -p "${ROOT_PATH}"/yamls +ROOT_PATH=${NOW_DIR}/../ +if [ "${VERSION}" != "local" ]; then + ROOT_PATH=${NOW_DIR}/chaosmeta_build + echo "${ROOT_PATH}" + mkdir -p "${ROOT_PATH}"/build "${ROOT_PATH}"/config "${ROOT_PATH}"/yamls + preurl=https://raw.githubusercontent.com/traas-stack/chaosmeta/"${VERSION}"/chaosmeta-inject-operator -curl -o "${ROOT_PATH}"/config/chaosmeta-inject.json https://raw.githubusercontent.com/traas-stack/chaosmeta/"${VERSION}"/chaosmeta-inject-operator/config/chaosmeta-inject.json -curl -o "${ROOT_PATH}"/build/build.sh https://raw.githubusercontent.com/traas-stack/chaosmeta/"${VERSION}"/chaosmeta-inject-operator/build/build.sh -curl -o "${ROOT_PATH}"/yamls/chaosmeta.yaml https://raw.githubusercontent.com/traas-stack/chaosmeta/"${VERSION}"/chaosmeta-inject-operator/build/yamls/chaosmeta.yaml -curl -o "${ROOT_PATH}"/yamls/chaosmeta-daemonset.yaml https://raw.githubusercontent.com/traas-stack/chaosmeta/"${VERSION}"/chaosmeta-inject-operator/build/yamls/chaosmeta-daemonset.yaml + downloadfile "${preurl}"/config/chaosmeta-inject.json "${ROOT_PATH}"/config/chaosmeta-inject.json + downloadfile "${preurl}"/build/build.sh "${ROOT_PATH}"/build/build.sh + downloadfile "${preurl}"/build/yamls/chaosmeta.yaml "${ROOT_PATH}"/yamls/chaosmeta.yaml + downloadfile "${preurl}"/build/yamls/chaosmeta-daemonset.yaml "${ROOT_PATH}"/yamls/chaosmeta-daemonset.yaml +fi kubectl apply -f "${ROOT_PATH}"/yamls/chaosmeta.yaml kubectl apply -f "${ROOT_PATH}"/yamls/chaosmeta-daemonset.yaml -sh "${ROOT_PATH}"/build/build.sh +if [ "${VERSION}" != "local" ]; then + sh "${ROOT_PATH}"/build/build.sh +else + sh "${ROOT_PATH}"/build.sh +fi diff --git a/chaosmeta-inject-operator/build/deploy/undeploy.sh b/chaosmeta-inject-operator/build/deploy/undeploy.sh index 7a18031..79bb86f 100644 --- a/chaosmeta-inject-operator/build/deploy/undeploy.sh +++ b/chaosmeta-inject-operator/build/deploy/undeploy.sh @@ -1,9 +1,35 @@ #!/bin/bash set -e + +NOW_DIR=`cd $(dirname $0); pwd` VERSION=$1 -ROOT_PATH=$(dirname $(readlink -f $0))/chaosmeta_build -echo "${ROOT_PATH}" -mkdir -p "${ROOT_PATH}"/yamls -curl -o "${ROOT_PATH}"/yamls/chaosmeta.yaml https://raw.githubusercontent.com/traas-stack/chaosmeta/"${VERSION}"/chaosmeta-inject-operator/build/yamls/chaosmeta.yaml +if [ -z "$VERSION" ]; then + echo "version is empty" + exit 1 +fi +echo "version: ${VERSION}" + +function downloadfile() { + url=$1 + filename=$2 + echo "download from: ${url}" + if [ ! -e "${filename}" ]; then + curl -o "${filename}" "${url}" + fi + echo "download success: ${filename}" +} + +ROOT_PATH=${NOW_DIR}/../ +if [ "${VERSION}" != "local" ]; then + ROOT_PATH=${NOW_DIR}/chaosmeta_build + echo "${ROOT_PATH}" + mkdir -p "${ROOT_PATH}"/yamls + filename="${ROOT_PATH}"/yamls/chaosmeta.yaml + + if [ ! -e "${filename}" ]; then + downloadfile https://raw.githubusercontent.com/traas-stack/chaosmeta/"${VERSION}"/chaosmeta-inject-operator/build/yamls/chaosmeta.yaml "${filename}" + fi +fi + kubectl delete -f "${ROOT_PATH}"/yamls/chaosmeta.yaml