Files
flatrender/services/node-agent/internal/config/config.go
T
soroush.asadi 1ff6e494c0
Build backend images / build content-svc (push) Failing after 19s
Build backend images / build file-svc (push) Failing after 1m53s
Build backend images / build gateway (push) Failing after 16s
Build backend images / build identity-svc (push) Failing after 7m1s
Build backend images / build notification-svc (push) Failing after 7m24s
Build backend images / build render-svc (push) Failing after 3m12s
Build backend images / build studio-svc (push) Failing after 43s
@
feat: AE template scanner + scene editor + AEP bundle pipeline

Scene editor (admin): per-project Scenes / Shared Colors / Color Presets
manager (ProjectScenes) reachable from each project.

AEP bundle pipeline: upload .aep or .zip → stored once per template at
templates/{project_id}/(bundle.zip|template.aep); render claim probes and
returns is_bundle+md5; node-agent extracts the bundle, locates the .aep
(zip-slip guarded), and caches by md5 so repeated renders extract once.

AE template scanner ("read scenes/colours/configs from the AEP"):
- content-svc importer: POST /v1/projects/{id}/scan/{preview,apply} —
  review-diff-then-merge into scenes/elements/colours (manual edits kept).
- render-svc Go quick-scan: stdlib RIFX parser extracts comp names+durations
  (no AE) → POST /v1/template-scans/{id}/quick.
- render-svc AE scan jobs + node-agent runner: queue → node runs scan.jsx
  (reverse of legacy JSXGenerator conventions: frfinal/frshare/frl_/frd_) →
  posts ScanResult back. Migration 26_render_scan_jobs.
- admin UI: "اسکن از افترافکت" with quick/full engines + diff-review modal.

Verified: importer preview/apply, Go quick-scan end-to-end (synthetic .aep →
scene imported), bundle extract unit tests, RIFX parser unit tests.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@
2026-06-04 10:39:45 +03:30

101 lines
3.3 KiB
Go

// Package config loads node-agent runtime configuration from environment variables.
package config
import (
"fmt"
"os"
"path/filepath"
"strconv"
)
// Config holds all runtime settings for the node agent.
type Config struct {
// NodeID is the UUID of this render node, registered in the orchestrator.
// Must match a row in render.render_nodes.
NodeID string
// OrchestratorURL is the base URL of the V2 API gateway (internal network).
// Example: http://gateway:8080 or http://172.30.0.5:8088
OrchestratorURL string
// NodeHMACSecret is the shared secret sent as X-Node-Signature header.
// Must match NODE_HMAC_SECRET in the render-svc environment.
NodeHMACSecret string
// Region is the datacenter/region label for this node (e.g. "iran-tehran-1").
// The orchestrator uses it to route region-preferred jobs to this node.
Region string
// AEPath is the full path to the aerender.exe binary.
// Example: C:\Program Files\Adobe\Adobe After Effects 2024\Support Files\aerender.exe
// Leave empty to use mock rendering (for development / testing without AE).
AEPath string
// AfterFxPath is the full path to afterfx.exe (the AE app, used to run the
// template scanner script). Defaults to afterfx.exe alongside aerender.exe.
// Leave AEPath empty too to disable scanning (dev/mock).
AfterFxPath string
// WorkDir is the scratch directory for render temp files and AE project copies.
WorkDir string
// HeartbeatIntervalSec is how often the agent sends a heartbeat to the orchestrator.
HeartbeatIntervalSec int
// PollIntervalSec is how long the agent waits between job-claim attempts when idle.
PollIntervalSec int
// AgentVersion is the semantic version string reported to the orchestrator.
AgentVersion string
// AEVersion is the After Effects version string reported to the orchestrator.
// Example: "2024"
AEVersion string
// ListenPort is the port for the agent's own HTTP health endpoint.
ListenPort int
}
// Load reads configuration from environment variables, returning an error
// if any required variable is missing.
func Load() (*Config, error) {
c := &Config{
NodeID: os.Getenv("NODE_ID"),
OrchestratorURL: getEnv("ORCHESTRATOR_URL", "http://localhost:8088"),
NodeHMACSecret: getEnv("NODE_HMAC_SECRET", "node-secret-change-me"),
Region: getEnv("NODE_REGION", ""),
AEPath: getEnv("AE_PATH", ""),
AfterFxPath: getEnv("AFTERFX_PATH", ""),
WorkDir: getEnv("WORK_DIR", os.TempDir()),
AgentVersion: getEnv("AGENT_VERSION", "0.1.0"),
AEVersion: getEnv("AE_VERSION", "2024"),
HeartbeatIntervalSec: getInt("HEARTBEAT_INTERVAL_SEC", 5),
PollIntervalSec: getInt("POLL_INTERVAL_SEC", 3),
ListenPort: getInt("LISTEN_PORT", 7777),
}
if c.NodeID == "" {
return nil, fmt.Errorf("NODE_ID environment variable is required")
}
// Derive afterfx.exe next to aerender.exe when not explicitly set.
if c.AfterFxPath == "" && c.AEPath != "" {
c.AfterFxPath = filepath.Join(filepath.Dir(c.AEPath), "afterfx.exe")
}
return c, nil
}
func getEnv(key, fallback string) string {
if v := os.Getenv(key); v != "" {
return v
}
return fallback
}
func getInt(key string, fallback int) int {
if v := os.Getenv(key); v != "" {
if n, err := strconv.Atoi(v); err == nil {
return n
}
}
return fallback
}