Files
aios/ops/gitops-migration/aios_v1r1c0_runtime_services.sh
T

98 lines
3.1 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
ROOT="/data/aios-gitops"
WORKSPACE="$ROOT/workspace"
LOG="$ROOT/logs/runtime-services-v1r1c0.log"
mkdir -p "$ROOT/logs" "$ROOT/runtime/secrets" "$WORKSPACE/deploy/systemd" "$WORKSPACE/deploy/gitea"
touch "$LOG"
log() {
printf '[%s] %s\n' "$(date -Is)" "$*" | tee -a "$LOG"
}
cd "$WORKSPACE"
TOKEN_FILE="$ROOT/runtime/secrets/gitops.tokens"
BARE_REPO="$ROOT/runtime/gitea-bin/data/repositories/aios/aios-v23.git"
if [ ! -s "$TOKEN_FILE" ]; then
(openssl rand -hex 32 || python3 -c 'import secrets; print(secrets.token_hex(32))') > "$TOKEN_FILE"
chmod 600 "$TOKEN_FILE"
fi
cat > deploy/systemd/aios-gitops-model-api.service <<EOF
[Unit]
Description=AIOS V1R1C0 GitOps Model API
After=network.target
[Service]
Type=simple
User=aiman
Group=aiman
Environment=AIOS_GITOPS_ROOT=$ROOT
Environment=AIOS_GITOPS_WORKSPACE=$WORKSPACE
Environment=AIOS_GITOPS_DB=$ROOT/runtime/gitops_model.sqlite3
Environment=AIOS_GITOPS_TOKEN_FILE=$TOKEN_FILE
Environment=AIOS_GITOPS_BARE_REPO=$BARE_REPO
Environment=AIOS_GITOPS_HOST=127.0.0.1
Environment=AIOS_GITOPS_PORT=18890
ExecStart=/usr/bin/python3 $WORKSPACE/active-runtime/app/aios_chatgpt_actions_api.py
Restart=always
RestartSec=3
[Install]
WantedBy=multi-user.target
EOF
cat > deploy/gitea/docker-compose.yml <<'EOF'
services:
gitea:
image: gitea/gitea:1.22
container_name: aios-gitea
restart: unless-stopped
environment:
- USER_UID=1000
- USER_GID=1000
- GITEA__server__DOMAIN=cnnetmkt.top
- GITEA__server__ROOT_URL=https://cnnetmkt.top/git/
- GITEA__server__SERVE_FROM_SUB_PATH=true
- GITEA__server__HTTP_PORT=3000
- GITEA__server__SSH_DOMAIN=cnnetmkt.top
- GITEA__server__SSH_PORT=2222
- GITEA__service__DISABLE_REGISTRATION=true
- GITEA__webhook__ALLOWED_HOST_LIST=*
- GITEA__database__DB_TYPE=sqlite3
volumes:
- /data/aios-gitops/runtime/gitea:/data
ports:
- "127.0.0.1:3000:3000"
- "127.0.0.1:2222:22"
EOF
git add deploy/systemd/aios-gitops-model-api.service deploy/gitea/docker-compose.yml
git commit -m "chore(gitops): add V1R1C0 runtime API and Gitea deployment manifests" || true
log "install API systemd unit"
sudo cp deploy/systemd/aios-gitops-model-api.service /etc/systemd/system/aios-gitops-model-api.service
sudo systemctl daemon-reload
sudo systemctl enable --now aios-gitops-model-api.service
sleep 2
systemctl is-active aios-gitops-model-api.service | tee -a "$LOG"
curl -fsS http://127.0.0.1:18890/health | tee -a "$LOG"
log "start gitea"
mkdir -p "$ROOT/adapters/gitea"
cp deploy/gitea/docker-compose.yml "$ROOT/adapters/gitea/docker-compose.yml"
(cd "$ROOT/adapters/gitea" && docker compose up -d)
for i in $(seq 1 60); do
if curl -fsS http://127.0.0.1:3000/git/api/healthz >/dev/null 2>&1 || curl -fsS http://127.0.0.1:3000/git/ >/dev/null 2>&1; then
break
fi
sleep 2
done
curl -fsS http://127.0.0.1:3000/git/ >/dev/null || true
docker ps --format '{{.Names}} {{.Image}} {{.Status}} {{.Ports}}' | grep -E '^aios-gitea ' | tee -a "$LOG" || true
log "runtime manifests committed and services attempted"