40 lines
1.2 KiB
Bash
40 lines
1.2 KiB
Bash
#!/bin/bash
|
|
|
|
# 设置颜色代码以改善输出可读性
|
|
GREEN='\033[0;32m'
|
|
RED='\033[0;31m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# 获取脚本所在目录的绝对路径
|
|
SCRIPT_DIR=$(dirname "$(realpath "$0")")
|
|
|
|
# 定义函数用于检查命令是否成功执行
|
|
check_command() {
|
|
if [ $? -ne 0 ]; then
|
|
echo -e "${RED}期间发生错误: $1${NC}"
|
|
exit 1
|
|
else
|
|
echo -e "${GREEN}$1 完成.${NC}"
|
|
fi
|
|
}
|
|
|
|
# 打印开始信息
|
|
echo -e "${GREEN}开始部署...${NC}"
|
|
|
|
# Step 1: 停止并移除现有的 docker-compose 服务
|
|
echo -e "${GREEN}停止并移除现有容器...${NC}"
|
|
docker compose -f "${SCRIPT_DIR}/docker_deploy/docker-compose.yml" down
|
|
check_command "docker-compose down"
|
|
|
|
# Step 2: 构建新的 Docker 镜像
|
|
echo -e "${GREEN}构建新的Docker镜像...${NC}"
|
|
docker build --no-cache -f "${SCRIPT_DIR}/Dockerfile" -t data_job "${SCRIPT_DIR}/"
|
|
check_command "docker build"
|
|
|
|
# Step 3: 使用更新后的镜像启动服务
|
|
echo -e "${GREEN}使用更新的映像启动服务...${NC}"
|
|
docker compose -f "${SCRIPT_DIR}/docker_deploy/docker-compose.yml" up -d
|
|
check_command "docker-compose up -d"
|
|
|
|
# 打印完成信息
|
|
echo -e "${GREEN}部署过程已成功完成.${NC}" |