68 lines
2.3 KiB
Bash
68 lines
2.3 KiB
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# 唯一安装入口:镜像仓库名与标签策略只在本脚本维护。
|
|
postgres_image="postgres:16-alpine"
|
|
|
|
if [[ ${EUID} -ne 0 ]]; then
|
|
echo "请在克隆仓库根目录执行:sudo bash ./install-docker.sh" >&2
|
|
exit 1
|
|
fi
|
|
|
|
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
cd "$repo_root"
|
|
[[ -f Dockerfile && -f deploy/dobotai-dingtalk/install-docker.sh ]] || {
|
|
echo "安装脚本必须从完整DobotAI源码仓库根目录运行。" >&2
|
|
exit 1
|
|
}
|
|
command -v git >/dev/null || { echo "未找到 git,无法确定当前源码版本。" >&2; exit 1; }
|
|
git -C "$repo_root" rev-parse --is-inside-work-tree >/dev/null || {
|
|
echo "请从 git clone 得到的仓库中执行本脚本。" >&2
|
|
exit 1
|
|
}
|
|
|
|
install_docker_if_missing() {
|
|
if command -v docker >/dev/null && docker compose version >/dev/null 2>&1; then
|
|
return
|
|
fi
|
|
command -v apt-get >/dev/null || {
|
|
echo "本脚本仅自动安装基于 apt 的 Docker;请先安装 Docker Engine 和 Docker Compose v2。" >&2
|
|
exit 1
|
|
}
|
|
export DEBIAN_FRONTEND=noninteractive
|
|
apt-get update
|
|
if apt-cache show docker-compose-v2 >/dev/null 2>&1; then
|
|
apt-get install -y docker.io docker-compose-v2
|
|
elif apt-cache show docker-compose-plugin >/dev/null 2>&1; then
|
|
apt-get install -y docker.io docker-compose-plugin
|
|
else
|
|
echo "当前APT源没有 Docker Compose v2 插件,无法安全继续。" >&2
|
|
exit 1
|
|
fi
|
|
systemctl enable --now docker
|
|
docker compose version >/dev/null
|
|
}
|
|
|
|
install_docker_if_missing
|
|
|
|
commit_sha="$(git -C "$repo_root" rev-parse HEAD)"
|
|
commit_short="$(git -C "$repo_root" rev-parse --short=12 HEAD)"
|
|
build_time="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
|
image="dobotai-dingtalk:local-${commit_short}"
|
|
|
|
echo "[1/3] 构建 DobotAI 镜像:$image"
|
|
docker build \
|
|
--build-arg "GOPROXY=https://goproxy.cn,direct" \
|
|
--build-arg "VERSION=local-${commit_short}" \
|
|
--build-arg "COMMIT_SHA=${commit_sha}" \
|
|
--build-arg "BUILD_TIME=${build_time}" \
|
|
--label "org.opencontainers.image.revision=${commit_sha}" \
|
|
--tag "$image" \
|
|
"$repo_root"
|
|
|
|
echo "[2/3] 准备独立PostgreSQL、目录、配置文件和迁移"
|
|
export DOBOTAI_IMAGE="$image"
|
|
export DOBOTAI_POSTGRES_IMAGE="$postgres_image"
|
|
export DOBOTAI_SOURCE_ROOT="$repo_root"
|
|
exec bash "$repo_root/deploy/dobotai-dingtalk/install-docker.sh"
|