Commit 3f6a0f96 by 李二毛

Merge branch 'development' into 'rel/major'

Development

See merge request liermao/microservice-autodevopspipelines!38
parents 3a3c41af b4de3044
Pipeline #4145 failed with stages
in 17 seconds
......@@ -19,7 +19,7 @@ staging-major_job:
- export K8sApiServer='https://172.24.83.222:6443'
# 001 Continuous integration image to registry.
- bash ./devops/PipeLines/Creation/001_CI.sh
# - bash ./devops/PipeLines/Creation/001_CI.sh
# 002 Create config information to k8s's configmap.
- bash ./devops/PipeLines/Creation/002_CreateConfig.sh
......
......@@ -2,68 +2,23 @@
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
GetAppName appName
echo ""
echo "Begin creating ${appName}'s settings to the configmap of k8s..."
function Create()
{
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
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"'
}
}'
}
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"
}
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"))
kubectl create namespace ${namespaceOfK8s}
GetNameSpace namespace
kubectl create namespace ${namespace}
declare services=$(ls -l src/services | awk 'NR>1')
declare servicePrefix=""
for service in ${services}
for servicePrefix in `ls ./src/Services|xargs -d '/'`
do
servicePrefix=($(echo ${service} | awk '{print $9}'))
Create ${Environment} ${namespaceOfK8s} ${k8sApiServer} "./src/${servicePrefix}.API" "${servicePrefix}"
GetServiceName ${servicePrefix} serviceName
GetServiceDir ${servicePrefix} ${serviceName} serviceDir
Create ${Environment} ${namespace} ${K8sApiServer} ${serviceDir} ${servicePrefix}
done
echo ""
......
#!/bin/bash
set -e
# Import external functions
chmod +x ./devops/PipeLines/Functions.core.sh
source ./devops/PipeLines/Functions.core.sh
function Create()
{
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
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"'
}
}'
}
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"
}
\ No newline at end of file
......@@ -22,6 +22,14 @@ function GetServiceCsProjFile()
eval $3="${csprojFile}"
}
function GetServiceDir()
{
declare prefix=${1}
declare name=${2}
declare dir="./src/Services/${prefix}/${name}"
eval $3="${dir}"
}
function GetServiceName()
{
declare prefix=${1}
......@@ -35,6 +43,14 @@ function GetAppName()
eval $1="${name}"
}
function GetNameSpace()
{
GetMajor major
declare namespace=($(grep -oP '(?<=Namespace>)[^<]+' "devops/app.props"))
declare namespaceOfK8s=$(echo "${namespace}-v${major}" | tr 'A-Z' 'a-z')
eval $1=${namespaceOfK8s}
}
function GetSolutionName()
{
declare name=($(grep -oP '(?<=SolutionName>)[^<]+' "./devops/app.props"))
......
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