jenkins傳統模式發佈istio應用

1、發佈金絲雀版本git

 

Pre Setpsdocker

cd /var/lib/jenkins/workspace/istio-service-user-canary/istio-service-user

# 舊版本號驗證

if [ "$oldVersion" == "" ];then
echo "舊版本號不能爲空"
return 0
fi
/usr/local/bin/kubectl get virtualservice istio-service-user -o yaml > k8s/vsold.yaml
vsold=$(cat k8s/vsold.yaml)
if [[ $vsold =~ $oldVersion ]];then
echo "舊版本包含"
else
echo "舊版本不包含"
return 0
fi

 

mavenapp

-pl istio-service-user -am clean package

Post Stepsmaven

cd /var/lib/jenkins/workspace/istio-service-user-canary/istio-service-user

# 使用GitTag做爲版本打docker鏡像並上傳至鏡像倉庫
docker build -t istio-service-user:${gittag} .
docker tag istio-service-user:${gittag} swr.ap-southeast-1.myhuaweicloud.com/mk-develop/istio-service-user:${gittag}
docker push swr.ap-southeast-1.myhuaweicloud.com/mk-develop/istio-service-user:${gittag}

# 使用GitTag做爲版本部署實例
sed -i "s/gittag/${gittag}/g" k8s/istio-service-user-deployment.yaml
mv -f k8s/istio-service-user-deployment.yaml k8s/istio-service-user-deployment-${gittag}.yaml
/usr/local/bin/kubectl apply -f k8s/istio-service-user-deployment-${gittag}.yaml

# 目標規則加入新GitTag版本
/usr/local/bin/kubectl get destinationrules istio-service-user -o yaml > k8s/istio-service-user-destinationrule.yaml
destrule=$(cat k8s/istio-service-user-destinationrule.yaml)
if [[ $destrule =~ $gittag ]];then
echo "目標規則包含"
else
sed -i "\$a\  - name: ${gittag}" k8s/istio-service-user-destinationrule.yaml
sed -i "\$a\    labels:" k8s/istio-service-user-destinationrule.yaml
sed -i "\$a\      version: ${gittag}" k8s/istio-service-user-destinationrule.yaml
fi
/usr/local/bin/kubectl apply -f k8s/istio-service-user-destinationrule.yaml

# 服務路由加入新版本金絲雀
sed -i "s/jsqVersion/${gittag}/g" k8s/istio-service-user-virtualservice-jsq.yaml
sed -i "s/currentVersion/${oldVersion}/g" k8s/istio-service-user-virtualservice-jsq.yaml
/usr/local/bin/kubectl apply -f k8s/istio-service-user-virtualservice-jsq.yaml

 

2、切換爲生產版本(上線)ui

Pre Stepsspa

cd /var/lib/jenkins/workspace/istio-service-user-canary/istio-service-user

# 生產版本號驗證
if [ "$proVersion" == "" ];then
echo "生產版本號不能爲空"
return 0
fi
/usr/local/bin/kubectl get virtualservice istio-service-user -o yaml > k8s/vspro.yaml
vspro=$(cat k8s/vspro.yaml)
if [[ $vspro =~ $proVersion ]];then
echo "生產版本存在"
else
echo "生產版本不存在"
return 0
fi

#替換生產版本號
sed -i "s/proVersion/${proVersion}/g" k8s/istio-service-user-virtualservice-pro.yaml
mv -f k8s/istio-service-user-virtualservice-pro.yaml k8s/istio-service-user-virtualservice-${proVersion}.yaml
/usr/local/bin/kubectl apply -f k8s/istio-service-user-virtualservice-${proVersion}.yaml
rm -rf k8s/istio-service-user-virtualservice-${oldVersion}.yaml

if [ "$oldVersion" == "" ];then
echo "未下線舊版本"
else
/usr/local/bin/kubectl delete -f k8s/istio-service-user-deployment-${oldVersion}.yaml
rm -rf k8s/istio-service-user-deployment-${oldVersion}.yaml
fi

 

3、下線已上線金絲雀(回滾)code

 

Pre Stepsblog

cd /var/lib/jenkins/workspace/istio-service-user-canary/istio-service-user

# 金絲雀版本號驗證
if [ "$jsqVersion" == "" ];then
echo "金絲雀版本號不能爲空"
return 0
fi
/usr/local/bin/kubectl get virtualservice istio-service-user -o yaml > k8s/vspro.yaml
vspro=$(cat k8s/vspro.yaml)
if [[ $vspro =~ $proVersion ]];then
echo "金絲雀版本號存在"
else
echo "金絲雀版本號不存在"
return 0
fi

#替換生產版本號
/usr/local/bin/kubectl apply -f k8s/istio-service-user-virtualservice-${rollbackVersion}.yaml

#刪除金絲雀版本發佈
/usr/local/bin/kubectl delete -f k8s/istio-service-user-deployment-${jsqVersion}.yaml 
rm -rf k8s/istio-service-user-deployment-${jsqVersion}.yaml 
相關文章
相關標籤/搜索