Commit f9fad4c2 by 李二毛

Merge branch 'development' into 'master'

Development

See merge request liermao/microservice-autodevopspipelines!74
parents a08c8a83 8a81a27e
Pipeline #4303 passed with stage
in 15 seconds
stages: stages:
- build - build
- staging-release-major # Creation
- release-major
# Updating
- analysing-git-changes
- synchronizing-config
build_job: build_job:
stage: build stage: build
script: script:
- echo "begin build..." - bash ./devops/PipeLines/Build.sh
- dotnet build MicroService.AutoDevOpsPipeLines.sln
- echo "build successful."
tags: tags:
- local - build
staging-major_job: staging-major_job:
stage: staging-release-major stage: release-major
script: script:
- export RegistryHost='registry.geekbuying.com:8100'
- export Environment='Staging' - export Environment='Staging'
- export K8sApiServer='https://172.24.83.222:6443' - bash ./devops/PipeLines/Creation/Creation_Pipeline.sh
only:
# 001 Continuous integration image to registry. - rel/major
- bash ./devops/PipeLines/CI.sh tags:
- staging
# 002 Create config information to k8s's configmap. prod-major_job:
- bash ./devops/PipeLines/Creation/CreateConfig.sh stage: release-major
script:
- export Environment='Production'
- bash ./devops/PipeLines/Creation/Creation_Pipeline.sh
only:
- rel/major
tags:
- production
# 003 Release major to k8s's cluster. staging-analysing-git-changes_job:
- bash ./devops/PipeLines/Creation/ReleaseMajor.sh stage: analysing-git-changes
script:
- export Environment='Staging'
- bash ./devops/PipeLines/Updating/001_AnalysingGitChanges.sh
only:
- staging
tags:
- staging
# 004 Create gateway route. staging-synchronizing-config_job:
- bash ./devops/PipeLines/Creation/Gateways/Kong/CreateGatewayRoute.sh stage: synchronizing-config
script:
- export Environment='Staging'
- bash ./devops/PipeLines/Updating/002_SyncConfig.sh
only: only:
- rel/major - staging
tags: tags:
- staging - staging
\ No newline at end of file
...@@ -51,7 +51,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "BuildingBlocks", "BuildingB ...@@ -51,7 +51,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "BuildingBlocks", "BuildingB
EndProject EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Extensions", "Extensions", "{26EA0840-FACE-4F72-B7D0-64CA9443BD9F}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Extensions", "Extensions", "{26EA0840-FACE-4F72-B7D0-64CA9443BD9F}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MvcExtensions", "src\BuildingBlocks\Extensions\MvcExtensions\MvcExtensions.csproj", "{8E88AA1F-8D4F-4FA6-9B94-03203BB5F739}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MvcExtensions", "src\BuildingBlocks\Extensions\MvcExtensions\MvcExtensions.csproj", "{2FFD7AC6-1A55-4B6E-BF9D-1B85CC5AE193}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
...@@ -87,10 +87,10 @@ Global ...@@ -87,10 +87,10 @@ Global
{94C559A6-82AA-4149-9616-E6EC78753766}.Debug|Any CPU.Build.0 = Debug|Any CPU {94C559A6-82AA-4149-9616-E6EC78753766}.Debug|Any CPU.Build.0 = Debug|Any CPU
{94C559A6-82AA-4149-9616-E6EC78753766}.Release|Any CPU.ActiveCfg = Release|Any CPU {94C559A6-82AA-4149-9616-E6EC78753766}.Release|Any CPU.ActiveCfg = Release|Any CPU
{94C559A6-82AA-4149-9616-E6EC78753766}.Release|Any CPU.Build.0 = Release|Any CPU {94C559A6-82AA-4149-9616-E6EC78753766}.Release|Any CPU.Build.0 = Release|Any CPU
{8E88AA1F-8D4F-4FA6-9B94-03203BB5F739}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {2FFD7AC6-1A55-4B6E-BF9D-1B85CC5AE193}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8E88AA1F-8D4F-4FA6-9B94-03203BB5F739}.Debug|Any CPU.Build.0 = Debug|Any CPU {2FFD7AC6-1A55-4B6E-BF9D-1B85CC5AE193}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8E88AA1F-8D4F-4FA6-9B94-03203BB5F739}.Release|Any CPU.ActiveCfg = Release|Any CPU {2FFD7AC6-1A55-4B6E-BF9D-1B85CC5AE193}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8E88AA1F-8D4F-4FA6-9B94-03203BB5F739}.Release|Any CPU.Build.0 = Release|Any CPU {2FFD7AC6-1A55-4B6E-BF9D-1B85CC5AE193}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
...@@ -113,7 +113,7 @@ Global ...@@ -113,7 +113,7 @@ Global
{94C559A6-82AA-4149-9616-E6EC78753766} = {9F378944-D65E-4FA7-AA34-23BF342112F8} {94C559A6-82AA-4149-9616-E6EC78753766} = {9F378944-D65E-4FA7-AA34-23BF342112F8}
{E53A0586-2FB1-4708-91A9-4D6814E02E3C} = {779A24FC-0621-4085-AB80-9BD0BB6AF605} {E53A0586-2FB1-4708-91A9-4D6814E02E3C} = {779A24FC-0621-4085-AB80-9BD0BB6AF605}
{26EA0840-FACE-4F72-B7D0-64CA9443BD9F} = {E53A0586-2FB1-4708-91A9-4D6814E02E3C} {26EA0840-FACE-4F72-B7D0-64CA9443BD9F} = {E53A0586-2FB1-4708-91A9-4D6814E02E3C}
{8E88AA1F-8D4F-4FA6-9B94-03203BB5F739} = {26EA0840-FACE-4F72-B7D0-64CA9443BD9F} {2FFD7AC6-1A55-4B6E-BF9D-1B85CC5AE193} = {26EA0840-FACE-4F72-B7D0-64CA9443BD9F}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {94A499F2-8AA4-43FC-9824-F095E42D54AB} SolutionGuid = {94A499F2-8AA4-43FC-9824-F095E42D54AB}
......
<Project>
<PropertyGroup>
<ServiceUrl></ServiceUrl>
</PropertyGroup>
</Project>
#!/bin/bash
set -e
# Import external functions
chmod +x ./devops/PipeLines/Functions.core.sh
source ./devops/PipeLines/Functions.core.sh
GetSolutionName SolutionName
echo "begin build..."
dotnet build ${SolutionName}
echo "build successful."
\ No newline at end of file
#!/bin/bash
set -e
# Import external functions
chmod +x ./devops/PipeLines/Functions.deploy.sh
source ./devops/PipeLines/Functions.deploy.sh
GetAppName appName
echo ""
echo "Continuous integration for ${appName} starting..."
echo ""
echo "${appName} building..."
GetSolutionName solutionName
dotnet build ${solutionName}
echo ""
echo "Please check the version of each microservice carefully !!!"
GetRegistryHost RegistryHost
for servicePrefix in `ls ./src/Services|xargs -d '/'`
do
GetServiceName ${servicePrefix} serviceName
GetServiceCsProjFile ${servicePrefix} ${serviceName} serviceCsProjFile
CI ${serviceName} ${serviceCsProjFile}
done
echo ""
echo "Continuous integration for ${appName} has been successful."
\ No newline at end of file
#!/bin/bash
set -e
IFS=$'\n\n'
# 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..."
GetNameSpace namespace
kubectl create namespace ${namespace}
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} ${accessToken}
done
echo ""
echo "End creating app settings to the configmap of k8s..."
\ No newline at end of file
#!/bin/bash
set -e
IFS=$'\n\n'
# Import external functions
chmod +x ./devops/PipeLines/Functions.core.sh
source ./devops/PipeLines/Functions.core.sh
GetAppName appName
echo "Starting release for ${appName}, it will dynamicly create k8s environment..."
GetVersion version
GetNameSpace namespace
echo ""
echo "Please check the image version of each microservice carefully !!!"
echo "kubernetes's namespace: ${namespace}"
for servicePrefix in `ls ./src/Services|xargs -d '/'`
do
GetServiceName ${servicePrefix} serviceName
echo "${serviceName}: ${version}"
done
echo ""
GetMajor major
GetReplicas replicas
GetRegistryHost RegistryHost
GetImageUserName registryUserName
ToLower ${Environment} environment
ToLower "${appName}.v${major}" releaseName
helm install /root/AutoDevOpsPipeLinesCharts \
--name=${releaseName} \
--set environment.upper=${Environment} \
--set environment.lower=${environment} \
--set namespace=${namespace} \
--set image.registryhost=${RegistryHost} \
--set image.username=${registryUserName} \
--set image.version=${version} \
--set replicas=${replicas}
echo ""
echo "K8s environment Created Successfully !!!"
\ No newline at end of file
#!/bin/bash
set -e
IFS=$'\n\n'
# 001 Continuous integration image to registry.
bash ./devops/PipeLines/Creation/001_CI.sh
# 002 Create config information to k8s's configmap.
bash ./devops/PipeLines/Creation/002_CreateConfig.sh
# 003 Release major to k8s's cluster.
bash ./devops/PipeLines/Creation/003_ReleaseMajor.sh
# 004 Create gateway route.
bash ./devops/PipeLines/Creation/Gateways/Kong/004_CreateGatewayRoute.sh
\ No newline at end of file
...@@ -2,16 +2,13 @@ ...@@ -2,16 +2,13 @@
set -e set -e
IFS=$'\n\n' IFS=$'\n\n'
declare appName=($(grep -oP '(?<=AppName>)[^<]+' "devops/app.props")) # Import external functions
chmod +x ./devops/PipeLines/Functions.core.sh
source ./devops/PipeLines/Functions.core.sh
echo "Start building the gateway for ${appName} route dynamically..." GetAppName appName
declare namespace=($(grep -oP '(?<=Namespace>)[^<]+' "devops/app.props")) echo "Start dynamically building the gateway route for ${appName}..."
declare namespaceOfK8s=$(echo "${appName}-v${major}" | tr 'A-Z' 'a-z')
declare fdnOfK8s="${namespaceOfK8s}.svc.cluster.local"
declare kongServiceUrl=($(grep -oP '(?<=Namespace>)[^<]+' "devops/app.props"))
declare major=($(grep -oP '(?<=Major>)[^<]+' "devops/version.props"))
declare releaseVersion="v${major}"
# resilience handle # resilience handle
# Maximum time in seconds that you allow the whole operation to take. # Maximum time in seconds that you allow the whole operation to take.
...@@ -58,33 +55,38 @@ function createRoute() ...@@ -58,33 +55,38 @@ function createRoute()
--retry $4 \ --retry $4 \
-H "accept: application/json" \ -H "accept: application/json" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d "{ \"service\": "{\"id\":\"$svcId\"}",\"paths\": "[\"$6\"]",\"methods\": "$defMethods",\"strip_path\":$7,\"hosts\": "[\"$kongRouteDomain\"]"}"; -d "{ \"service\": "{\"id\":\"$svcId\"}",\"paths\": "[\"$6\"]",\"methods\": "$defMethods",\"strip_path\":$7,\"hosts\": "[\"${KongRouteDomain}\"]"}";
fi fi
fi fi
set -e set -e
} }
declare services=$(ls -l src/services | awk 'NR>1') GetMajor major
declare servicePrefix="" GetNameSpace namespace
declare serviceName="" GetKongApiServer KongApiServer
declare serviceNameWithVersion="" GetKongRouteDomain KongRouteDomain
declare serviceFullName=""
declare serviceUrl="" declare fdnOfK8s="${namespace}.svc.cluster.local"
declare serviceRouteUrl="" declare kongServiceBaseUrl="${KongApiServer}/services"
for service in ${services} declare kongRouteBaseUrl="${KongApiServer}/routes"
declare releaseVersion="v${major}"
for servicePrefix in `ls ./src/Services|xargs -d '/'`
do do
servicePrefix=($(echo ${service} | awk '{print $9}')) GetServiceName ${servicePrefix} serviceName
serviceName="${servicePrefix}-api" # replace . to -, compatible with k8s.
serviceNameWithVersion="${serviceName}-${releaseVersion}" Replace ${serviceName} '.' '-' serviceName
serviceFullName="${serviceName}.${fdnOfK8s}" ToLower "${serviceName}-${releaseVersion}" serviceNameWithVersion
serviceUrl="http://${serviceFullName}/api/${servicePrefix}" ToLower "${serviceName}.${fdnOfK8s}" serviceFdn
ToLower ${servicePrefix} prefix
ToLower "http://${serviceFdn}/api/${prefix}" serviceUrl
echo "Begin creating service[${serviceNameWithVersion}]" echo "Begin creating service[${serviceNameWithVersion}]"
createService ${kongServiceUrl} ${maxConnectTime} ${maxTime} ${retryCount} ${serviceNameWithVersion} ${serviceUrl} createService ${kongServiceBaseUrl} ${maxConnectTime} ${maxTime} ${retryCount} ${serviceNameWithVersion} ${serviceUrl}
echo "Begin creating route of service[${serviceNameWithVersion}]" echo "Begin creating route of service[${serviceNameWithVersion}]"
serviceRouteUrl="/api/${releaseVersion}/${servicePrefix}" ToLower "/api/${releaseVersion}/${prefix}" serviceRouteUrl
createRoute ${kongServiceUrl} ${maxConnectTime} ${maxTime} ${retryCount} ${serviceNameWithVersion} ${serviceRouteUrl} true createRoute ${kongRouteBaseUrl} ${maxConnectTime} ${maxTime} ${retryCount} ${serviceNameWithVersion} ${serviceRouteUrl} true
done done
echo "" echo ""
......
#
οű
## k8s
helm delete --purge microservice.autodevopspipeline.v0
kubectl delete namespace microservice-autodevopspipeline-v0
## gateway
delete FROM routes where created_at>'2019-01-10';
delete FROM services where created_at>'2019-01-10';
\ No newline at end of file
#!/bin/bash
set -e
IFS=$'\n\n'
declare appName=($(grep -oP '(?<=AppName>)[^<]+' "devops/app.props"))
echo "Release for ${appName} starting, dynamicly creating k8s environment..."
declare major=($(grep -oP '(?<=Major>)[^<]+' "devops/version.props"))
declare minor=($(grep -oP '(?<=Minor>)[^<]+' "devops/version.props"))
declare patch=($(grep -oP '(?<=Patch>)[^<]+' "devops/version.props"))
declare namespace=($(grep -oP '(?<=Namespace>)[^<]+' "devops/app.props"))
declare version=${major}.${minor}.${patch}
declare namespaceOfK8s=$(echo "${namespace}-v${major}" | tr 'A-Z' 'a-z')
declare releaseName="${appName}-v${major}"
echo ""
echo "Please check the image version of each microservice carefully !!!"
echo "kubernetes's namespace: ${namespaceOfK8s}"
declare services=$(ls -l src/services | awk 'NR>1')
declare servicePrefix=""
for service in ${services}
do
servicePrefix=($(echo ${service} | awk '{print $9}'))
echo "${servicePrefix}: ${version}"
done
echo ""
declare replicas=($(grep -oP '(?<=Replicas>)[^<]+' "devops/app.props"))
helm install /root/AutoDevOpsPipeLinesCharts \
--name=${releaseName} \
--set environment.upper=${Environment} \
--set environment.lower=$(echo ${Environment} | tr 'A-Z' 'a-z') \
--set namespace=${namespaceOfK8s} \
--set image.version=${version} \
--set replicas=${replicas}
echo ""
echo "Dynamicly creating k8s environment Successfully !!!"
\ No newline at end of file
#!/bin/bash
set -e
function ToLower()
{
declare input=$1
declare output=($(echo "${input}" | tr 'A-Z' 'a-z'))
eval $2=${output}
}
function Replace()
{
declare input=$1
declare sourceExpr=$2
declare targetExpr=$3
declare output=${input//${sourceExpr}/${targetExpr}}
eval $4=${output}
}
function DynamicVariableValueOf()
{
declare prefix=$1
declare suffix=$2
eval "output=\$$prefix$suffix"
eval $3=${output}
}
\ No newline at end of file
#!/bin/bash #!/bin/bash
set -e
IFS=$'\n\n'
declare appName=($(grep -oP '(?<=AppName>)[^<]+' "devops/app.props")) set -e
echo "Begin creating ${appName}'s settings to the configmap of k8s..." # Import external functions
chmod +x ./devops/PipeLines/Functions.core.sh
source ./devops/PipeLines/Functions.core.sh
function Create() function CreateConfig()
{ {
declare createUrl="$3/api/v1/namespaces/$2/configmaps?pretty=true" 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]" echo "[environment: $1, namespace: $2]"
function send() function Send()
{ {
set +e set +e
declare deleteUrl="${3}/api/v1/namespaces/${2}/configmaps/$5" declare deleteUrl="${apiServer}/api/v1/namespaces/${ns}/configmaps/$5"
curl -X DELETE $deleteUrl -k \ curl -X DELETE $deleteUrl -k \
--connect-timeout $2 --max-time $3 --retry $4 \ --connect-timeout $2 --max-time $3 --retry $4 \
-H 'Authorization: Bearer '${AccessToken}'' -H 'Authorization: Bearer '${token}''
set -e set -e
...@@ -29,16 +33,16 @@ function Create() ...@@ -29,16 +33,16 @@ function Create()
--connect-timeout $2 --max-time $3 --retry $4 \ --connect-timeout $2 --max-time $3 --retry $4 \
-H 'Content-Type: application/json' \ -H 'Content-Type: application/json' \
-H 'cache-control: no-cache' \ -H 'cache-control: no-cache' \
-H 'Authorization: Bearer '${AccessToken}'' \ -H 'Authorization: Bearer '${token}'' \
-d '{ -d '{
"kind": "ConfigMap", "kind": "ConfigMap",
"apiVersion": "v1", "apiVersion": "v1",
"metadata": { "metadata": {
"name": "'$5'", "name": "'$5'",
"namespace": "'${namespace}'" "namespace": "'${ns}'"
}, },
"data": { "data": {
"'$6'":'"$configInfo"' "'$6'":'"${configInfo}"'
} }
}' }'
} }
...@@ -47,24 +51,9 @@ function Create() ...@@ -47,24 +51,9 @@ function Create()
declare maxConnectTime=20 declare maxConnectTime=20
declare retryCount=5 declare retryCount=5
send "$4/appsettings.json" $maxConnectTime $maxTime $retryCount "$5.appsettings.json" "appsettings.json" ToLower "$5.appsettings.json" configName
send "$4/appsettings.$1.json" $maxConnectTime $maxTime $retryCount "$(echo $5.appsettings.$1.json | tr 'A-Z' 'a-z')" "appsettings.$1.json" ToLower "$5.appsettings.$1.json" configEnvName
}
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} Send "$4/appsettings.json" $maxConnectTime $maxTime $retryCount ${configName} "appsettings.json"
Send "$4/appsettings.$1.json" $maxConnectTime $maxTime $retryCount ${configEnvName} "appsettings.$1.json"
declare services=$(ls -l src/services | awk 'NR>1') }
declare servicePrefix="" \ No newline at end of file
for service in ${services}
do
servicePrefix=($(echo ${service} | awk '{print $9}'))
Create ${Environment} ${namespaceOfK8s} ${k8sApiServer} "./src/${servicePrefix}.API" "${servicePrefix}"
done
echo ""
echo "End creating app settings to the configmap of k8s..."
\ No newline at end of file
#!/bin/bash
set -e
# Import external functions
chmod +x ./devops/PipeLines/Functions.common.sh
source ./devops/PipeLines/Functions.common.sh
# function GetServices()
# {
#
# }
function GetServiceCsProjFile()
{
declare prefix=${1}
declare name=${2}
declare csprojFile="./src/Services/${prefix}/${name}/${name}.csproj"
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}
declare name=($(ls ./src/Services/${prefix}|head -n 1|xargs -d '/' echo))
eval $2="${name}"
}
function GetAppName()
{
declare name=($(grep -oP '(?<=AppName>)[^<]+' "./devops/app.props"))
eval $1="${name}"
}
function GetNameSpace()
{
GetMajor major
declare ns=($(grep -oP '(?<=NameSpace>)[^<]+' "./devops/app.props"))
ToLower "${ns}-v${major}" nsOfK8s
eval $1=${nsOfK8s}
}
function GetSolutionName()
{
declare name=($(grep -oP '(?<=SolutionName>)[^<]+' "./devops/app.props"))
eval $1="${name}"
}
function GetImageUserName()
{
declare name=($(grep -oP '(?<=ImageUserName>)[^<]+' "devops/deploy.props"))
eval $1="${name}"
}
function GetCiCdSettings()
{
declare all=($(grep -oP '(?<=AllPublishable>)[^<]+' "/tmp/cicd.props"))
declare no=($(grep -oP '(?<=NoPublishable>)[^<]+' "/tmp/cicd.props"))
eval $1=${all}
eval $2=${no}
}
function GetMajor()
{
declare m=($(grep -oP '(?<=Major>)[^<]+' "./devops/version.props"))
eval $1=${m}
}
function GetVersion()
{
declare major=($(grep -oP '(?<=Major>)[^<]+' "./devops/version.props"))
declare minor=($(grep -oP '(?<=Minor>)[^<]+' "./devops/version.props"))
declare patch=($(grep -oP '(?<=Patch>)[^<]+' "./devops/version.props"))
eval $1="${major}.${minor}.${patch}"
}
function GetImageRegistrySettings()
{
declare host=($(grep -oP '(?<=ImageRegistryHost>)[^<]+' "devops/deploy.props"))
declare username=($(grep -oP '(?<=ImageUserName>)[^<]+' "devops/deploy.props"))
eval $1=${host}
eval $2=${username}
}
function GetReplicas()
{
declare count=($(grep -oP '(?<=Replicas>)[^<]+' "devops/deploy.props"))
eval $1=${count}
}
function GetAccessToken()
{
ToLower ${Environment} environment
declare token=($(grep -oP "(?<=AccessToken>)[^<]+" "devops/deploy.${environment}.props"))
eval $1="${token}"
}
function GetRegistryHost()
{
ToLower ${Environment} environment
declare host=($(grep -oP "(?<=RegistryHost>)[^<]+" "devops/deploy.${environment}.props"))
eval $1="${host}"
}
function GetK8sApiServer()
{
ToLower ${Environment} environment
declare host=($(grep -oP "(?<=K8sApiServer>)[^<]+" "devops/deploy.${environment}.props"))
eval $1="${host}"
}
function GetKongApiServer()
{
ToLower ${Environment} environment
declare host=($(grep -oP "(?<=KongApiServer>)[^<]+" "devops/deploy.${environment}.props"))
eval $1="${host}"
}
function GetKongRouteDomain()
{
ToLower ${Environment} environment
declare domain=($(grep -oP "(?<=KongRouteDomain>)[^<]+" "devops/deploy.${environment}.props"))
eval $1="${domain}"
}
function IsPublishableOf()
{
declare prefix=$1
declare isP=($(grep -oP "(?<=${prefix}Publishable>)[^<]+" "/tmp/cicd.props"))
eval $2="${isP}"
}
\ No newline at end of file
#!/bin/bash
set -e
# Import external functions
chmod +x ./devops/PipeLines/Functions.core.sh
source ./devops/PipeLines/Functions.core.sh
function CI()
{
declare serviceName=$1
declare publishFile=$2
declare publishOutputDir="/tmp/${serviceName}"
GetVersion version
GetImageUserName registryUserName
# repository name must be lowercase
ToLower "${RegistryHost}/${registryUserName}/${serviceName}:${version}" imagefullname
echo ""
echo "Begin delivering for ${serviceName}..."
echo "Tips: Image full name: ${imagefullname}"
mkdir -p ${publishOutputDir}
dotnet publish ${publishFile} -o ${publishOutputDir} -c release --no-restore
docker build -t ${imagefullname} ${publishOutputDir}
docker push ${imagefullname}
rm -fr ${publishOutputDir}
echo "Delivery for ${serviceName} has been successful."
}
\ No newline at end of file
#!/bin/bash
set -e
function GetServiceName()
{
declare servicePrefix=${1}
declare serviceName=$(ls ./src/services/${servicePrefix}|head -n 1|xargs -d '/' echo)
$2="${serviceName}"
}
function GetAppName()
{
declare appName=($(grep -oP '(?<=AppName>)[^<]+' "devops/app.props"))
$1="${appName}"
}
function GetCiCdSettings()
{
declare allPublishable=($(grep -oP '(?<=AllPublishable>)[^<]+' "/tmp/cicd.props"))
declare noPublishable=($(grep -oP '(?<=NoPublishable>)[^<]+' "/tmp/cicd.props"))
}
function GetMajor()
{
declare major=($(grep -oP '(?<=VersionMajor>)[^<]+' "devops/version.props"))
$1=${major}
}
function GetVersion()
{
declare major=($(grep -oP '(?<=VersionMajor>)[^<]+' "devops/version.props"))
declare minor=($(grep -oP '(?<=VersionMinor>)[^<]+' "devops/version.props"))
declare patch=($(grep -oP '(?<=VersionPatch>)[^<]+' "devops/version.props"))
declare version=${major}.${minor}.${patch}
$1=${version}
}
function GetImageRegistrySettings()
{
declare host=($(grep -oP '(?<=ImageRegistryHost>)[^<]+' "devops/deploy.props"))
declare username=($(grep -oP '(?<=ImageUserName>)[^<]+' "devops/deploy.props"))
$1=${host}
$2=${username}
}
function GetAccessTokenOf()
{
declare token=($(grep -oP "(?<=${Environment}AccessToken>)[^<]+" "devops/deploy.props"))
$1="${token}"
}
\ No newline at end of file
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
set -e set -e
IFS=$'\n\n' IFS=$'\n\n'
# Import external functions
chmod +x ./devops/PipeLines/Functions.common.sh
source ./devops/PipeLines/Functions.common.sh
function AddHeadConfig() function AddHeadConfig()
{ {
# sync config for later retries, not affected by cross-job. # sync config for later retries, not affected by cross-job.
...@@ -17,9 +21,7 @@ function AddConfig() ...@@ -17,9 +21,7 @@ function AddConfig()
declare name=${1} declare name=${1}
declare publishable=${2} declare publishable=${2}
if [ "${publishable}" == "1" ]; then
echo "<${name}Publishable>${publishable}</${name}Publishable>" >> /tmp/cicd.props echo "<${name}Publishable>${publishable}</${name}Publishable>" >> /tmp/cicd.props
fi
} }
function AddTailConfig() function AddTailConfig()
...@@ -30,7 +32,7 @@ function AddTailConfig() ...@@ -30,7 +32,7 @@ function AddTailConfig()
if [ "${AllPublishable}" == "1" ]; if [ "${AllPublishable}" == "1" ];
then then
AddHeadConfig "1","0" AddHeadConfig "1" "0"
AddTailConfig AddTailConfig
echo "All micro-services will be released." echo "All micro-services will be released."
...@@ -57,34 +59,34 @@ else ...@@ -57,34 +59,34 @@ else
fi fi
} }
declare services=$(ls -l src/services | awk 'NR>1')
declare servicePrefix=""
declare isPublishable declare isPublishable
declare publishableCount=0; declare publishableCount=0;
AddHeadConfig "1","0" AddHeadConfig "0" "0"
for service in ${services} for servicePrefix in `ls ./src/Services|xargs -d '/'`
do do
servicePrefix=($(echo ${service} | awk '{print $9}')) # Notes: Hard release[manual control], will not analyz changes.
# Notes: manual control, mandatory release, will not analyzing changes DynamicVariableValueOf "${servicePrefix}" "Publishable" isPublishable
isPublishable=$(eval echo ${servicePrefix}Publishable)
if [ "${isPublishable}" == "1" ]; if [ "${isPublishable}" == "1" ];
then then
AddConfig "${servicePrefix}" "${isPublishable}" AddConfig "${servicePrefix}" "${isPublishable}"
echo "Tips[Hard Release]: ${servicePrefix} will be released." echo "Tips[Hard Release]: ${servicePrefix} will be released."
else else
# Analyzing git changes # Soft Release, begin Analyzing git changes
IsPublishable "src/${servicePrefix}" isPublishable publishableCount IsPublishable "src/${servicePrefix}" isPublishable publishableCount
if [ "${isPublishable}" == "1" ];
then
AddConfig "${servicePrefix}" "${isPublishable}" AddConfig "${servicePrefix}" "${isPublishable}"
echo "Tips[Soft Release]: ${servicePrefix} will be released." echo "Tips[Soft Release]: ${servicePrefix} will be released."
fi fi
fi
done done
AddTailConfig AddTailConfig
declare serviceCount=$(ls -l src/services | grep "^d" | wc -l) declare serviceCount=$(ls -l src/Services | grep "^d" | wc -l)
if [ "${publishableCount}" == "${serviceCount}" ] ; if [ "${publishableCount}" == "${serviceCount}" ] ;
then then
AddHeadConfig "0","1" AddHeadConfig "0" "1"
AddTailConfig AddTailConfig
echo "Tips: No services need to be released." echo "Tips: No services need to be released."
fi fi
......
#!/bin/bash
set -e
IFS=$'\n\n'
declare appName=($(grep -oP '(?<=AppName>)[^<]+' "devops/app.props"))
echo "Begin creating ${appName}'s settings to the configmap of k8s..."
declare noPublishable=($(grep -oP '(?<=NoPublishable>)[^<]+' "/tmp/cicd.props"))
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
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"
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
#!/bin/bash
set -e
IFS=$'\n\n'
# Import external functions
chmod +x ./devops/PipeLines/Functions.config.sh
source ./devops/PipeLines/Functions.config.sh
GetAppName appName
echo ""
echo "Begin synchronizing ${appName}'s settings to the configmap of k8s..."
GetCiCdSettings allPublishable noPublishable
if [ "${noPublishable}" == "1" ] ;
then
echo ""
echo "Tips: No services need to be synced config."
else
GetNameSpace namespace
GetAccessToken accessToken
GetK8sApiServer k8sApiServer
for servicePrefix in `ls ./src/Services|xargs -d '/'`
do
IsPublishableOf ${servicePrefix} isPublishable
GetServiceName ${servicePrefix} serviceName
if [ "${isPublishable}" == "1" ];
then
echo ""
echo "Tips: ${serviceName} begin synchronizing config!!!"
GetServiceDir ${servicePrefix} ${serviceName} serviceDir
CreateConfig ${Environment} ${namespace} ${k8sApiServer} ${serviceDir} ${servicePrefix} ${accessToken}
else
echo ""
echo "Tips: ${serviceName} will not be synced config!!!"
fi
done
fi
echo ""
echo "End synchronizing app settings to the configmap of k8s..."
\ No newline at end of file
<Project>
<PropertyGroup>
<RegistryHost>dockerhub.geekbuying.com:8100</RegistryHost>
<K8sApiServer>https://10.76.134.3:6443</K8sApiServer>
<KongApiServer>http://10.76.134.4:81</KongApiServer>
<KongRouteDomain>s.geekbuying.com</KongRouteDomain>
<AccessToken>eyJhbGciOiJSUzI1NiIsImtpZCI6IiJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJhZG1pbi11c2VyLXRva2VuLXhwamRyIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6ImFkbWluLXVzZXIiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiI4ZjYyNjk3NS05OWRlLTExZTgtOTU5YS0wNjc5ZjViMzhiN2IiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6a3ViZS1zeXN0ZW06YWRtaW4tdXNlciJ9.NE5AHZWWdRb_ml2SfliIfcOcP4_9I-UcTVyEQnQ2F3vAsxYkhUzhBBbB6G3UmW5cD-i_aTraYy5t6joZSVsDATyZBlSWWq1vSzXO6rsEW6xoagTsehAPRfUO-FkmtbJuPPtZUkn7fkUGVfcM_IvIEg6z_F7qGaSyOYbe9lvqzs9pRvfGMo0Vxe1RpvyrB0aHPIx6XHJrGjWsfD8f4rKI0f5oH2N9VOEETlPaMmVCKcf-b55RRdblYVZMyH9plEbdDQj9EgjvGKwtpAoxbxGpoagKu_T88cfyAPoua-2bWSQaZ_Eq5W7gon_F6sCZ8ENQj37YOwo0fRRzaqs2lGVd3g</AccessToken>
</PropertyGroup>
</Project>
<Project> <Project>
<PropertyGroup> <PropertyGroup>
<Replicas>1</Replicas> <Replicas>1</Replicas>
<ImageUserName></ImageUserName> <ImageUserName>devopspipelines</ImageUserName>
<K8sApiServer></K8sApiServer>
<StagingAccessToken>eyJhbGciOiJSUzI1NiIsImtpZCI6IiJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJhZG1pbi11c2VyLXRva2VuLXh3MnpkIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6ImFkbWluLXVzZXIiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiI4Y2IyNTA1ZC1iNGFlLTExZTgtYWNkNS0wMDE2M2UwMDFhMzAiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6a3ViZS1zeXN0ZW06YWRtaW4tdXNlciJ9.XFuVK10f_D3eJ04tDRibl8zZGYe6wrCiSw7NQjnApvyQS7dF1igItH2Fh5HaA12JcslrsBBWRUu0A9ZPVHfq-MW4CNgff8UKAE76Y7rYWfHHjTYumZJJJeUi1QHlNFvWJy3s8yjM5P1RomFCZYysUHv3Z5DVWD4uaX_C78tJxMFQYfFYD0DJah1WBpO0_ymixveffLsB_v5YN9jreW2b2uyIfJTqcCbYVo_vy4jB1HDvAQuvC6k4CKACk8AjT-o1R9QrsSEbggZ_Rss_j2iOeONlG_vDFbzkqFbxg3QKu5ULi4FdL3qOQBjx9Fgi-oXINX8ELlyZs3dNW62Bm6_P3g</StagingAccessToken>
<ProductionAccessToken></ProductionAccessToken>
</PropertyGroup> </PropertyGroup>
</Project> </Project>
<Project> <Project>
<PropertyGroup> <PropertyGroup>
<Replicas>1</Replicas> <RegistryHost>registry.geekbuying.com:8100</RegistryHost>
<ImageUserName></ImageUserName> <K8sApiServer>https://172.24.83.222:6443</K8sApiServer>
<K8sApiServer></K8sApiServer> <KongApiServer>http://127.0.0.1:81</KongApiServer>
<KongRouteDomain>staging-api.geekbuy.cn</KongRouteDomain>
<AccessToken>eyJhbGciOiJSUzI1NiIsImtpZCI6IiJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJhZG1pbi11c2VyLXRva2VuLXh3MnpkIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6ImFkbWluLXVzZXIiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiI4Y2IyNTA1ZC1iNGFlLTExZTgtYWNkNS0wMDE2M2UwMDFhMzAiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6a3ViZS1zeXN0ZW06YWRtaW4tdXNlciJ9.XFuVK10f_D3eJ04tDRibl8zZGYe6wrCiSw7NQjnApvyQS7dF1igItH2Fh5HaA12JcslrsBBWRUu0A9ZPVHfq-MW4CNgff8UKAE76Y7rYWfHHjTYumZJJJeUi1QHlNFvWJy3s8yjM5P1RomFCZYysUHv3Z5DVWD4uaX_C78tJxMFQYfFYD0DJah1WBpO0_ymixveffLsB_v5YN9jreW2b2uyIfJTqcCbYVo_vy4jB1HDvAQuvC6k4CKACk8AjT-o1R9QrsSEbggZ_Rss_j2iOeONlG_vDFbzkqFbxg3QKu5ULi4FdL3qOQBjx9Fgi-oXINX8ELlyZs3dNW62Bm6_P3g</AccessToken>
</PropertyGroup> </PropertyGroup>
</Project> </Project>
<Project> <Project>
<PropertyGroup> <PropertyGroup>
<Major>0</Major> <Major>1</Major>
<Minor>0</Minor> <Minor>0</Minor>
<Patch>1</Patch> <Patch>0</Patch>
</PropertyGroup> </PropertyGroup>
</Project> </Project>
{
"sdk": {
"version": "2.2.100"
}
}
\ No newline at end of file
## 为我们的项目创建chart目录
helm create AutoDevOpsPipeLinesCharts
## 安装
## 渲染模板(调试)
```shell
helm install --debug --dry-run /root/AutoDevOpsPipeLinesCharts \
--name=v1 \
--set environment.upper=Production \
--set environment.lower=production \
--set namespace=microservice-autodevopspipeline-v0 \
--set image.version=0.0.0 \
--set replicas=1
```
## 发布版本
```shell
helm install /root/AutoDevOpsPipeLinesCharts \
--name=geekbuying-light-v2 \
--set environment.upper=Production \
--set environment.lower=production \
--set namespace=geekbuying-light-v3 \
--set image.version=2.0.0
```
## 检视发布
helm get manifest [release name]
## 删除发布
helm delete [release name]
## 其他
helm ls
helm ls --deleted -d
helm del --purge $releaseName
\ No newline at end of file
...@@ -5,24 +5,27 @@ helm create AutoDevOpsPipeLinesCharts ...@@ -5,24 +5,27 @@ helm create AutoDevOpsPipeLinesCharts
## 渲染模板(调试) ## 渲染模板(调试)
```shell ```shell
helm install --debug --dry-run /root/AutoDevOpsPipeLinesCharts \ helm install --debug --dry-run /root/AutoDevOpsPipeLinesCharts \
--set environment.upper=Production \ --set environment.upper=Staging \
--set environment.lower=production \ --set environment.lower=staging \
--set namespace=geekbuying-light-v2 \ --set image.registryhost=registry.geekbuying.com:8100 \
--set image.version=2.0.0 --set image.username=devopspipelines \
--set namespace=microservice-autodevopspipeline-v0 \
--set image.version=0.0.1 \
--set replicas=1
``` ```
## 发布版本 ## 发布版本
```shell ```shell
helm install /root/AutoDevOpsPipeLinesCharts \ helm install /root/AutoDevOpsPipeLinesCharts \
--name=geekbuying-light-v2 \ --set environment.upper=Staging \
--set environment.upper=Production \ --set environment.lower=staging \
--set environment.lower=production \ --set image.registryhost=registry.geekbuying.com:8100 \
--set namespace=geekbuying-light-v3 \ --set image.username=devopspipelines \
--set image.version=2.0.0 --set namespace=microservice-autodevopspipeline-v0 \
--set image.version=0.0.1 \
--set replicas=1
``` ```
## 检视发布 ## 检视发布
helm get manifest [release name] helm get manifest [release name]
......
...@@ -26,17 +26,10 @@ spec: ...@@ -26,17 +26,10 @@ spec:
name: identity.appsettings.{{ .Values.environment.lower }}.json name: identity.appsettings.{{ .Values.environment.lower }}.json
containers: containers:
- name: identity-api - name: identity-api
image: {{ .Values.image.registryhost }}{{ .Values.image.username }}identity.api:{{ .Values.image.version }} image: {{ .Values.image.registryhost }}/{{ .Values.image.username }}/identity.api:{{ .Values.image.version }}
imagePullPolicy: Always imagePullPolicy: Always
ports: ports:
- containerPort: 80 - containerPort: 80
readinessProbe:
httpGet:
path: /healthchecks
port: 80
scheme: HTTP
initialDelaySeconds: 5
periodSeconds: 60
volumeMounts: volumeMounts:
- name: appsetting - name: appsetting
mountPath: "/app/appsettings.json" mountPath: "/app/appsettings.json"
...@@ -76,17 +69,10 @@ spec: ...@@ -76,17 +69,10 @@ spec:
name: basket.appsettings.{{ .Values.environment.lower }}.json name: basket.appsettings.{{ .Values.environment.lower }}.json
containers: containers:
- name: basket-api - name: basket-api
image: {{ .Values.image.registryhost }}{{ .Values.image.username }}basket.api:{{ .Values.image.version }} image: {{ .Values.image.registryhost }}/{{ .Values.image.username }}/basket.api:{{ .Values.image.version }}
imagePullPolicy: Always imagePullPolicy: Always
ports: ports:
- containerPort: 80 - containerPort: 80
readinessProbe:
httpGet:
path: /healthchecks
port: 80
scheme: HTTP
initialDelaySeconds: 5
periodSeconds: 60
volumeMounts: volumeMounts:
- name: appsetting - name: appsetting
mountPath: "/app/appsettings.json" mountPath: "/app/appsettings.json"
...@@ -127,17 +113,10 @@ spec: ...@@ -127,17 +113,10 @@ spec:
name: catalog.appsettings.{{ .Values.environment.lower }}.json name: catalog.appsettings.{{ .Values.environment.lower }}.json
containers: containers:
- name: catalog-api - name: catalog-api
image: {{ .Values.image.registryhost }}{{ .Values.image.username }}catalog.api:{{ .Values.image.version }} image: {{ .Values.image.registryhost }}/{{ .Values.image.username }}/catalog.api:{{ .Values.image.version }}
imagePullPolicy: Always imagePullPolicy: Always
ports: ports:
- containerPort: 80 - containerPort: 80
readinessProbe:
httpGet:
path: /healthchecks
port: 80
scheme: HTTP
initialDelaySeconds: 5
periodSeconds: 60
volumeMounts: volumeMounts:
- name: appsetting - name: appsetting
mountPath: "/app/appsettings.json" mountPath: "/app/appsettings.json"
...@@ -178,17 +157,10 @@ spec: ...@@ -178,17 +157,10 @@ spec:
name: marketing.appsettings.{{ .Values.environment.lower }}.json name: marketing.appsettings.{{ .Values.environment.lower }}.json
containers: containers:
- name: marketing-api - name: marketing-api
image: {{ .Values.image.registryhost }}{{ .Values.image.username }}marketing.api:{{ .Values.image.version }} image: {{ .Values.image.registryhost }}/{{ .Values.image.username }}/marketing.api:{{ .Values.image.version }}
imagePullPolicy: Always imagePullPolicy: Always
ports: ports:
- containerPort: 80 - containerPort: 80
readinessProbe:
httpGet:
path: /healthchecks
port: 80
scheme: HTTP
initialDelaySeconds: 5
periodSeconds: 60
volumeMounts: volumeMounts:
- name: appsetting - name: appsetting
mountPath: "/app/appsettings.json" mountPath: "/app/appsettings.json"
...@@ -229,17 +201,10 @@ spec: ...@@ -229,17 +201,10 @@ spec:
name: ordering.appsettings.{{ .Values.environment.lower }}.json name: ordering.appsettings.{{ .Values.environment.lower }}.json
containers: containers:
- name: ordering-api - name: ordering-api
image: {{ .Values.image.registryhost }}{{ .Values.image.username }}ordering.api:{{ .Values.image.version }} image: {{ .Values.image.registryhost }}/{{ .Values.image.username }}/ordering.api:{{ .Values.image.version }}
imagePullPolicy: Always imagePullPolicy: Always
ports: ports:
- containerPort: 80 - containerPort: 80
readinessProbe:
httpGet:
path: /healthchecks
port: 80
scheme: HTTP
initialDelaySeconds: 5
periodSeconds: 60
volumeMounts: volumeMounts:
- name: appsetting - name: appsetting
mountPath: "/app/appsettings.json" mountPath: "/app/appsettings.json"
...@@ -280,17 +245,10 @@ spec: ...@@ -280,17 +245,10 @@ spec:
name: payment.appsettings.{{ .Values.environment.lower }}.json name: payment.appsettings.{{ .Values.environment.lower }}.json
containers: containers:
- name: payment-api - name: payment-api
image: {{ .Values.image.registryhost }}{{ .Values.image.username }}payment.api:{{ .Values.image.version }} image: {{ .Values.image.registryhost }}/{{ .Values.image.username }}/payment.api:{{ .Values.image.version }}
imagePullPolicy: Always imagePullPolicy: Always
ports: ports:
- containerPort: 80 - containerPort: 80
readinessProbe:
httpGet:
path: /healthchecks
port: 80
scheme: HTTP
initialDelaySeconds: 5
periodSeconds: 60
volumeMounts: volumeMounts:
- name: appsetting - name: appsetting
mountPath: "/app/appsettings.json" mountPath: "/app/appsettings.json"
......
...@@ -2,24 +2,7 @@ apiVersion: v1 ...@@ -2,24 +2,7 @@ apiVersion: v1
kind: Service kind: Service
metadata: metadata:
labels: labels:
app: light app: auto-devops-pipelines
component: common
name: common-api
namespace: {{ .Values.namespace }}
spec:
type: ClusterIP
ports:
- port: 80
selector:
app: light
component: common
type: webapi
---
apiVersion: v1
kind: Service
metadata:
labels:
app: light
component: basket component: basket
name: basket-api name: basket-api
namespace: {{ .Values.namespace }} namespace: {{ .Values.namespace }}
...@@ -28,7 +11,7 @@ spec: ...@@ -28,7 +11,7 @@ spec:
ports: ports:
- port: 80 - port: 80
selector: selector:
app: light app: auto-devops-pipelines
component: basket component: basket
type: webapi type: webapi
...@@ -37,7 +20,7 @@ apiVersion: v1 ...@@ -37,7 +20,7 @@ apiVersion: v1
kind: Service kind: Service
metadata: metadata:
labels: labels:
app: light app: auto-devops-pipelines
component: catalog component: catalog
name: catalog-api name: catalog-api
namespace: {{ .Values.namespace }} namespace: {{ .Values.namespace }}
...@@ -46,7 +29,7 @@ spec: ...@@ -46,7 +29,7 @@ spec:
ports: ports:
- port: 80 - port: 80
selector: selector:
app: light app: auto-devops-pipelines
component: catalog component: catalog
type: webapi type: webapi
...@@ -55,7 +38,7 @@ apiVersion: v1 ...@@ -55,7 +38,7 @@ apiVersion: v1
kind: Service kind: Service
metadata: metadata:
labels: labels:
app: light app: auto-devops-pipelines
component: identity component: identity
name: identity-api name: identity-api
namespace: {{ .Values.namespace }} namespace: {{ .Values.namespace }}
...@@ -64,7 +47,7 @@ spec: ...@@ -64,7 +47,7 @@ spec:
ports: ports:
- port: 80 - port: 80
selector: selector:
app: light app: auto-devops-pipelines
component: identity component: identity
type: webapi type: webapi
...@@ -73,7 +56,7 @@ apiVersion: v1 ...@@ -73,7 +56,7 @@ apiVersion: v1
kind: Service kind: Service
metadata: metadata:
labels: labels:
app: light app: auto-devops-pipelines
component: marketing component: marketing
name: marketing-api name: marketing-api
namespace: {{ .Values.namespace }} namespace: {{ .Values.namespace }}
...@@ -82,7 +65,7 @@ spec: ...@@ -82,7 +65,7 @@ spec:
ports: ports:
- port: 80 - port: 80
selector: selector:
app: light app: auto-devops-pipelines
component: marketing component: marketing
type: webapi type: webapi
...@@ -91,7 +74,7 @@ apiVersion: v1 ...@@ -91,7 +74,7 @@ apiVersion: v1
kind: Service kind: Service
metadata: metadata:
labels: labels:
app: light app: auto-devops-pipelines
component: ordering component: ordering
name: ordering-api name: ordering-api
namespace: {{ .Values.namespace }} namespace: {{ .Values.namespace }}
...@@ -100,7 +83,7 @@ spec: ...@@ -100,7 +83,7 @@ spec:
ports: ports:
- port: 80 - port: 80
selector: selector:
app: light app: auto-devops-pipelines
component: ordering component: ordering
type: webapi type: webapi
...@@ -109,7 +92,7 @@ apiVersion: v1 ...@@ -109,7 +92,7 @@ apiVersion: v1
kind: Service kind: Service
metadata: metadata:
labels: labels:
app: light app: auto-devops-pipelines
component: payment component: payment
name: payment-api name: payment-api
namespace: {{ .Values.namespace }} namespace: {{ .Values.namespace }}
...@@ -118,43 +101,6 @@ spec: ...@@ -118,43 +101,6 @@ spec:
ports: ports:
- port: 80 - port: 80
selector: selector:
app: light app: auto-devops-pipelines
component: payment component: payment
type: webapi type: webapi
\ No newline at end of file
---
apiVersion: v1
kind: Service
metadata:
labels:
app: light
component: searching
name: searching-yu
namespace: {{ .Values.namespace }}
spec:
type: ClusterIP
ports:
- port: 80
selector:
app: light
component: searching
type: webapi
---
apiVersion: v1
kind: Service
metadata:
labels:
app: light
role: aggregation
component: light
name: aggregation-light
namespace: {{ .Values.namespace }}
spec:
type: ClusterIP
ports:
- port: 80
selector:
app: light
role: aggregation
component: light
type: webapi
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework> <TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Microsoft.AspNetCore.Mvc.Core"> <PackageReference Include="Microsoft.AspNetCore.App" />
<HintPath>C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.mvc.core\2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.Mvc.Core.dll</HintPath>
</Reference>
</ItemGroup> </ItemGroup>
</Project> </Project>
...@@ -14,4 +14,10 @@ ...@@ -14,4 +14,10 @@
<ProjectReference Include="..\..\..\BuildingBlocks\Extensions\MvcExtensions\MvcExtensions.csproj" /> <ProjectReference Include="..\..\..\BuildingBlocks\Extensions\MvcExtensions\MvcExtensions.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Update="Dockerfile">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project> </Project>
using System; using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
namespace Basket.API.Controllers namespace Basket.API.Controllers
{ {
[Route("api/[controller]")] [Route("[controller]")]
[ApiController] [ApiController]
public class ValuesController : ControllerBase public class ValuesController : ControllerBase
{ {
......
FROM microsoft/dotnet:2.2.0-aspnetcore-runtime
RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
MAINTAINER geekbuy.cn
WORKDIR /app
COPY . .
EXPOSE 80
ENTRYPOINT ["dotnet", "Basket.API.dll"]
\ No newline at end of file
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework> <TargetFramework>netcoreapp2.2</TargetFramework>
...@@ -14,4 +14,10 @@ ...@@ -14,4 +14,10 @@
<ProjectReference Include="..\..\..\BuildingBlocks\Extensions\MvcExtensions\MvcExtensions.csproj" /> <ProjectReference Include="..\..\..\BuildingBlocks\Extensions\MvcExtensions\MvcExtensions.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Update="Dockerfile">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project> </Project>
using System; using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
namespace Catalog.API.Controllers namespace Catalog.API.Controllers
{ {
[Route("api/[controller]")] [Route("[controller]")]
[ApiController] [ApiController]
public class ValuesController : ControllerBase public class ValuesController : ControllerBase
{ {
......
FROM microsoft/dotnet:2.2.0-aspnetcore-runtime
RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
MAINTAINER geekbuy.cn
WORKDIR /app
COPY . .
EXPOSE 80
ENTRYPOINT ["dotnet", "Catalog.API.dll"]
\ No newline at end of file
using System; using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
namespace Identity.API.Controllers namespace Identity.API.Controllers
{ {
[Route("api/[controller]")] [Route("[controller]")]
[ApiController] [ApiController]
public class ValuesController : ControllerBase public class ValuesController : ControllerBase
{ {
......
FROM microsoft/dotnet:2.2.0-aspnetcore-runtime
RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
MAINTAINER geekbuy.cn
WORKDIR /app
COPY . .
EXPOSE 80
ENTRYPOINT ["dotnet", "Identity.API.dll"]
\ No newline at end of file
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework> <TargetFramework>netcoreapp2.2</TargetFramework>
...@@ -14,4 +14,10 @@ ...@@ -14,4 +14,10 @@
<ProjectReference Include="..\..\..\BuildingBlocks\Extensions\MvcExtensions\MvcExtensions.csproj" /> <ProjectReference Include="..\..\..\BuildingBlocks\Extensions\MvcExtensions\MvcExtensions.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Update="Dockerfile">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project> </Project>
using System; using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
namespace Marketing.API.Controllers namespace Marketing.API.Controllers
{ {
[Route("api/[controller]")] [Route("[controller]")]
[ApiController] [ApiController]
public class ValuesController : ControllerBase public class ValuesController : ControllerBase
{ {
......
FROM microsoft/dotnet:2.2.0-aspnetcore-runtime
RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
MAINTAINER geekbuy.cn
WORKDIR /app
COPY . .
EXPOSE 80
ENTRYPOINT ["dotnet", "Marketing.API.dll"]
\ No newline at end of file
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework> <TargetFramework>netcoreapp2.2</TargetFramework>
...@@ -14,4 +14,10 @@ ...@@ -14,4 +14,10 @@
<ProjectReference Include="..\..\..\BuildingBlocks\Extensions\MvcExtensions\MvcExtensions.csproj" /> <ProjectReference Include="..\..\..\BuildingBlocks\Extensions\MvcExtensions\MvcExtensions.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Update="Dockerfile">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project> </Project>
using System; using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
namespace Ordering.API.Controllers namespace Ordering.API.Controllers
{ {
[Route("api/[controller]")] [Route("[controller]")]
[ApiController] [ApiController]
public class ValuesController : ControllerBase public class ValuesController : ControllerBase
{ {
......
FROM microsoft/dotnet:2.2.0-aspnetcore-runtime
RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
MAINTAINER geekbuy.cn
WORKDIR /app
COPY . .
EXPOSE 80
ENTRYPOINT ["dotnet", "Ordering.API.dll"]
\ No newline at end of file
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework> <TargetFramework>netcoreapp2.2</TargetFramework>
...@@ -14,4 +14,10 @@ ...@@ -14,4 +14,10 @@
<ProjectReference Include="..\..\..\BuildingBlocks\Extensions\MvcExtensions\MvcExtensions.csproj" /> <ProjectReference Include="..\..\..\BuildingBlocks\Extensions\MvcExtensions\MvcExtensions.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Update="Dockerfile">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project> </Project>
using System; using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
namespace Payment.API.Controllers namespace Payment.API.Controllers
{ {
[Route("api/[controller]")] [Route("[controller]")]
[ApiController] [ApiController]
public class ValuesController : ControllerBase public class ValuesController : ControllerBase
{ {
......
FROM microsoft/dotnet:2.2.0-aspnetcore-runtime
RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
MAINTAINER geekbuy.cn
WORKDIR /app
COPY . .
EXPOSE 80
ENTRYPOINT ["dotnet", "Payment.API.dll"]
\ No newline at end of file
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework> <TargetFramework>netcoreapp2.2</TargetFramework>
...@@ -14,4 +14,10 @@ ...@@ -14,4 +14,10 @@
<ProjectReference Include="..\..\..\BuildingBlocks\Extensions\MvcExtensions\MvcExtensions.csproj" /> <ProjectReference Include="..\..\..\BuildingBlocks\Extensions\MvcExtensions\MvcExtensions.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Update="Dockerfile">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project> </Project>
#!/bin/bash
set -e
IFS=$'\n\n'
export Environment='Staging'
# 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..."
GetNameSpace namespace
# global variable
GetAccessToken AccessToken
GetRegistryHost RegistryHost
GetK8sApiServer K8sApiServer
GetKongApiServer KongApiServer
GetKongRouteDomain KongRouteDomain
for servicePrefix in `ls ./src/Services|xargs -d '/'`
do
GetServiceName ${servicePrefix} serviceName
GetServiceDir ${servicePrefix} ${serviceName} serviceDir
CreateConfig ${Environment} ${namespace} ${K8sApiServer} ${serviceDir} ${servicePrefix}
done
echo ""
echo "End creating 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