#!/usr/bin/env node import { spawnSync } from 'node:child_process'; import { dirname, resolve } from 'node:path'; import { fileURLToPath } from 'node:url'; const root = resolve(dirname(fileURLToPath(import.meta.url)), '..'); const storage = resolve(root, '..'); const context = process.env.GRAPH_DOCKER_CONTEXT || 'colima-yawan'; const container = process.env.GRAPH_APP_CONTAINER || 'yawan-native-acceptance'; const inspected = spawnSync('docker', ['--context', context, 'inspect', container], { encoding: 'utf8' }); if (inspected.status !== 0) throw new Error('Cannot inspect graph worker runtime'); const config = JSON.parse(inspected.stdout)[0]; const runtime = Object.fromEntries(config.Config.Env.map(value => { const index = value.indexOf('='); return [value.slice(0, index), value.slice(index + 1)]; })); const selected = Object.fromEntries(Object.entries(runtime).filter(([key]) => /^(DB_|REDIS_)/.test(key) || key === 'LEGACY_GRAPH_ENABLE')); const args = ['--context', context, 'run', '--rm', '--network', `container:${container}`, '-v', `${root}:/workspace:ro`, '-v', `${storage}/go-cache:/go`, '-v', `${storage}/go-build:/build-cache`, '-e', 'GOMODCACHE=/go/pkg/mod', '-e', 'GOCACHE=/build-cache', '-e', 'GRAPH_NATIVE_WRITE_VERIFIED']; if (process.env.GRAPH_BACKFILL_REVISION) args.push('-e', 'GRAPH_BACKFILL_REVISION'); if (process.env.GRAPH_LEDGER_RECONCILE_VERIFIED) args.push('-e', 'GRAPH_LEDGER_RECONCILE_VERIFIED'); for (const key of Object.keys(selected)) args.push('-e', key); args.push('-w', '/workspace', 'golang:1.26-bookworm', 'go', 'run', 'scripts/native_graph_backfill.go', ...process.argv.slice(2)); const result = spawnSync('docker', args, { env: { ...process.env, ...selected }, stdio: 'inherit' }); process.exitCode = result.status ?? 1;