Functions.config.sh 1.24 KB
Newer Older
据说甜蜜呢 committed
1 2 3 4 5 6 7 8
#!/bin/bash

set -e

# Import external functions
chmod +x ./devops/PipeLines/Functions.core.sh
source ./devops/PipeLines/Functions.core.sh

据说甜蜜呢 committed
9
function CreateConfig()
据说甜蜜呢 committed
10 11 12 13 14 15 16 17 18
{
	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"
据说甜蜜呢 committed
19
		echo ${AccessToken}
据说甜蜜呢 committed
20 21
		curl -X DELETE $deleteUrl -k \
		--connect-timeout $2 --max-time $3 --retry $4 \
据说甜蜜呢 committed
22
		-H 'Authorization: Bearer '${AccessToken}'' 
据说甜蜜呢 committed
23 24 25 26 27 28 29 30 31

		set -e

		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' \
据说甜蜜呢 committed
32
		-H 'Authorization: Bearer '${AccessToken}'' \
据说甜蜜呢 committed
33 34 35 36 37 38 39 40
		-d '{
	"kind": "ConfigMap",
	"apiVersion": "v1",
	"metadata": {
	"name": "'$5'",
	"namespace": "'${namespace}'"
	},
	"data": {
据说甜蜜呢 committed
41
	"'$6'":'"${configInfo}"'
据说甜蜜呢 committed
42 43 44 45 46 47 48 49 50 51 52
	}
}'
	}

	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"
}