Add dynamic AI Workspace run profiles

This commit is contained in:
Codex
2026-06-13 17:30:48 +03:00
parent 385e2732e8
commit 6244b44c6e
21 changed files with 2179 additions and 52 deletions
+3
View File
@@ -62,6 +62,9 @@ AI_WORKSPACE_PG_USER=nodedc_ai_workspace
AI_WORKSPACE_PG_PASS=replace-with-random-synology-secret
AI_WORKSPACE_ASSISTANT_TOKEN=replace-with-random-synology-secret
NODEDC_AI_WORKSPACE_ASSISTANT_URL=http://ai-workspace-assistant:18082
AI_WORKSPACE_OPS_ENTITLEMENT_URL=http://172.22.0.222:18190/api/internal/v1/ai-workspace/entitlements
AI_WORKSPACE_OPS_ENTITLEMENT_TOKEN=replace-with-ops-agent-gateway-internal-token
AI_WORKSPACE_OPS_ENTITLEMENT_REQUIRED=false
AI_WORKSPACE_HUB_TOKEN=replace-with-random-synology-secret
AI_WORKSPACE_HUB_HOST_BIND=0.0.0.0:18081
+10
View File
@@ -47,6 +47,14 @@ AI_WORKSPACE_HUB_FALLBACK_URLS=
Server-side Hub API calls, including executor status checks, use `AI_WORKSPACE_HUB_INTERNAL_URL` and require a token accepted by Hub: `AI_WORKSPACE_HUB_TOKEN`, `NDC_AI_WORKSPACE_HUB_TOKEN`, or the shared `NODEDC_INTERNAL_ACCESS_TOKEN` where that token is intentionally common across platform services.
AI Workspace Assistant also calls product entitlement adapters before every Codex run. Ops uses the Agent Gateway internal endpoint; the token must match `NODEDC_AGENT_GATEWAY_INTERNAL_TOKEN` from the Ops Agent Gateway deployment:
```env
AI_WORKSPACE_OPS_ENTITLEMENT_URL=http://172.22.0.222:18190/api/internal/v1/ai-workspace/entitlements
AI_WORKSPACE_OPS_ENTITLEMENT_TOKEN=<same value as Ops NODEDC_AGENT_GATEWAY_INTERNAL_TOKEN>
AI_WORKSPACE_OPS_ENTITLEMENT_REQUIRED=false
```
## Локальные домены для первичной проверки
На Mac для первичной проверки добавить в `/etc/hosts`:
@@ -137,6 +145,8 @@ GATEWAY_REPO=/Users/dcconstructions/Downloads/mnt/data/NODEDC_TASKMANAGER_CODEXA
Скрипт не запускает Docker сам: на NAS `sudo` интерактивный, поэтому команды применения печатаются в конце.
По умолчанию sync source-копий на SMB/NAS не сохраняет owner/group/perms/times. Для Docker build важен контент, а macOS/Synology metadata может падать на `utimensat Operation timed out`. Если metadata действительно нужно сохранить для отдельного ручного случая, запускать с `RSYNC_PRESERVE_METADATA=1`.
Что синхронизируется:
- Platform compose/Caddy.
+4
View File
@@ -57,6 +57,10 @@ echo "== ai workspace assistant hub target check =="
"${DOCKER_BIN}" exec nodedc-platform-ai-workspace-assistant-1 sh -lc \
'test "$AI_WORKSPACE_HUB_PUBLIC_URL" = "wss://ai-hub.nodedc.ru/api/ai-workspace/hub" && test -z "$AI_WORKSPACE_HUB_FALLBACK_URLS" && echo ai-workspace-prod-hub-target-ok'
echo "== ai workspace assistant Ops entitlement adapter check =="
"${DOCKER_BIN}" exec nodedc-platform-ai-workspace-assistant-1 sh -lc \
'test "$AI_WORKSPACE_OPS_ENTITLEMENT_URL" = "http://172.22.0.222:18190/api/internal/v1/ai-workspace/entitlements" && test -n "$AI_WORKSPACE_OPS_ENTITLEMENT_TOKEN" && echo ai-workspace-ops-entitlement-env-ok'
echo "== clear authentik global brand css =="
DOCKER_BIN="${DOCKER_BIN}" bash "${PLATFORM_DIR}/clear-authentik-brand-css.sh"
+68 -8
View File
@@ -46,6 +46,7 @@ rsync_dir "${NAS_ROOT}/authentik/custom-templates/" "${BACKUP_DIR}/files/authent
rsync_dir "${NAS_ROOT}/platform/authentik/" "${BACKUP_DIR}/files/platform/authentik/"
rsync_dir "${NAS_ROOT}/platform/notification-core/" "${BACKUP_DIR}/files/platform/notification-core/"
rsync_dir "${NAS_ROOT}/platform/ai-workspace-hub/" "${BACKUP_DIR}/files/platform/ai-workspace-hub/"
rsync_dir "${NAS_ROOT}/platform/ai-workspace-assistant/" "${BACKUP_DIR}/files/platform/ai-workspace-assistant/"
rsync_file "${NAS_ROOT}/platform/.env.synology" "${BACKUP_DIR}/files/platform/"
rsync_file "${NAS_ROOT}/platform/.env.synology.example" "${BACKUP_DIR}/files/platform/"
@@ -73,6 +74,7 @@ Contains:
- Platform runtime config: platform/.env.synology, compose, Caddyfile
- Notification Core source/config: platform/notification-core, platform compose/env
- AI Workspace Hub source/config: platform/ai-workspace-hub, platform compose/env
- AI Workspace Assistant source/config: platform/ai-workspace-assistant, platform compose/env
- Tasker runtime config: tasker/plane-app/.env.synology, compose, Synology override
- Ops Agents Gateway runtime config: ops-agents/.env, compose
@@ -101,8 +103,24 @@ sudo "${DOCKER_BIN}" compose \\
--env-file "${ENV_FILE}" \\
-f "${COMPOSE_FILE}" \\
exec -T postgresql-authentik \\
sh -lc 'pg_restore --list /dev/stdin >/dev/null' \\
< "\${BACKUP_DIR}/authentik-postgres.dump"
rm -f /tmp/authentik-postgres.dump
sudo "${DOCKER_BIN}" compose \\
--env-file "${ENV_FILE}" \\
-f "${COMPOSE_FILE}" \\
cp "\${BACKUP_DIR}/authentik-postgres.dump" postgresql-authentik:/tmp/authentik-postgres.dump
sudo "${DOCKER_BIN}" compose \\
--env-file "${ENV_FILE}" \\
-f "${COMPOSE_FILE}" \\
exec -T postgresql-authentik \\
pg_restore --list /tmp/authentik-postgres.dump >/dev/null
sudo "${DOCKER_BIN}" compose \\
--env-file "${ENV_FILE}" \\
-f "${COMPOSE_FILE}" \\
exec -T postgresql-authentik \\
rm -f /tmp/authentik-postgres.dump
if command -v sha256sum >/dev/null 2>&1; then
(cd "\${BACKUP_DIR}" && sha256sum authentik-postgres.dump > SHA256SUMS)
@@ -132,8 +150,24 @@ sudo "${DOCKER_BIN}" compose \\
--env-file "${ENV_FILE}" \\
-f "${COMPOSE_FILE}" \\
exec -T notification-postgres \\
sh -lc 'pg_restore --list /dev/stdin >/dev/null' \\
< "\${BACKUP_DIR}/notification-postgres.dump"
rm -f /tmp/notification-postgres.dump
sudo "${DOCKER_BIN}" compose \\
--env-file "${ENV_FILE}" \\
-f "${COMPOSE_FILE}" \\
cp "\${BACKUP_DIR}/notification-postgres.dump" notification-postgres:/tmp/notification-postgres.dump
sudo "${DOCKER_BIN}" compose \\
--env-file "${ENV_FILE}" \\
-f "${COMPOSE_FILE}" \\
exec -T notification-postgres \\
pg_restore --list /tmp/notification-postgres.dump >/dev/null
sudo "${DOCKER_BIN}" compose \\
--env-file "${ENV_FILE}" \\
-f "${COMPOSE_FILE}" \\
exec -T notification-postgres \\
rm -f /tmp/notification-postgres.dump
echo "notification-db-dump-ok: \${BACKUP_DIR}/notification-postgres.dump"
EOF
@@ -158,8 +192,18 @@ sudo "${DOCKER_BIN}" "\${compose_args[@]}" \\
sudo "${DOCKER_BIN}" "\${compose_args[@]}" \\
exec -T plane-db \\
sh -lc 'pg_restore --list /dev/stdin >/dev/null' \\
< "\${BACKUP_DIR}/tasker-postgres.dump"
rm -f /tmp/tasker-postgres.dump
sudo "${DOCKER_BIN}" "\${compose_args[@]}" \\
cp "\${BACKUP_DIR}/tasker-postgres.dump" plane-db:/tmp/tasker-postgres.dump
sudo "${DOCKER_BIN}" "\${compose_args[@]}" \\
exec -T plane-db \\
pg_restore --list /tmp/tasker-postgres.dump >/dev/null
sudo "${DOCKER_BIN}" "\${compose_args[@]}" \\
exec -T plane-db \\
rm -f /tmp/tasker-postgres.dump
echo "tasker-db-dump-ok: \${BACKUP_DIR}/tasker-postgres.dump"
EOF
@@ -183,8 +227,24 @@ sudo "${DOCKER_BIN}" compose \\
--env-file .env \\
-f docker-compose.synology.yml \\
exec -T postgres \\
sh -lc 'pg_restore --list /dev/stdin >/dev/null' \\
< "\${BACKUP_DIR}/ops-agents-postgres.dump"
rm -f /tmp/ops-agents-postgres.dump
sudo "${DOCKER_BIN}" compose \\
--env-file .env \\
-f docker-compose.synology.yml \\
cp "\${BACKUP_DIR}/ops-agents-postgres.dump" postgres:/tmp/ops-agents-postgres.dump
sudo "${DOCKER_BIN}" compose \\
--env-file .env \\
-f docker-compose.synology.yml \\
exec -T postgres \\
pg_restore --list /tmp/ops-agents-postgres.dump >/dev/null
sudo "${DOCKER_BIN}" compose \\
--env-file .env \\
-f docker-compose.synology.yml \\
exec -T postgres \\
rm -f /tmp/ops-agents-postgres.dump
echo "ops-agents-db-dump-ok: \${BACKUP_DIR}/ops-agents-postgres.dump"
EOF
+190
View File
@@ -0,0 +1,190 @@
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
PLATFORM_REPO="$(cd -- "${SCRIPT_DIR}/../.." && pwd)"
NAS_ROOT="${NAS_ROOT:-/Volumes/docker/nodedc-platform}"
GATEWAY_REPO="${GATEWAY_REPO:-${PLATFORM_REPO}/../../data/NODEDC_TASKMANAGER_CODEXAPI}"
ENGINE_REPO="${ENGINE_REPO:-${PLATFORM_REPO}/../NODEDC_ENGINE_INFRA}"
NAS_PLATFORM_ENV="${NAS_PLATFORM_ENV:-${NAS_ROOT}/platform/.env.synology}"
NAS_GATEWAY_ENV="${NAS_GATEWAY_ENV:-${NAS_ROOT}/ops-agents/.env}"
passed=0
failed=0
warnings=0
section() {
printf '\n== %s ==\n' "$1"
}
pass() {
passed=$((passed + 1))
printf 'PASS %s\n' "$1"
}
fail() {
failed=$((failed + 1))
printf 'FAIL %s\n' "$1" >&2
}
warn() {
warnings=$((warnings + 1))
printf 'WARN %s\n' "$1" >&2
}
read_env() {
local file="$1"
local key="$2"
[[ -f "${file}" ]] || return 0
awk -F= -v key="${key}" '
$0 ~ "^[[:space:]]*#" { next }
$1 == key {
value = substr($0, index($0, "=") + 1)
gsub(/^[[:space:]]+|[[:space:]]+$/, "", value)
gsub(/^"|"$/, "", value)
print value
exit
}
' "${file}"
}
require_path() {
local path="$1"
local label="$2"
if [[ -e "${path}" ]]; then
pass "${label}"
else
fail "${label} (missing: ${path})"
fi
}
require_file_contains() {
local file="$1"
local needle="$2"
local label="$3"
if [[ ! -f "${file}" ]]; then
fail "${label} (missing file: ${file})"
return
fi
if grep -Fq "${needle}" "${file}"; then
pass "${label}"
else
fail "${label} (missing: ${needle})"
fi
}
require_env_value() {
local file="$1"
local key="$2"
local expected="$3"
local label="$4"
local actual
actual="$(read_env "${file}" "${key}" || true)"
if [[ "${actual}" == "${expected}" ]]; then
pass "${label}"
else
fail "${label} (expected ${key}=${expected}, got ${actual:-<missing>})"
fi
}
require_env_nonempty() {
local file="$1"
local key="$2"
local label="$3"
local actual
actual="$(read_env "${file}" "${key}" || true)"
if [[ -n "${actual}" && "${actual}" != replace-with-* && "${actual}" != change-me-* ]]; then
pass "${label}"
else
fail "${label} (${key} missing or placeholder)"
fi
}
section "Local prerequisites"
require_path "${NAS_ROOT}" "NAS mount exists"
require_path "${GATEWAY_REPO}" "Ops Gateway repo exists"
require_path "${ENGINE_REPO}" "Engine repo exists"
require_path "${PLATFORM_REPO}/infra/scripts/check-ai-workspace-release-gates.sh" "Predeploy gate runner exists"
require_path "${PLATFORM_REPO}/infra/scripts/check-ai-workspace-config-contract.sh" "Config contract checker exists"
require_path "${PLATFORM_REPO}/infra/synology/backup-current.sh" "Synology backup script exists"
require_path "${PLATFORM_REPO}/infra/synology/apply-current-runtime.sh" "Synology apply script exists"
require_path "${PLATFORM_REPO}/infra/synology/verify-current-runtime.sh" "Synology verify script exists"
section "Source and migration audit"
require_path "${PLATFORM_REPO}/services/ai-workspace-assistant/src/server.mjs" "AI Workspace Assistant source present"
require_path "${PLATFORM_REPO}/services/ai-workspace-assistant/src/templates/install-windows.ps1" "Worker installer template present"
require_path "${GATEWAY_REPO}/migrations/004_run_grants.sql" "Ops Gateway token-scoped run grants migration present"
require_file_contains "${GATEWAY_REPO}/docker-entrypoint.sh" "npm run migrate:dist" "Ops Gateway image applies migrations on startup"
require_file_contains "${PLATFORM_REPO}/infra/synology/backup-current.sh" "ai-workspace-assistant" "Backup includes AI Workspace Assistant source"
require_file_contains "${PLATFORM_REPO}/infra/synology/deploy-current.sh" "RSYNC_METADATA_ARGS" "Deploy sync avoids fragile NAS metadata by default"
require_file_contains "${PLATFORM_REPO}/infra/synology/apply-current-runtime.sh" "ai-workspace-ops-entitlement-env-ok" "Apply verifies Ops entitlement env"
require_file_contains "${PLATFORM_REPO}/infra/synology/verify-current-runtime.sh" "ai-workspace-ops-entitlement-env-ok" "Verify checks Ops entitlement env"
section "NAS env readiness"
if [[ -f "${NAS_PLATFORM_ENV}" ]]; then
pass "NAS Platform env exists"
require_env_value "${NAS_PLATFORM_ENV}" "AI_WORKSPACE_HUB_PUBLIC_URL" "wss://ai-hub.nodedc.ru/api/ai-workspace/hub" "NAS Platform worker-facing Hub URL"
require_env_value "${NAS_PLATFORM_ENV}" "AI_WORKSPACE_HUB_INTERNAL_URL" "https://ai-hub.nodedc.ru" "NAS Platform internal Hub URL"
require_env_value "${NAS_PLATFORM_ENV}" "AI_WORKSPACE_HUB_FALLBACK_URLS" "" "NAS Platform Hub fallback URLs disabled"
require_env_value "${NAS_PLATFORM_ENV}" "AI_WORKSPACE_OPS_ENTITLEMENT_URL" "http://172.22.0.222:18190/api/internal/v1/ai-workspace/entitlements" "NAS Platform Ops entitlement URL"
require_env_nonempty "${NAS_PLATFORM_ENV}" "AI_WORKSPACE_OPS_ENTITLEMENT_TOKEN" "NAS Platform Ops entitlement token configured"
require_env_nonempty "${NAS_PLATFORM_ENV}" "AI_WORKSPACE_ASSISTANT_TOKEN" "NAS Platform Assistant token configured"
require_env_nonempty "${NAS_PLATFORM_ENV}" "AI_WORKSPACE_HUB_TOKEN" "NAS Platform Hub token configured"
else
fail "NAS Platform env missing: ${NAS_PLATFORM_ENV}"
fi
if [[ -f "${NAS_GATEWAY_ENV}" ]]; then
pass "NAS Ops Gateway env exists"
require_env_value "${NAS_GATEWAY_ENV}" "NODEDC_AGENT_GATEWAY_PUBLIC_URL" "https://ops-agents.nodedc.ru" "NAS Gateway worker-facing MCP URL"
require_env_value "${NAS_GATEWAY_ENV}" "NODEDC_TASKER_INTERNAL_URL" "http://172.22.0.222:18090" "NAS Gateway downstream Tasker URL"
require_env_value "${NAS_GATEWAY_ENV}" "NODEDC_AI_WORKSPACE_RUN_TOKEN_TTL_SECONDS" "43200" "NAS Gateway AI Workspace run token TTL"
require_env_nonempty "${NAS_GATEWAY_ENV}" "NODEDC_AGENT_GATEWAY_INTERNAL_TOKEN" "NAS Gateway internal token configured"
require_env_nonempty "${NAS_GATEWAY_ENV}" "NODEDC_INTERNAL_ACCESS_TOKEN" "NAS Gateway Tasker internal token configured"
require_env_nonempty "${NAS_GATEWAY_ENV}" "POSTGRES_PASSWORD" "NAS Gateway Postgres password configured"
else
fail "NAS Ops Gateway env missing: ${NAS_GATEWAY_ENV}"
fi
section "Controlled apply order"
cat <<EOF
1. Run local predeploy gate:
cd ${PLATFORM_REPO}
infra/scripts/check-ai-workspace-release-gates.sh
2. Create file backup from mounted NAS share:
cd ${PLATFORM_REPO}
NAS_ROOT=${NAS_ROOT} infra/synology/backup-current.sh
3. On Synology, run DB dumps from the backup folder:
bash /volume1/docker/nodedc-platform/backups/<backup-id>/run-authentik-db-dump-on-synology.sh
bash /volume1/docker/nodedc-platform/backups/<backup-id>/run-notification-db-dump-on-synology.sh
bash /volume1/docker/nodedc-platform/backups/<backup-id>/run-ops-agents-db-dump-on-synology.sh
# Tasker DB dump only if Tasker backend/schema changes are included:
bash /volume1/docker/nodedc-platform/backups/<backup-id>/run-tasker-db-dump-on-synology.sh
4. Sync source to NAS mount:
cd ${PLATFORM_REPO}
NAS_ROOT=${NAS_ROOT} GATEWAY_REPO=${GATEWAY_REPO} infra/synology/deploy-current.sh
5. Apply Ops Gateway first on Synology:
cd /volume1/docker/nodedc-platform/ops-agents
sudo /usr/local/bin/docker compose --env-file .env -f docker-compose.synology.yml up -d --build --force-recreate
curl -fsS http://172.22.0.222:18190/readyz
6. Apply Platform AI Workspace services on Synology:
cd /volume1/docker/nodedc-platform/platform
sudo bash apply-current-runtime.sh
7. Verify runtime:
cd /volume1/docker/nodedc-platform/platform
sudo bash verify-current-runtime.sh
EOF
section "Summary"
printf 'passed=%s failed=%s warnings=%s\n' "${passed}" "${failed}" "${warnings}"
if [[ "${failed}" -ne 0 ]]; then
exit 1
fi
+18 -13
View File
@@ -11,6 +11,11 @@ TASKER_CHANGED_BASE="${TASKER_CHANGED_BASE:-}"
GATEWAY_REPO="${GATEWAY_REPO:-}"
SYNC_AUTHENTIK_TEMPLATES="${SYNC_AUTHENTIK_TEMPLATES:-0}"
RSYNC_METADATA_ARGS=()
if [[ "${RSYNC_PRESERVE_METADATA:-0}" != "1" ]]; then
RSYNC_METADATA_ARGS=(--no-times --no-perms --no-owner --no-group)
fi
if [[ ! -d "${NAS_ROOT}" ]]; then
echo "NAS_ROOT not found: ${NAS_ROOT}" >&2
echo "Set NAS_ROOT=/path/to/nodedc-platform when the Synology share is mounted elsewhere." >&2
@@ -19,15 +24,15 @@ fi
mkdir -p "${NAS_ROOT}/platform"
rsync -av \
rsync -av "${RSYNC_METADATA_ARGS[@]}" \
"${PLATFORM_REPO}/infra/synology/docker-compose.platform-http.yml" \
"${NAS_ROOT}/platform/docker-compose.platform-http.yml"
rsync -av \
rsync -av "${RSYNC_METADATA_ARGS[@]}" \
"${PLATFORM_REPO}/infra/synology/Caddyfile.http" \
"${NAS_ROOT}/platform/Caddyfile.http"
rsync -av \
rsync -av "${RSYNC_METADATA_ARGS[@]}" \
"${PLATFORM_REPO}/infra/synology/deploy-current.sh" \
"${PLATFORM_REPO}/infra/synology/backup-current.sh" \
"${PLATFORM_REPO}/infra/synology/apply-current-runtime.sh" \
@@ -36,7 +41,7 @@ rsync -av \
"${NAS_ROOT}/platform/"
mkdir -p "${NAS_ROOT}/platform/notification-core"
rsync -av --delete \
rsync -av "${RSYNC_METADATA_ARGS[@]}" --delete \
--exclude='node_modules/' \
--exclude='.env' \
--exclude='.env.*' \
@@ -44,7 +49,7 @@ rsync -av --delete \
"${NAS_ROOT}/platform/notification-core/"
mkdir -p "${NAS_ROOT}/platform/ai-workspace-hub"
rsync -av --delete \
rsync -av "${RSYNC_METADATA_ARGS[@]}" --delete \
--exclude='node_modules/' \
--exclude='.env' \
--exclude='.env.*' \
@@ -52,7 +57,7 @@ rsync -av --delete \
"${NAS_ROOT}/platform/ai-workspace-hub/"
mkdir -p "${NAS_ROOT}/platform/ai-workspace-assistant"
rsync -av --delete \
rsync -av "${RSYNC_METADATA_ARGS[@]}" --delete \
--exclude='node_modules/' \
--exclude='.env' \
--exclude='.env.*' \
@@ -61,7 +66,7 @@ rsync -av --delete \
if [[ "${SYNC_AUTHENTIK_TEMPLATES}" == "1" ]]; then
mkdir -p "${NAS_ROOT}/authentik/custom-templates"
rsync -av --delete \
rsync -av "${RSYNC_METADATA_ARGS[@]}" --delete \
"${PLATFORM_REPO}/infra/authentik/custom-templates/" \
"${NAS_ROOT}/authentik/custom-templates/"
else
@@ -75,7 +80,7 @@ if [[ -n "${LAUNCHER_REPO}" ]]; then
fi
mkdir -p "${NAS_ROOT}/launcher/source"
rsync -av --delete \
rsync -av "${RSYNC_METADATA_ARGS[@]}" --delete \
--exclude='.git/' \
--exclude='node_modules/' \
--exclude='dist/' \
@@ -95,7 +100,7 @@ if [[ -n "${TASKER_REPO}" ]]; then
mkdir -p "${NAS_ROOT}/tasker/plane-src" "${NAS_ROOT}/tasker/plane-app"
rsync -av \
rsync -av "${RSYNC_METADATA_ARGS[@]}" \
"${TASKER_REPO}/plane-app/docker-compose.yaml" \
"${NAS_ROOT}/tasker/plane-app/docker-compose.yaml"
@@ -121,14 +126,14 @@ if [[ -n "${TASKER_REPO}" ]]; then
if [[ -f "${source_path}" ]]; then
mkdir -p "$(dirname -- "${target_path}")"
rsync -av "${source_path}" "${target_path}"
rsync -av "${RSYNC_METADATA_ARGS[@]}" "${source_path}" "${target_path}"
else
echo "skip deleted Tasker file in changed sync: ${changed_file}"
fi
done
elif [[ "${TASKER_SYNC_SOURCE}" == "1" ]]; then
echo "TASKER_SYNC_SOURCE=1: syncing full Tasker source without delete"
rsync -av \
rsync -av "${RSYNC_METADATA_ARGS[@]}" \
--exclude='.git/' \
--exclude='node_modules/' \
--exclude='.pnpm-store/' \
@@ -153,7 +158,7 @@ if [[ -n "${TASKER_REPO}" ]]; then
fi
if [[ -f "${TASKER_REPO}/plane-app/docker-compose.synology.override.yml" ]]; then
rsync -av \
rsync -av "${RSYNC_METADATA_ARGS[@]}" \
"${TASKER_REPO}/plane-app/docker-compose.synology.override.yml" \
"${NAS_ROOT}/tasker/plane-app/docker-compose.synology.override.yml"
else
@@ -170,7 +175,7 @@ if [[ -n "${GATEWAY_REPO}" ]]; then
fi
mkdir -p "${NAS_ROOT}/ops-agents"
rsync -av --delete \
rsync -av "${RSYNC_METADATA_ARGS[@]}" --delete \
--exclude='.git/' \
--exclude='node_modules/' \
--exclude='dist/' \
+98
View File
@@ -0,0 +1,98 @@
#!/usr/bin/env bash
set -euo pipefail
NAS_ROOT="${NAS_ROOT:-/Volumes/docker/nodedc-platform}"
PLATFORM_ENV="${PLATFORM_ENV:-${NAS_ROOT}/platform/.env.synology}"
GATEWAY_ENV="${GATEWAY_ENV:-${NAS_ROOT}/ops-agents/.env}"
BACKUP_ROOT="${BACKUP_ROOT:-${NAS_ROOT}/backups/env-prep}"
TIMESTAMP="${TIMESTAMP:-$(date +%Y%m%d-%H%M%S)}"
BACKUP_DIR="${BACKUP_DIR:-${BACKUP_ROOT}/${TIMESTAMP}}"
mkdir -p "${BACKUP_DIR}"
read_env() {
local file="$1"
local key="$2"
[[ -f "${file}" ]] || return 0
awk -F= -v key="${key}" '
$0 ~ "^[[:space:]]*#" { next }
$1 == key {
value = substr($0, index($0, "=") + 1)
gsub(/^[[:space:]]+|[[:space:]]+$/, "", value)
gsub(/^"|"$/, "", value)
print value
exit
}
' "${file}"
}
backup_file() {
local file="$1"
local label="$2"
if [[ ! -f "${file}" ]]; then
echo "missing ${label}: ${file}" >&2
exit 1
fi
local backup_path="${BACKUP_DIR}/$(basename "${file}").${label}.bak"
if ! COPYFILE_DISABLE=1 cp -X "${file}" "${backup_path}" 2>/dev/null; then
cat "${file}" > "${backup_path}"
fi
chmod 600 "${backup_path}"
}
set_env_value() {
local file="$1"
local key="$2"
local value="$3"
local tmp
tmp="$(mktemp)"
if grep -qE "^${key}=" "${file}"; then
awk -v key="${key}" -v value="${value}" '
BEGIN { replaced = 0 }
$0 ~ "^[[:space:]]*#" { print; next }
index($0, key "=") == 1 {
print key "=" value
replaced = 1
next
}
{ print }
END {
if (!replaced) {
print key "=" value
}
}
' "${file}" > "${tmp}"
else
cat "${file}" > "${tmp}"
printf '\n%s=%s\n' "${key}" "${value}" >> "${tmp}"
fi
cat "${tmp}" > "${file}"
rm -f "${tmp}"
chmod 600 "${file}"
}
gateway_internal_token="$(read_env "${GATEWAY_ENV}" NODEDC_AGENT_GATEWAY_INTERNAL_TOKEN || true)"
if [[ -z "${gateway_internal_token}" || "${gateway_internal_token}" == replace-with-* || "${gateway_internal_token}" == change-me-* ]]; then
echo "Gateway NODEDC_AGENT_GATEWAY_INTERNAL_TOKEN is missing or placeholder in ${GATEWAY_ENV}" >&2
exit 1
fi
backup_file "${PLATFORM_ENV}" platform
backup_file "${GATEWAY_ENV}" ops-agents
set_env_value "${PLATFORM_ENV}" AI_WORKSPACE_HUB_PUBLIC_URL "wss://ai-hub.nodedc.ru/api/ai-workspace/hub"
set_env_value "${PLATFORM_ENV}" AI_WORKSPACE_HUB_INTERNAL_URL "https://ai-hub.nodedc.ru"
set_env_value "${PLATFORM_ENV}" AI_WORKSPACE_HUB_FALLBACK_URLS ""
set_env_value "${PLATFORM_ENV}" AI_WORKSPACE_OPS_ENTITLEMENT_URL "http://172.22.0.222:18190/api/internal/v1/ai-workspace/entitlements"
set_env_value "${PLATFORM_ENV}" AI_WORKSPACE_OPS_ENTITLEMENT_TOKEN "${gateway_internal_token}"
set_env_value "${PLATFORM_ENV}" AI_WORKSPACE_OPS_ENTITLEMENT_REQUIRED "false"
set_env_value "${GATEWAY_ENV}" NODEDC_AI_WORKSPACE_RUN_TOKEN_TTL_SECONDS "43200"
cat <<EOF
ai-workspace-env-prep-ok
backup_dir=${BACKUP_DIR}
updated_platform_env=${PLATFORM_ENV}
updated_gateway_env=${GATEWAY_ENV}
secrets_printed=false
EOF
+4
View File
@@ -67,6 +67,10 @@ echo "== ai workspace assistant hub target check =="
"${DOCKER_BIN}" exec nodedc-platform-ai-workspace-assistant-1 sh -lc \
'test "$AI_WORKSPACE_HUB_PUBLIC_URL" = "wss://ai-hub.nodedc.ru/api/ai-workspace/hub" && test -z "$AI_WORKSPACE_HUB_FALLBACK_URLS" && echo ai-workspace-prod-hub-target-ok'
echo "== ai workspace assistant Ops entitlement adapter check =="
"${DOCKER_BIN}" exec nodedc-platform-ai-workspace-assistant-1 sh -lc \
'test "$AI_WORKSPACE_OPS_ENTITLEMENT_URL" = "http://172.22.0.222:18190/api/internal/v1/ai-workspace/entitlements" && test -n "$AI_WORKSPACE_OPS_ENTITLEMENT_TOKEN" && echo ai-workspace-ops-entitlement-env-ok'
echo "== auth flow check =="
auth_flow="$(fetch_with_retry https://id.nodedc.ru/if/flow/default-authentication-flow/)"
printf '%s' "$auth_flow" \