Files
AuthCenterConsoleApp/build-run-pro.sh

55 lines
1.5 KiB
Bash
Raw Permalink 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.

#!/bin/bash
set -e
# 核心配置(必改 CONFIG_DIR
APP_NAME="authcenter"
APP_VERSION="1.0.0"
IMAGE_NAME="${APP_NAME}:${APP_VERSION}"
CONTAINER_NAME="authcenter-app"
HOST_PORT=999
CONTAINER_PORT=990
CONFIG_DIR="/sdcard/WinBoLLStudio/AuthCenterConsoleApp" # 务必修改!例 /home/zhang/authcenter/config
WORK_DIR="/sdcard/WinBoLLStudio/AuthCenterConsoleApp"
log(){
echo "[$(date +'%Y-%m-%d %H:%M:%S')] $1"
}
log "===== 一键构建启动开始 ====="
# 1. Maven打包
log "1. Maven编译打包"
mvn clean package -Dmaven.test.skip=true
# 2. 删旧容器(强制)
log "2. 清理旧容器"
docker rm -f "${CONTAINER_NAME}" >/dev/null 2>&1 || log "无旧容器"
# 3. 删旧镜像
log "3. 清理旧镜像"
docker rmi -f "${IMAGE_NAME}" >/dev/null 2>&1 || log "无旧镜像"
# 清悬空镜像
docker rmi $(docker images -f dangling=true -q) 2>/dev/null || true
# 4. 构建镜像(变量加引号,必加!)
log "4. 构建镜像 ${IMAGE_NAME}"
docker build -t "${IMAGE_NAME}" .
# 5. 启动容器(挂载+时区+内存限制)
log "5. 启动容器"
docker run -d \
--name "${CONTAINER_NAME}" \
-p "${HOST_PORT}":"${CONTAINER_PORT}" \
-v "${CONFIG_DIR}":"${WORK_DIR}"/config:ro \
-v /etc/localtime:/etc/localtime:ro \
--restart=on-failure:3 \
--memory=512m \
"${IMAGE_NAME}"
# 验证
if docker ps | grep -w "${CONTAINER_NAME}"; then
log "✅ 成功!容器名:${CONTAINER_NAME} 访问http://本机IP:${HOST_PORT}"
else
log "❌ 容器启动失败!"
exit 1
fi