Commit 431a0d1e by 据说甜蜜呢

优化脚本

parent 64fb4b91
......@@ -13,15 +13,14 @@ echo "Begin creating ${appName}'s settings to the configmap of k8s..."
GetNameSpace namespace
kubectl create namespace ${namespace}
# global variable
GetAccessToken AccessToken
GetK8sApiServer K8sApiServer
GetAccessToken accessToken
GetK8sApiServer k8sApiServer
for servicePrefix in `ls ./src/Services|xargs -d '/'`
do
GetServiceName ${servicePrefix} serviceName
GetServiceDir ${servicePrefix} ${serviceName} serviceDir
CreateConfig ${Environment} ${namespace} ${K8sApiServer} ${serviceDir} ${servicePrefix}
CreateConfig ${Environment} ${namespace} ${k8sApiServer} ${serviceDir} ${servicePrefix} ${accessToken}
done
echo ""
......
......@@ -10,6 +10,7 @@ function CreateConfig()
{
declare ns=$2
declare apiServer=$3
declare token=$6
declare createUrl="${apiServer}/api/v1/namespaces/$2/configmaps?pretty=true"
echo ""
echo "[environment: $1, namespace: $2]"
......@@ -22,7 +23,7 @@ function CreateConfig()
curl -X DELETE $deleteUrl -k \
--connect-timeout $2 --max-time $3 --retry $4 \
-H 'Authorization: Bearer '${AccessToken}''
-H 'Authorization: Bearer '${token}''
set -e
......@@ -32,13 +33,13 @@ function CreateConfig()
--connect-timeout $2 --max-time $3 --retry $4 \
-H 'Content-Type: application/json' \
-H 'cache-control: no-cache' \
-H 'Authorization: Bearer '${AccessToken}'' \
-H 'Authorization: Bearer '${token}'' \
-d '{
"kind": "ConfigMap",
"apiVersion": "v1",
"metadata": {
"name": "'$5'",
"namespace": "'${namespace}'"
"namespace": "'${ns}'"
},
"data": {
"'$6'":'"${configInfo}"'
......
......@@ -2,81 +2,39 @@
set -e
IFS=$'\n\n'
declare appName=($(grep -oP '(?<=AppName>)[^<]+' "devops/app.props"))
# Import external functions
chmod +x ./devops/PipeLines/Functions.config.sh
source ./devops/PipeLines/Functions.config.sh
echo "Begin creating ${appName}'s settings to the configmap of k8s..."
GetAppName appName
echo ""
echo "Begin synchronizing ${appName}'s settings to the configmap of k8s..."
declare noPublishable=($(grep -oP '(?<=NoPublishable>)[^<]+' "/tmp/cicd.props"))
GetCiCdSettings allPublishable noPublishable
if [ "${noPublishable}" == "1" ] ;
then
echo ""
echo "Tips: No services need to be synced config."
else
function create()
{
if [ "$6" == "1" ];
then
declare createUrl="$3/api/v1/namespaces/$2/configmaps?pretty=true"
echo "[environment: $1, namespace: $2]"
function send()
{
set +e
declare deleteUrl="$3/api/v1/namespaces/$2/configmaps/$5"
curl -X DELETE $deleteUrl -k \
--connect-timeout $2 --max-time $3 --retry $4 \
-H 'Authorization: Bearer '${AccessToken}''
set -e
GetNameSpace namespace
GetAccessToken accessToken
GetK8sApiServer k8sApiServer
declare configInfo=$(cat $1 | jq tostring)
curl -X POST $createUrl -k \
--connect-timeout $2 --max-time $3 --retry $4 \
-H 'Content-Type: application/json' \
-H 'cache-control: no-cache' \
-H 'Authorization: Bearer '${AccessToken}'' \
-d '{
"kind": "ConfigMap",
"apiVersion": "v1",
"metadata": {
"name": "'$5'",
"namespace": "'${namespace}'"
},
"data": {
"'$6'":'"$configInfo"'
}
}'
}
for ServicePrefix in `ls ./src/Services|xargs -d '/'`
do
IsPublishableOf ServicePrefix isPublishable
declare maxTime=30
declare maxConnectTime=20
declare retryCount=5
send "$4/appsettings.json" $maxConnectTime $maxTime $retryCount "$5.appsettings.json" "appsettings.json"
send "$4/appsettings.$1.json" $maxConnectTime $maxTime $retryCount "$(echo $5.appsettings.$1.json | tr 'A-Z' 'a-z')" "appsettings.$1.json"
if [ "${isPublishable}" == "1" ];
then
GetServiceName ${ServicePrefix} serviceName
GetServiceDir ${ServicePrefix} ${serviceName} serviceDir
CreateConfig ${Environment} ${namespace} ${k8sApiServer} ${serviceDir} ${servicePrefix} ${accessToken}
else
echo ""
echo "Tips: $5 will not be synced config!!!"
fi
}
declare major=($(grep -oP '(?<=VersionMajor>)[^<]+' "devops/version.props"))
declare namespace=($(grep -oP '(?<=Namespace>)[^<]+' "devops/app.props"))
declare namespaceOfK8s=$(echo "${namespace}-v${major}" | tr 'A-Z' 'a-z')
declare k8sApiServer=($(grep -oP '(?<=K8sApiServer>)[^<]+' "devops/deploy.props"))
declare services=$(ls -l src/services | awk 'NR>1')
declare servicePrefix=""
for service in ${services}
do
servicePrefix=($(echo ${service} | awk '{print $9}'))
declare isPublishable=($(grep -oP "(?<=${servicePrefix}Publishable>)[^<]+" "/tmp/cicd.props"))
Create ${Environment} ${namespaceOfK8s} ${k8sApiServer} "./src/${servicePrefix}.API" "${servicePrefix}" ${isPublishable}
done
fi
echo ""
echo "End creating app settings to the configmap of k8s..."
\ No newline at end of file
echo "End synchronizing app settings to the configmap of k8s..."
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment