docs: 初始化 Docs 仓库

This commit is contained in:
2026-01-29 01:58:15 +00:00
commit 88ad71041b
37 changed files with 25416 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
#!/usr/bin/env bash
# 用法:在 Linux 终端执行本脚本,后台启动 AdminApi 的 dotnet watch开发用不需要 docker build
# 前置:已安装并运行 Docker。
set -euo pipefail
trap 'echo "发生错误:${BASH_COMMAND}" >&2' ERR
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
repo_root="$(cd "${script_dir}/.." && pwd)"
container_name="${CONTAINER_NAME:-takeout.api.admin}"
docker_network="${DOCKER_NETWORK:-web_apps}"
host_port="${HOST_PORT:-7801}"
container_port="${CONTAINER_PORT:-7801}"
sdk_image="${SDK_IMAGE:-mcr.microsoft.com/dotnet/sdk:10.0}"
nuget_volume="${NUGET_VOLUME:-takeout-nuget}"
project_path="${PROJECT_PATH:-src/Api/TakeoutSaaS.AdminApi/TakeoutSaaS.AdminApi.csproj}"
environment="${ASPNETCORE_ENVIRONMENT:-Development}"
echo "工作目录:${repo_root}"
echo "使用 SDK 镜像:${sdk_image}"
echo "容器:${container_name} 端口:${host_port}:${container_port} 网络:${docker_network}"
# Ensure network exists (so it can talk to other services like postgres/redis on the same network).
if [ -n "${docker_network}" ]; then
if ! docker network inspect "${docker_network}" >/dev/null 2>&1; then
echo "Docker network 不存在,正在创建:${docker_network}"
docker network create "${docker_network}" >/dev/null
fi
fi
# Persist NuGet cache across container restarts to speed up restore/build.
if ! docker volume inspect "${nuget_volume}" >/dev/null 2>&1; then
echo "NuGet volume 不存在,正在创建:${nuget_volume}"
docker volume create "${nuget_volume}" >/dev/null
fi
# Replace existing container (if any).
if docker ps -a --format '{{.Names}}' | grep -qx "${container_name}"; then
echo "发现旧容器,正在移除:${container_name}"
docker rm -f "${container_name}" >/dev/null
fi
run_args=()
if [ -n "${docker_network}" ]; then
run_args+=(--network "${docker_network}")
fi
echo "启动 dotnet watch后台运行..."
docker run -d --name "${container_name}" \
"${run_args[@]}" \
-p "${host_port}:${container_port}" \
-v "${repo_root}":/src \
-w /src \
-v "${nuget_volume}":/root/.nuget/packages \
-e ASPNETCORE_ENVIRONMENT="${environment}" \
-e ASPNETCORE_URLS="http://+:${container_port}" \
-e DOTNET_USE_POLLING_FILE_WATCHER=1 \
"${sdk_image}" \
dotnet watch --project "${project_path}" run
echo "已启动。查看日志docker logs -f ${container_name}"
echo "Swaggerhttp://localhost:${host_port}/swagger"