Commit 3bb38827 by 李二毛

Merge branch 'development' into 'staging'

Development

See merge request liermao/microservice-autodevopspipelines!77
parents 732bf13a 8397d9be
Pipeline #4265 failed with stages
in 49 seconds
......@@ -5,6 +5,11 @@ stages:
# Updating
- analysing-git-changes
- synchronizing-config
- ci
- cd
- is-k8s-ready
- testing
- clean-k8s
build_job:
stage: build
......@@ -51,4 +56,54 @@ staging-synchronizing-config_job:
only:
- staging
tags:
- staging
staging-ci_job:
stage: ci
script:
- export Environment='Staging'
- bash ./devops/PipeLines/Updating/003_CI.sh
only:
- staging
tags:
- staging
staging-cd_job:
stage: cd
script:
- export Environment='Staging'
- bash ./devops/PipeLines/Updating/004_CD.sh
only:
- staging
tags:
- staging
staging-is-k8s-ready_job:
stage: is-k8s-ready
script:
- export Environment='Staging'
- bash ./devops/PipeLines/Updating/005_IsK8sReady.sh
only:
- staging
tags:
- staging
staging-testing_job:
stage: testing
script:
- export Environment='Staging'
- bash ./devops/PipeLines/Updating/006_Testing.sh
only:
- staging
tags:
- staging
staging-clean-k8s_job:
stage: clean-k8s
script:
- export Environment='Staging'
- bash ./devops/PipeLines/Updating/007_CleanK8s.sh
only:
- staging
tags:
- staging
\ No newline at end of file
......@@ -8,6 +8,6 @@ source ./devops/PipeLines/Functions.core.sh
GetSolutionName SolutionName
echo "begin build..."
echo "Begin building..."
dotnet build ${SolutionName}
echo "build successful."
\ No newline at end of file
echo "Build completed."
\ No newline at end of file
......@@ -15,12 +15,11 @@ 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
echo ""
echo "Tips: ${servicePrefix} begin integrating to image registry!!!"
GetServiceName ${servicePrefix} serviceName
GetServiceCsProjFile ${servicePrefix} ${serviceName} serviceCsProjFile
CI ${serviceName} ${serviceCsProjFile}
......
......@@ -27,4 +27,25 @@ function CI()
docker push ${imagefullname}
rm -fr ${publishOutputDir}
echo "Delivery for ${serviceName} has been successful."
}
function CD()
{
declare registryHost=$1
declare registryUserName=$2
declare serviceName=$3
declare version=$4
Replace ${serviceName} '.' '-' appName
# repository name must be lowercase
ToLower "${registryHost}/${registryUserName}/${serviceName}:${version}" imagefullname
ToLower ${appName} appNameOfK8s
kubectl -n ${namespace} set image deployments/${appNameOfK8s} "${appNameOfK8s}=${imagefullname}";
# [compatible]Staging environment does not need to change version number.
if [ "${Environment}" == "Staging" ]; then
kubectl -n ${namespace} scale deploy ${appNameOfK8s} --replicas=0;
kubectl -n ${namespace} scale deploy ${appNameOfK8s} --replicas=1;
fi
echo "Deployment[${Environment}] for ${appName}:${version} has been successful."
}
\ No newline at end of file
......@@ -3,11 +3,11 @@
set -e
# Import external functions
chmod +x ./devops/PipeLines/functions.sh
./devops/PipeLines/functions.sh
chmod +x ./devops/PipeLines/Functions.deploy.sh
source ./devops/PipeLines/Functions.deploy.sh
GetAppName appName
echo "Continuous integration for ${appName} starting..."
echo "Continuous integration[${Environment}] for ${appName} starting..."
GetCiCdSettings allPublishable noPublishable
if [ "${noPublishable}" == "1" ] ;
......@@ -15,56 +15,28 @@ then
echo ""
echo "Tips: No services need to be cied."
else
declare solutionName=($(grep -oP '(?<=SolutionName>)[^<]+' "devops/app.props"))
echo ""
echo "${appName} building..."
GetSolutionName solutionName
dotnet build ${solutionName}
echo "Please check the version of each microservice carefully !!!"
declare major=($(grep -oP '(?<=VersionMajor>)[^<]+' "build/version.props"))
declare minor=($(grep -oP '(?<=VersionMinor>)[^<]+' "build/version.props"))
declare patch=($(grep -oP '(?<=VersionPatch>)[^<]+' "build/version.props"))
declare version=${major}.${minor}.${patch}
declare registryUserName=($(grep -oP '(?<=ImageUserName>)[^<]+' "build/deploy.props"))
declare publishOutputDir=./publish
rm -fr ${publishOutputDir}
mkdir -p ${publishOutputDir}
function CI()
{
declare publishable=$1
declare imagename=$2
echo ""
if [ "${publishable}" == "1" ];
then
declare imagefullname=${RegistryHost}/${registryUserName}/${imagename}:${version}
declare publishFile=$3
echo "begin delivery of master branch for ${imagename}..."
mkdir -p ${publishOutputDir}/${imagename}
dotnet publish ${publishFile} -o ../../publish/${imagename} -c release --no-restore
docker build -t ${imagefullname} ${publishOutputDir}/${imagename}
docker push ${imagefullname}
echo "delivery of master branch for ${imagename}:${version} has been successful."
else
echo "Tips: master branch for ${imagename}:${version} will not be cied!!!"
fi
}
declare services=$(ls -l src/services | awk 'NR>1')
declare servicePrefix=""
declare serviceName=""
declare isPublishable="0"
for service in ${services}
GetRegistryHost RegistryHost
for servicePrefix in `ls ./src/Services|xargs -d '/'`
do
servicePrefix=($(echo ${service} | awk '{print $9}'))
isPublishable=($(grep -oP "(?<=${servicePrefix}Publishable>)[^<]+" "/tmp/cicd.props"))
GetServiceName "${servicePrefix}" serviceName
CI ${isPublishable} "${servicePrefix}" "./src/${servicePrefix}/${serviceName}.csproj"
IsPublishableOf ${servicePrefix} isPublishable
GetServiceName ${servicePrefix} serviceName
if [ "${isPublishable}" == "1" ];
then
echo ""
echo "Tips: ${serviceName} begin integrating to image registry!!!"
GetServiceCsProjFile ${servicePrefix} ${serviceName} serviceCsProjFile
CI ${serviceName} ${serviceCsProjFile}
else
echo ""
echo "Tips: ${serviceName} will not be integrated to image registry!!!"
fi
done
fi
echo ""
echo "Continuous integration for ${appName} has been successful."
\ No newline at end of file
echo "Continuous integration[${Environment}] for ${appName} has been successful."
\ No newline at end of file
......@@ -7,7 +7,7 @@ sh ./devops/PipeLines/functions.sh
GetAppName appName
echo "Continuous deployment of ${Environment} branch for ${appName} starting..."
echo "Continuous deployment[${Environment}] for ${appName} starting..."
GetCiCdSettings allPublishable noPublishable
......@@ -16,45 +16,24 @@ then
echo ""
echo "Tips: No services need to be cded."
else
echo "Please check the version of each microservice carefully !!!"
echo ""
GetVersion version
GetNameSpace namespace
GetImageRegistrySettings registryHost registryUserName
function CD()
{
declare publishable=$1
declare appName=$2
declare imageName=$3
echo ""
if [ "${publishable}" == "1" ];
then
kubectl -n ${namespace} set image deployments/${appName} "${appName}=${registryHost}/${registryUserName}/${imageName}:${version}";
if [ "${Environment}" == "Staging" ]; then
kubectl -n ${namespace} scale deploy ${appName} --replicas=0;
kubectl -n ${namespace} scale deploy ${appName} --replicas=1;
fi
echo "deployment of ${Environment} branch for ${appName}:${version} has been successful."
else
echo "Tips: ${Environment} branch for ${appName}:${version} will not be cded!!!"
fi
}
declare services=$(ls -l src/services | awk 'NR>1')
declare servicePrefix=""
declare serviceName=""
declare isPublishable="0"
for service in ${services}
for servicePrefix in `ls ./src/Services|xargs -d '/'`
do
servicePrefix=($(echo ${service} | awk '{print $9}'))
isPublishable=($(grep -oP "(?<=${servicePrefix}Publishable>)[^<]+" "/tmp/cicd.props"))
GetServiceName "${servicePrefix}" serviceName
CD ${apiPublishable} "${serviceName}" "${serviceName}"
IsPublishableOf ${servicePrefix} isPublishable
GetServiceName ${servicePrefix} serviceName
if [ "${isPublishable}" == "1" ];
then
echo ""
echo "Tips: ${serviceName} begin deployment to K8S!!!"
CD ${registryHost} ${registryUserName} ${serviceName} ${version}
else
echo ""
echo "Tips: ${serviceName} will not be deploymented to K8S!!!"
fi
done
fi
echo ""
echo "Continuous deployment of ${Environment} branch for ${appName} has been successful."
echo "Continuous deployment[${Environment}] for ${appName} has been successful."
......@@ -3,8 +3,8 @@
IFS=$'\n\n'
# Import external functions
chmod +x ./devops/PipeLines/functions.sh
sh ./devops/PipeLines/functions.sh
chmod +x ./devops/PipeLines/Functions.core.sh
sh ./devops/PipeLines/Functions.core.sh
#1: ready, 0: not ready.
declare ready=0
......@@ -18,19 +18,19 @@ do
declare allIsReady=1
for row in $(kubectl -n ${namespace} get deployment)
do
echo ""
declare name=$(echo "${row}"|awk '{print $1}')
declare desired=$(echo "${row}"|awk '{print $2}')
declare current=$(echo "${row}"|awk '{print $3}')
declare uptodate=$(echo "${row}"|awk '{print $4}')
declare available=$(echo "${row}"|awk '{print $5}')
echo "deployment: ${name}, desired: ${desired}, current: ${current}, uptodate: ${uptodate}, available: ${available}"
if [ $((${desired})) == $((${current})) -a $((${current})) == $((${uptodate})) -a $((${uptodate})) == $((${available})) ]; then
echo "${name} has been ready.";
else
echo "${name} has been not ready.";
allIsReady=0
fi
echo ""
declare name=$(echo "${row}"|awk '{print $1}')
declare desired=$(echo "${row}"|awk '{print $2}')
declare current=$(echo "${row}"|awk '{print $3}')
declare uptodate=$(echo "${row}"|awk '{print $4}')
declare available=$(echo "${row}"|awk '{print $5}')
echo "[${Environment}]deployment: ${name}, desired: ${desired}, current: ${current}, uptodate: ${uptodate}, available: ${available}"
if [ $((${desired})) == $((${current})) -a $((${current})) == $((${uptodate})) -a $((${uptodate})) == $((${available})) ]; then
echo "[${Environment}]${name} has been ready.";
else
echo "[${Environment}]${name} has been not ready.";
allIsReady=0
fi
done
if [ $((${allIsReady})) == 1 ]; then
......
#!/bin/bash
set -e
echo "[${Environment}]Begin testing..."
declare dir='./test/ServicesTests'
for prefix in `ls ${dir}|xargs -d '/'`
do
dotnet test "${dir}/${prefix}/${prefix}.csproj"
done
echo "[${Environment}]Test completed."
\ No newline at end of file
......@@ -3,11 +3,12 @@
IFS=$'\n\n'
# Import external functions
chmod +x ./devops/PipeLines/functions.sh
sh ./devops/PipeLines/functions.sh
chmod +x ./devops/PipeLines/Functions.core.sh
sh ./devops/PipeLines/Functions.core.sh
GetNameSpace namespace
echo "[${Environment}]Begin cleaning..."
declare replicas=$(kubectl -n ${namespace} get rs)
for row in $replicas
do
......@@ -18,10 +19,8 @@ do
# echo "replica set: ${name}, desired: ${desired}"
if [ $((${desired})) == 0 -a $((${current})) == 0 -a $((${ready})) == 0 ]; then
# echo ${name}
kubectl -n ${namespace} delete rs ${name} --grace-period=0 --force
kubectl -n ${namespace} delete rs ${name} --grace-period=0 --force
fi
done
echo 'clean successful...'
exit 0
\ No newline at end of file
echo '[${Environment}]Clean completed.'
\ No newline at end of file
......@@ -11,7 +11,7 @@ namespace Identity.API
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
Configuration = configuration;
}
public IConfiguration Configuration { get; }
......
#!/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