feat(deploy): load credentials from nexus-1panel.secrets.sh
Keep secrets out of tracked scripts; support git add -f secrets file, git remote token parsing, and port/firewall checks for one-click install. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
# 1Panel + Docker 一键部署
|
||||
|
||||
## 一条命令安装(推荐)
|
||||
|
||||
**先确保** `deploy/nexus-1panel.secrets.sh` 存在(本机已从 `SECRETS.md` 配好)。
|
||||
|
||||
### 新机(带令牌 clone,无需 export)
|
||||
|
||||
```bash
|
||||
git clone "http://admin:你的Gitea令牌@66.154.115.8:3000/admin/Nexus.git" /opt/nexus
|
||||
cd /opt/nexus
|
||||
# 若 secrets.sh 已随私人仓库 push(见下):
|
||||
bash deploy/nexus-1panel.sh install --skip-clone
|
||||
```
|
||||
|
||||
### 私人仓库强制带上 secrets(仅你一人用时)
|
||||
|
||||
在开发机:
|
||||
|
||||
```bash
|
||||
git add -f deploy/nexus-1panel.secrets.sh
|
||||
git push origin main
|
||||
```
|
||||
|
||||
之后任意服务器 `git clone` / `pull` 即可直接:
|
||||
|
||||
```bash
|
||||
cd /opt/nexus && bash deploy/nexus-1panel.sh install --skip-clone
|
||||
```
|
||||
|
||||
### 4 核 16G
|
||||
|
||||
```bash
|
||||
bash deploy/nexus-1panel.sh install --profile 4c16g --skip-clone
|
||||
```
|
||||
|
||||
## 升级
|
||||
|
||||
```bash
|
||||
bash deploy/nexus-1panel.sh upgrade
|
||||
bash deploy/nexus-1panel.sh check
|
||||
bash deploy/nexus-1panel.sh ports
|
||||
```
|
||||
|
||||
## 文件说明
|
||||
|
||||
| 文件 | 说明 |
|
||||
|------|------|
|
||||
| `nexus-1panel.sh` | 主脚本(可提交 Git) |
|
||||
| `nexus-1panel.secrets.sh` | 令牌 + NEXUS 密钥(gitignore,可 `git add -f`) |
|
||||
| `docker/profiles/*.env` | 1c4g / 2c8g / 4c16g 资源档位 |
|
||||
@@ -1,9 +1,13 @@
|
||||
# 复制为 deploy/nexus-1panel.secrets.sh(已在 .gitignore,勿提交)
|
||||
# 或在服务器执行: bash deploy/nexus-1panel.sh init-token '你的Gitea令牌'
|
||||
# 复制为 deploy/nexus-1panel.secrets.sh(值见本地 SECRETS.md)
|
||||
# 私人仓库单人使用: git add -f deploy/nexus-1panel.secrets.sh && git push
|
||||
|
||||
NEXUS_GITEA_TOKEN=在此填入Gitea_Access_Token
|
||||
NEXUS_GITEA_TOKEN='你的Gitea_Access_Token'
|
||||
|
||||
# 可选覆盖
|
||||
# NEXUS_DOMAIN=api.synaglobal.vip
|
||||
# NEXUS_ROOT=/opt/nexus
|
||||
# NEXUS_PROFILE=2c8g
|
||||
NEXUS_SECRET_KEY='生产NEXUS_SECRET_KEY不可改'
|
||||
NEXUS_API_KEY='生产NEXUS_API_KEY不可改'
|
||||
NEXUS_ENCRYPTION_KEY=''
|
||||
|
||||
NEXUS_DOMAIN='api.synaglobal.vip'
|
||||
NEXUS_ROOT='/opt/nexus'
|
||||
NEXUS_PROFILE='2c8g'
|
||||
NEXUS_FROM_ENV='/www/wwwroot/api.synaglobal.vip/.env'
|
||||
|
||||
+59
-30
@@ -1,24 +1,26 @@
|
||||
#!/usr/bin/env bash
|
||||
# Nexus 6.0 — 1Panel + Docker 一键安装 / 升级 / 检查
|
||||
# Nexus 6.0 — 1Panel + Docker 一键安装 / 升级(参数已全部内置,无需 export)
|
||||
#
|
||||
# 服务器上直接跑(参数已内置,令牌见 /root/.nexus-deploy.env):
|
||||
# curl -fsSL http://66.154.115.8:3000/admin/Nexus/raw/branch/main/deploy/nexus-1panel.sh | bash -s install
|
||||
# cd /opt/nexus && bash deploy/nexus-1panel.sh install
|
||||
# 新机 1Panel 终端一条命令:
|
||||
# curl -fsSL "http://66.154.115.8:3000/admin/Nexus/raw/branch/main/deploy/nexus-1panel.sh" | bash -s install
|
||||
#
|
||||
# 已 clone 到 /opt/nexus:
|
||||
# cd /opt/nexus && bash deploy/nexus-1panel.sh install --skip-clone
|
||||
#
|
||||
# 其他:
|
||||
# bash deploy/nexus-1panel.sh install --profile 4c16g
|
||||
# bash deploy/nexus-1panel.sh install --cpus 2 --mem-gb 8
|
||||
# bash deploy/nexus-1panel.sh upgrade
|
||||
# bash deploy/nexus-1panel.sh check
|
||||
# bash deploy/nexus-1panel.sh ports
|
||||
#
|
||||
# 首次无令牌时:
|
||||
# bash deploy/nexus-1panel.sh init-token '你的Gitea令牌'
|
||||
#
|
||||
# 从宝塔迁密钥:
|
||||
# bash deploy/nexus-1panel.sh install --from-env /www/wwwroot/api.synaglobal.vip/.env
|
||||
# 凭据: deploy/nexus-1panel.secrets.sh(与 SECRETS.md 一致,gitignore)
|
||||
# 私人仓库可: git add -f deploy/nexus-1panel.secrets.sh && git push
|
||||
# 或 clone 时 URL 带令牌,脚本会从 git remote 自动解析
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════════
|
||||
# 内置默认(除 Gitea 令牌外均已填好;令牌勿提交 Git)
|
||||
# 内置路径/域名(无敏感信息,可提交 Git)
|
||||
# ═══════════════════════════════════════════════════════════════════
|
||||
NEXUS_ROOT="${NEXUS_ROOT:-/opt/nexus}"
|
||||
NEXUS_GITEA_HOST="${NEXUS_GITEA_HOST:-66.154.115.8:3000}"
|
||||
@@ -28,6 +30,7 @@ NEXUS_PROFILE="${NEXUS_PROFILE:-2c8g}"
|
||||
NEXUS_FROM_ENV="${NEXUS_FROM_ENV:-/www/wwwroot/api.synaglobal.vip/.env}"
|
||||
NEXUS_BACKUP_DIR="${NEXUS_BACKUP_DIR:-/var/backups/nexus}"
|
||||
NEXUS_DEPLOY_ENV="${NEXUS_DEPLOY_ENV:-/root/.nexus-deploy.env}"
|
||||
NEXUS_PUBLISH_PORT="${NEXUS_PUBLISH_PORT:-8600}"
|
||||
GIT_BRANCH="${NEXUS_GIT_BRANCH:-main}"
|
||||
|
||||
COMPOSE_FILE="docker/docker-compose.prod.yml"
|
||||
@@ -63,7 +66,7 @@ Nexus 1Panel 一键脚本
|
||||
bash deploy/nexus-1panel.sh upgrade [选项] 拉代码+备份+重建
|
||||
bash deploy/nexus-1panel.sh check 检查远程是否有更新
|
||||
bash deploy/nexus-1panel.sh ports 检查 Gitea/8600/80/443 与防火墙
|
||||
bash deploy/nexus-1panel.sh init-token <令牌> 写入 /root/.nexus-deploy.env
|
||||
bash deploy/nexus-1panel.sh init-token <令牌> 覆盖内置 Gitea 令牌(一般不需要)
|
||||
|
||||
资源档位(三选一):
|
||||
--profile 2c8g|4c16g|1c4g 预设(默认 2c8g = 2核8G)
|
||||
@@ -78,12 +81,45 @@ Nexus 1Panel 一键脚本
|
||||
升级选项:
|
||||
--no-backup --prune --dry-run
|
||||
|
||||
令牌: /root/.nexus-deploy.env 或 deploy/nexus-1panel.secrets.sh(gitignore)
|
||||
凭据: deploy/nexus-1panel.secrets.sh(推荐)或 /root/.nexus-deploy.env
|
||||
EOF
|
||||
exit 0
|
||||
}
|
||||
|
||||
script_dir() {
|
||||
dirname "$(readlink -f "${BASH_SOURCE[0]}")"
|
||||
}
|
||||
|
||||
secrets_file_path() {
|
||||
echo "$(script_dir)/nexus-1panel.secrets.sh"
|
||||
}
|
||||
|
||||
load_token_from_git_remote() {
|
||||
local root="${1:-$NEXUS_ROOT}"
|
||||
[[ -n "${NEXUS_GITEA_TOKEN:-}" ]] && return 0
|
||||
[[ -d "${root}/.git" ]] || return 0
|
||||
local url
|
||||
url="$(git -C "$root" remote get-url origin 2>/dev/null || true)"
|
||||
if [[ "$url" =~ http://[^:]+:([^@]+)@ ]]; then
|
||||
NEXUS_GITEA_TOKEN="${BASH_REMATCH[1]}"
|
||||
info "已从 git remote 解析 Gitea 令牌"
|
||||
fi
|
||||
}
|
||||
|
||||
load_secrets() {
|
||||
local secrets_file
|
||||
secrets_file="$(secrets_file_path)"
|
||||
if [[ -f "$secrets_file" ]]; then
|
||||
# shellcheck disable=SC1090
|
||||
set -a
|
||||
source "$secrets_file"
|
||||
set +a
|
||||
info "已加载 $secrets_file"
|
||||
elif [[ ! -f "$NEXUS_DEPLOY_ENV" ]]; then
|
||||
warn "未找到 $(secrets_file_path)"
|
||||
warn " 请复制: cp deploy/nexus-1panel.secrets.sh.example deploy/nexus-1panel.secrets.sh 并填入凭据"
|
||||
warn " 或: bash $0 init-bundle (从本机 SECRETS 生成,见 deploy/README-1panel.md)"
|
||||
fi
|
||||
if [[ -f "$NEXUS_DEPLOY_ENV" ]]; then
|
||||
# shellcheck disable=SC1090
|
||||
set -a
|
||||
@@ -91,15 +127,7 @@ load_secrets() {
|
||||
set +a
|
||||
info "已加载 $NEXUS_DEPLOY_ENV"
|
||||
fi
|
||||
local secrets_file
|
||||
secrets_file="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")/nexus-1panel.secrets.sh"
|
||||
if [[ -f "$secrets_file" ]]; then
|
||||
# shellcheck disable=SC1090
|
||||
set -a
|
||||
source "$secrets_file"
|
||||
set +a
|
||||
info "已加载 $secrets_file"
|
||||
fi
|
||||
load_token_from_git_remote "$NEXUS_ROOT"
|
||||
}
|
||||
|
||||
resolve_profile() {
|
||||
@@ -351,9 +379,7 @@ require_token() {
|
||||
if [[ -n "${NEXUS_GITEA_TOKEN:-}" ]]; then
|
||||
return 0
|
||||
fi
|
||||
error "未配置 Gitea 令牌。"
|
||||
error " bash deploy/nexus-1panel.sh init-token '你的令牌'"
|
||||
error " 或: echo 'NEXUS_GITEA_TOKEN=...' > $NEXUS_DEPLOY_ENV && chmod 600 $NEXUS_DEPLOY_ENV"
|
||||
error "Gitea 令牌为空(内置配置异常)。可执行: bash $0 init-token '<令牌>'"
|
||||
exit 1
|
||||
}
|
||||
|
||||
@@ -442,15 +468,14 @@ write_env_prod() {
|
||||
secret="$(read_env_val "$FROM_ENV" NEXUS_SECRET_KEY)"
|
||||
api="$(read_env_val "$FROM_ENV" NEXUS_API_KEY)"
|
||||
enc="$(read_env_val "$FROM_ENV" NEXUS_ENCRYPTION_KEY)"
|
||||
local old_root old_pass
|
||||
local old_root old_pass dburl
|
||||
old_root="$(read_env_val "$FROM_ENV" MYSQL_ROOT_PASSWORD)"
|
||||
old_pass="$(read_env_val "$FROM_ENV" MYSQL_PASSWORD)"
|
||||
[[ -n "$old_root" ]] && mysql_root="$old_root"
|
||||
[[ -n "$old_pass" ]] && mysql_pass="$old_pass"
|
||||
if [[ -z "$old_pass" ]]; then
|
||||
local dburl
|
||||
dburl="$(read_env_val "$FROM_ENV" NEXUS_DATABASE_URL)"
|
||||
if [[ "$dburl" =~ nexus:([^@]+)@ ]]; then
|
||||
if [[ "$dburl" =~ [Nn]exus:([^@]+)@ ]]; then
|
||||
mysql_pass="${BASH_REMATCH[1]}"
|
||||
fi
|
||||
fi
|
||||
@@ -459,12 +484,16 @@ write_env_prod() {
|
||||
api=""
|
||||
enc=""
|
||||
info "全新安装:完成后访问 https://${NEXUS_DOMAIN}/app/install.html"
|
||||
elif [[ -n "${NEXUS_SECRET_KEY:-}" ]]; then
|
||||
secret="$NEXUS_SECRET_KEY"
|
||||
api="${NEXUS_API_KEY:-}"
|
||||
enc="${NEXUS_ENCRYPTION_KEY:-}"
|
||||
info "使用 secrets 文件中的生产 NEXUS 密钥(Docker MySQL 密码为新生成)"
|
||||
else
|
||||
secret="$(rand_secret)"
|
||||
api="$(rand_secret)"
|
||||
enc=""
|
||||
warn "未指定 --from-env / --fresh,已生成随机密钥(仅适合测试)"
|
||||
warn "生产迁机: bash $0 install --from-env /path/to/.env"
|
||||
warn "已生成随机 NEXUS 密钥(仅适合测试)"
|
||||
fi
|
||||
|
||||
cp "$example" "$env_file"
|
||||
|
||||
@@ -49,6 +49,7 @@ bash deploy/nexus-1panel.sh check
|
||||
|
||||
## 后续(同批)
|
||||
|
||||
- 凭据集中在 `deploy/nexus-1panel.secrets.sh`(gitignore);私人仓库可 `git add -f` 后服务器零 export 安装
|
||||
- `install` / `upgrade` 前检测 Gitea 端口可达性;检测本机 80/443/8600 与 UFW/firewalld 放行提醒
|
||||
- 子命令 `ports` 可单独跑端口检查
|
||||
- 安装成功后检测 `https://域名/health` 外网是否可达
|
||||
|
||||
Reference in New Issue
Block a user