forked from ci4s/pipeline-convert
78 lines
2.6 KiB
Bash
78 lines
2.6 KiB
Bash
#!/bin/bash
|
|
|
|
# 检查参数是否为空或'fast'
|
|
if [[ -n "$1" && "$1" != "fast" ]]; then
|
|
echo "Invalid parameter: $1"
|
|
echo "Parameter must be 'fast' or empty"
|
|
exit 1
|
|
fi
|
|
|
|
start=$(date +%s)
|
|
if [ -e "pipeline-convert" ];then
|
|
rm pipeline-convert
|
|
fi
|
|
|
|
echo "################### build start ###################"
|
|
#docker run -v /data/nfs/gocache:/go -v /mnt/e/复杂计算平台资料/code/pipeline-convert/:/code ccr.ccs.tencentyun.com/somunslotus/pipeline-covert:develop-env sh -c "cd /code && go build"
|
|
#根据参数判断
|
|
if [ "$1" == "" ];then
|
|
echo "normal build"
|
|
docker run -v /data/nfs/gocache:/go -v $(pwd):/code -e http_proxy=http://172.20.32.253:3128 -e https_proxy=http://172.20.32.253:3128 ccr.ccs.tencentyun.com/somunslotus/pipeline-covert:develop-env-go1.22.2 sh -c "cd /code && go mod tidy && go build"
|
|
fi
|
|
#docker run -tid --name go-compile -w /code -v /data/nfs/gocache:/go -v /home/somuns/code/:/code -e http_proxy=http://172.20.32.253:3128 -e https_proxy=http://172.20.32.253:3128 ccr.ccs.tencentyun.com/somunslotus/pipeline-covert:develop-env-go1.22.2 /bin/bash
|
|
|
|
if [ "$1" == "fast" ];then
|
|
echo "fast build"
|
|
docker exec -ti go-compile sh -c "rm -rf pipeline-covert && go mod tidy && go build"
|
|
fi
|
|
|
|
if [ "$?" -ne "0" ];then
|
|
echo "build fail"
|
|
exit 1
|
|
fi
|
|
echo "################### build end ###################"
|
|
|
|
tag=$(date +'%Y%m%d%H%M')
|
|
image=172.20.32.187/pipeline-service/pipeline-convert:${tag}
|
|
#image=somunslotus/pipeline-convert:${tag}
|
|
echo "image is ${image}"##################"
|
|
|
|
echo "################### build image start #
|
|
docker build -t ${image} .
|
|
if [ "$?" -ne "0" ];then
|
|
echo "make image fail"
|
|
exit 2
|
|
fi
|
|
echo "################### build image end ###################"
|
|
|
|
|
|
|
|
echo "################### push image start ###################"
|
|
docker push ${image}
|
|
if [ "$?" -ne "0" ];then
|
|
echo "push image fail"
|
|
exit 3
|
|
fi
|
|
echo "################### push image end ###################"
|
|
|
|
sed -i "s#pipeline-image#${image}#g" pipeline-convert.yaml
|
|
if [ "$?" -ne "0" ];then
|
|
echo "replace image fail"
|
|
exit 4
|
|
fi
|
|
|
|
echo "################### deploy start ###################"
|
|
|
|
scp pipeline-convert.yaml root@172.20.32.197:/home/deploy/script/pipeline-convert/pipeline-convert.yaml
|
|
ssh root@172.20.32.197 "unset http_proxy && unset https_proxy && kubectl apply -f /home/deploy/script/pipeline-convert/pipeline-convert.yaml"
|
|
sed -i "s#${image}#pipeline-image#g" pipeline-convert.yaml
|
|
if [ "$?" -ne "0" ];then
|
|
echo "deploy fail"
|
|
exit 5
|
|
fi
|
|
|
|
|
|
echo "################### deploy success ###################"
|
|
end=$(date +%s)
|
|
|
|
echo "build and deploy success, cost time: $((end-start))s" |