ai-data/bin/depoly.sh

50 lines
1.2 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#接收外部参数由jenkinsfile执行部署脚本时传递
projectName=$1
imageName=$2
version=$3
profileActive=$4
echo "镜像名: $imageName"
echo "项目名: $projectName"
echo "版本号: $version"
echo "多环境: $profileActive"
# 容器id
containerId=$(docker ps -a | grep -w "${projectName}" | awk '{print $1}')
if [ "$containerId" != "" ] ;
then
#停掉容器
docker stop "$containerId"
#删除容器
docker rm "$containerId"
echo "成功删除容器"
fi
# 镜像id
imageId=$(docker images | grep -w "${projectName}" | awk '{print $3}')
#if [ "$imageId" != "" ] ;
#then
#删除镜像
#docker rmi --force $(docker images | grep -w "${projectName}" | awk '{print $3}')
#echo "成功删除镜像"
#fi
docker login 192.168.3.210:9999
# 镜像下载
docker pull "$imageName"
# cd /data/dev/app
# 启动容器
VERSION="${version}" PROFILE_ACTIVE=${profileActive} docker-compose up -d "${projectName}"
echo "容器启动成功"
# 镜像id
imageId=$(docker images | grep -w "${projectName}" | awk '{print $3}')
#if [ "$imageId" != "" ] ;
#then
#删除镜像
#docker rmi --force $(docker images | grep -w "${projectName}" | awk '{print $3}')
#echo "成功删除镜像"
#fi