feat: 调整

This commit is contained in:
caiyuchao
2025-09-28 15:10:24 +08:00
parent 40603ad3a1
commit cd728ef085
3 changed files with 84 additions and 53 deletions

View File

@@ -1,59 +1,84 @@
#!/bin/sh #!/bin/bash
set -e
[ -z "$2"] && branch='main' || branch=$2 # ==== 配置区 ====
MIRROR_URL="https://mirrors.aliyun.com/docker-ce"
COMPOSE_VERSION="2.29.2"
IMAGE_TAR=""
COMPOSE_FILE="../docker/docker-compose.yml"
# 使用说明,用来提示输入参数 # ==== 检查 root 权限 ====
usage() { if [ "$(id -u)" -ne 0 ]; then
echo "Usage: sh start.sh [system|user|auth]" echo "请使用 root 权限运行此脚本"
exit 1 exit 1
fi
# ==== 检查并安装 Docker ====
if ! command -v docker &> /dev/null; then
echo "[INFO] 未检测到 Docker开始安装..."
if [ -f /etc/os-release ]; then
. /etc/os-release
if [[ "$ID" == "ubuntu" || "$ID" == "debian" ]]; then
apt-get update
apt-get install -y apt-transport-https ca-certificates curl software-properties-common
curl -fsSL ${MIRROR_URL}/linux/${ID}/gpg | apt-key add -
add-apt-repository \
"deb [arch=amd64] ${MIRROR_URL}/linux/${ID} \
$(lsb_release -cs) stable"
apt-get update
apt-get install -y docker-ce docker-ce-cli containerd.io
elif [[ "$ID" == "centos" || "$ID" == "rhel" ]]; then
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo ${MIRROR_URL}/linux/centos/docker-ce.repo
yum install -y docker-ce docker-ce-cli containerd.io
else
echo "[ERROR] 当前系统不支持自动安装 Docker请手动安装"
exit 1
fi
fi
systemctl enable docker
systemctl start docker
else
echo "[INFO] 已检测到 Docker"
fi
# ==== 配置 Docker 镜像加速器 ====
echo "[INFO] 配置 Docker 镜像加速器..."
mkdir -p /etc/docker
cat > /etc/docker/daemon.json <<EOF
{
"registry-mirrors": [
"https://registry.docker-cn.com",
"https://docker.mirrors.ustc.edu.cn",
"https://hub-mirror.c.163.com",
"https://mirror.ccs.tencentyun.com",
"https://mirrors.aliyun.com"
]
} }
EOF
systemctl daemon-reload
systemctl restart docker
common(){ # ==== 检查并安装 docker-compose ====
cd .. if ! command -v docker-compose &> /dev/null && ! docker compose version &> /dev/null; then
git checkout $branch echo "[INFO] 未检测到 docker-compose开始安装..."
git pull curl -L "https://github.com/docker/compose/releases/download/${COMPOSE_VERSION}/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
mvn clean package -Dmaven.test.skip=true -P test chmod +x /usr/local/bin/docker-compose
cd docker else
} echo "[INFO] 已检测到 docker-compose"
fi
# 启动程序模块(必须) # ==== 导入镜像 ====
backend(){ if [ -f "$IMAGE_TAR" ]; then
echo "begin copy agt-server " echo "[INFO] 导入镜像 $IMAGE_TAR ..."
cp ../agt-server.jar ./agt/jar/ docker load -i "$IMAGE_TAR"
sudo docker stop agt-server fi
sudo docker rm agt-server
sudo docker rmi deploy_agt-server
sudo docker-compose up -d agt-server
}
frontend(){ # ==== 启动服务 ====
echo "begin copy agt-server " if [ -f "$COMPOSE_FILE" ]; then
mkdir -p ./nginx/html/dist echo "[INFO] 使用 docker-compose 启动服务..."
rm -rf ./nginx/html/dist/* docker-compose -f "$COMPOSE_FILE" up -d
rm -rf ./dist/* echo "[SUCCESS] 应用已部署完成!"
cd dist else
cp ../../dist.zip ./ echo "[WARN] 未找到 $COMPOSE_FILE,跳过服务启动"
unzip ./dist.zip fi
cd ..
cp -rf ./dist/* ./nginx/html/dist/
}
# 根据输入参数,选择执行对应方法,不输入则执行使用说明
case "$1" in
"backend")
backend
;;
"frontend")
frontend
;;
"stop")
stop
;;
"rm")
rm
;;
*)
usage
;;
esac

View File

@@ -0,0 +1,3 @@
# 设置当前项目所有自定义的配置
agt:
domain: http://192.168.9.50

View File

@@ -9,6 +9,7 @@ services:
ports: ports:
- "3306:3306" - "3306:3306"
volumes: volumes:
- ./mysql/db:/docker-entrypoint-initdb.d
- ./mysql/conf:/etc/mysql/conf.d - ./mysql/conf:/etc/mysql/conf.d
- ./mysql/logs:/logs - ./mysql/logs:/logs
- ./mysql/data:/var/lib/mysql - ./mysql/data:/var/lib/mysql
@@ -64,6 +65,8 @@ services:
- agt-mysql - agt-mysql
volumes: volumes:
- /usr/local/licGen/log/:/usr/local/licGen/log/ - /usr/local/licGen/log/:/usr/local/licGen/log/
- ./agt/config/application-test.yaml:/app/config/application-test.yaml
command: ["--spring.config.location=/app/config/application-test.yaml"]
links: links:
- agt-redis - agt-redis
- agt-mysql - agt-mysql