Commit 7d9500eb by 李二毛

Merge branch 'development' into 'release/staging'

测试发布主版本1.0.0

See merge request liermao/microservice-autodevopspipelines!103
parents 12ccc6fe 7d2ad31d
Pipeline #4362 passed with stages
in 1 minute 3 seconds
......@@ -10,6 +10,10 @@ stages:
- is-k8s-ready
- testing
- clean-k8s
# Scaling
- auto-scaling
# Roll back
- roll-back
build_job:
stage: build
......@@ -18,6 +22,7 @@ build_job:
tags:
- build
# Creation
staging_release-major_job:
stage: release-major
script:
......@@ -36,6 +41,7 @@ prod_release-major_job:
tags:
- production
# Updating
staging_analysing-git-changes_job:
stage: analysing-git-changes
script:
......@@ -160,4 +166,42 @@ prod_clean-k8s_job:
only:
- master
tags:
- production
# Scaling
staging_autoscaling_job:
stage: auto-scaling
script:
- bash ./devops/PipeLines/AutoScaling.sh
only:
- scaling/staging
tags:
- staging
prod_auto-scaling_job:
stage: auto-scaling
script:
- bash ./devops/PipeLines/AutoScaling.sh
only:
- scaling/production
tags:
- production
# Roll-back
staging_roll-back_job:
stage: roll-back
script:
- bash ./devops/PipeLines/RollBack.sh
only:
- rollback/staging
tags:
- staging
prod_roll-back_job:
stage: roll-back
script:
- bash ./devops/PipeLines/RollBack.sh
only:
- rollback/production
tags:
- production
\ 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
# global variable
RollEnvironmentOf Environment
GetAppName appName
echo "[${Environment}]Auto scaling for ${appName} starting..."
GetCiCdSettings allPublishable noPublishable
if [ "${noPublishable}" == "1" ] ;
then
echo ""
echo "Tips: No services need to be cded."
else
GetNameSpace namespace
GetReplicas replicas
for servicePrefix in `ls ./src/Services|xargs -d '/'`
do
IsPublishableOf ${servicePrefix} isPublishable
GetServiceName ${servicePrefix} serviceName
if [ "${isPublishable}" == "1" ];
then
echo ""
echo "Tips: ${serviceName} begin scaling, replicas: [${replicas}]!!!"
AutoScaling ${namespace} ${serviceName} ${replicas}
else
echo ""
echo "Tips: ${serviceName} will not be scaled!!!"
fi
done
fi
echo ""
echo "[${Environment}]Auto scaling for ${appName} has been successful."
\ No newline at end of file
......@@ -31,4 +31,13 @@ function FirstCharUpperCase()
declare input=$1
declare output=($(echo ${input} | sed -e "s/\b\(.\)/\u\1/g"))
eval $2=${output}
}
function Substr()
{
declare input=$1
declare start=$2
declare length=$3
declare output=${input:start:length}
eval $4=${output}
}
\ No newline at end of file
......@@ -82,6 +82,31 @@ function GetVersion()
eval $1="${major}.${minor}.${patch}"
}
function GetNumericVersion()
{
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 GetRollBackVersion()
{
GetNumericVersion currentVersion
declare step=($(grep -oP '(?<=RollBackStep>)[^<]+' "devops/deploy.props"))
declare rollbackVersion=`expr $currentVersion - $step`
declare versionStr=""
if [ "$rollbackVersion" -lt "100" ]
then
versionStr="0.${rollbackVersion:0:1}.${rollbackVersion:1:1}"
else
versionStr="${rollbackVersion:0:1}.${rollbackVersion:1:1}.${rollbackVersion:2:1}"
fi
eval $1=${versionStr}
}
function GetImageRegistrySettings()
{
declare host=($(grep -oP '(?<=ImageRegistryHost>)[^<]+' "devops/deploy.props"))
......
......@@ -50,4 +50,17 @@ function CD()
kubectl -n ${namespace} scale deploy ${appNameOfK8s} --replicas=1;
fi
echo "Deployment[${Environment}] for ${appName}:${version} has been successful."
}
function AutoScaling()
{
declare namespace=$1
declare serviceName=$2
declare replicas=$3
Replace ${serviceName} '.' '-' appName
# repository name must be lowercase
ToLower ${appName} appNameOfK8s
kubectl -n ${namespace} scale deploy ${appNameOfK8s} --replicas=${replicas};
}
\ 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
# global variable
RollEnvironmentOf Environment
GetAppName appName
echo "Continuous deployment[${Environment}] for ${appName} starting..."
GetCiCdSettings allPublishable noPublishable
if [ "${noPublishable}" == "1" ] ;
then
echo ""
echo "Tips: No services need to be cded."
else
GetRollBackVersion version
GetNameSpace namespace
GetRegistryHost registryHost
GetImageUserName registryUserName
for servicePrefix in `ls ./src/Services|xargs -d '/'`
do
IsPublishableOf ${servicePrefix} isPublishable
GetServiceName ${servicePrefix} serviceName
if [ "${isPublishable}" == "1" ];
then
echo ""
echo "Tips: ${serviceName} begin deployment to K8S!!!"
CD ${registryHost} ${registryUserName} ${serviceName} ${version} ${namespace}
else
echo ""
echo "Tips: ${serviceName} will not be deploymented to K8S!!!"
fi
done
fi
echo ""
echo "Continuous deployment[${Environment}] for ${appName} has been successful."
<Project>
<PropertyGroup>
<!--key: branch name, value: environment-->
<!--key: branch name(last keyword), value: environment-->
<staging>Staging</staging>
<master>Production</master>
</PropertyGroup>
......
<Project>
<PropertyGroup>
<Replicas>1</Replicas>
<RollBackStep>1</RollBackStep>
<ImageUserName>devopspipelines</ImageUserName>
</PropertyGroup>
</Project>
......@@ -9,7 +9,7 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace Basket.API
{
{
public class Program
{
public static void Main(string[] args)
......
......@@ -10,7 +10,7 @@ using Microsoft.Extensions.Logging;
namespace Catalog.API
{
public class Program
public class Program
{
public static void Main(string[] args)
{
......
......@@ -12,7 +12,7 @@ namespace Identity.API
{
public class Program
{
public static void Main(string[] args)
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
......
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