@@ -7,7 +7,7 @@ const path = require("path");
77const fs = require ( "fs" ) ;
88const os = require ( "os" ) ;
99
10- const { ROOT , SCRIPTS , run, runCapture, runInteractive } = require ( "./lib/runner" ) ;
10+ const { ROOT , SCRIPTS , run, runCapture, runInteractive, runArgv } = require ( "./lib/runner" ) ;
1111const {
1212 ensureApiKey,
1313 ensureGithubToken,
@@ -17,6 +17,7 @@ const {
1717const registry = require ( "./lib/registry" ) ;
1818const nim = require ( "./lib/nim" ) ;
1919const policies = require ( "./lib/policies" ) ;
20+ const { validateInstanceName, runSsh, runScp, runRsync, shellQuote : deployShellQuote } = require ( "./lib/deploy" ) ;
2021
2122// ── Global commands ──────────────────────────────────────────────
2223
@@ -106,6 +107,7 @@ async function deploy(instanceName) {
106107 await ensureGithubToken ( ) ;
107108 }
108109 const name = instanceName ;
110+ validateInstanceName ( name ) ;
109111 const gpu = process . env . NEMOCLAW_GPU || "a2-highgpu-1g:nvidia-tesla-a100:1" ;
110112
111113 console . log ( "" ) ;
@@ -127,17 +129,18 @@ async function deploy(instanceName) {
127129
128130 if ( ! exists ) {
129131 console . log ( ` Creating Brev instance '${ name } ' (${ gpu } )...` ) ;
130- run ( ` brev create ${ name } --gpu " ${ gpu } "` ) ;
132+ runArgv ( " brev" , [ " create" , name , " --gpu" , gpu ] ) ;
131133 } else {
132134 console . log ( ` Brev instance '${ name } ' already exists.` ) ;
133135 }
134136
135- run ( ` brev refresh` , { ignoreError : true } ) ;
137+ runArgv ( " brev" , [ " refresh" ] , { ignoreError : true } ) ;
136138
137139 console . log ( " Waiting for SSH..." ) ;
140+ const { execFileSync } = require ( "child_process" ) ;
138141 for ( let i = 0 ; i < 60 ; i ++ ) {
139142 try {
140- execSync ( ` ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no ${ name } ' echo ok' 2>/dev/null` , { encoding : "utf-8" , stdio : "pipe" } ) ;
143+ execFileSync ( " ssh" , [ "-o" , " ConnectTimeout=5" , "-o" , " StrictHostKeyChecking=accept-new" , name , " echo ok" ] , { encoding : "utf-8" , stdio : "pipe" } ) ;
141144 break ;
142145 } catch {
143146 if ( i === 59 ) {
@@ -149,8 +152,12 @@ async function deploy(instanceName) {
149152 }
150153
151154 console . log ( " Syncing NemoClaw to VM..." ) ;
152- run ( `ssh -o StrictHostKeyChecking=no -o LogLevel=ERROR ${ name } 'mkdir -p /home/ubuntu/nemoclaw'` ) ;
153- run ( `rsync -az --delete --exclude node_modules --exclude .git --exclude src -e "ssh -o StrictHostKeyChecking=no -o LogLevel=ERROR" "${ ROOT } /scripts" "${ ROOT } /Dockerfile" "${ ROOT } /nemoclaw" "${ ROOT } /nemoclaw-blueprint" "${ ROOT } /bin" "${ ROOT } /package.json" ${ name } :/home/ubuntu/nemoclaw/` ) ;
155+ runSsh ( name , "mkdir -p /home/ubuntu/nemoclaw" ) ;
156+ runRsync (
157+ [ `${ ROOT } /scripts` , `${ ROOT } /Dockerfile` , `${ ROOT } /nemoclaw` , `${ ROOT } /nemoclaw-blueprint` , `${ ROOT } /bin` , `${ ROOT } /package.json` ] ,
158+ name ,
159+ "/home/ubuntu/nemoclaw/"
160+ ) ;
154161
155162 const envLines = [ `NVIDIA_API_KEY=${ process . env . NVIDIA_API_KEY } ` ] ;
156163 const ghToken = process . env . GITHUB_TOKEN ;
@@ -159,21 +166,25 @@ async function deploy(instanceName) {
159166 if ( tgToken ) envLines . push ( `TELEGRAM_BOT_TOKEN=${ tgToken } ` ) ;
160167 const envTmp = path . join ( os . tmpdir ( ) , `nemoclaw-env-${ Date . now ( ) } ` ) ;
161168 fs . writeFileSync ( envTmp , envLines . join ( "\n" ) + "\n" , { mode : 0o600 } ) ;
162- run ( `scp -q -o StrictHostKeyChecking=no -o LogLevel=ERROR " ${ envTmp } " ${ name } :/home/ubuntu/nemoclaw/.env`) ;
169+ const scpResult = runScp ( envTmp , ` ${ name } :/home/ubuntu/nemoclaw/.env`, { ignoreError : true } ) ;
163170 fs . unlinkSync ( envTmp ) ;
171+ if ( scpResult . status !== 0 ) {
172+ console . error ( ` Failed to copy .env to ${ name } ` ) ;
173+ process . exit ( scpResult . status || 1 ) ;
174+ }
164175
165176 console . log ( " Running setup..." ) ;
166- runInteractive ( `ssh -t -o StrictHostKeyChecking=no -o LogLevel=ERROR ${ name } ' cd /home/ubuntu/nemoclaw && set -a && . .env && set +a && bash scripts/brev-setup.sh'` ) ;
177+ runSsh ( name , " cd /home/ubuntu/nemoclaw && set -a && . .env && set +a && bash scripts/brev-setup.sh" , { tty : true } ) ;
167178
168179 if ( tgToken ) {
169180 console . log ( " Starting services..." ) ;
170- run ( `ssh -o StrictHostKeyChecking=no -o LogLevel=ERROR ${ name } ' cd /home/ubuntu/nemoclaw && set -a && . .env && set +a && bash scripts/start-services.sh'` ) ;
181+ runSsh ( name , " cd /home/ubuntu/nemoclaw && set -a && . .env && set +a && bash scripts/start-services.sh" ) ;
171182 }
172183
173184 console . log ( "" ) ;
174185 console . log ( " Connecting to sandbox..." ) ;
175186 console . log ( "" ) ;
176- runInteractive ( `ssh -t -o StrictHostKeyChecking=no -o LogLevel=ERROR ${ name } ' cd /home/ubuntu/nemoclaw && set -a && . .env && set +a && openshell sandbox connect nemoclaw'` ) ;
187+ runSsh ( name , " cd /home/ubuntu/nemoclaw && set -a && . .env && set +a && openshell sandbox connect nemoclaw" , { tty : true } ) ;
177188}
178189
179190async function start ( ) {
@@ -260,8 +271,8 @@ function listSandboxes() {
260271
261272function sandboxConnect ( sandboxName ) {
262273 // Ensure port forward is alive before connecting
263- run ( `openshell forward start --background 18789 " ${ sandboxName } " 2>/dev/null || true` , { ignoreError : true } ) ;
264- runInteractive ( `openshell sandbox connect " ${ sandboxName } " ` ) ;
274+ run ( `openshell forward start --background 18789 ${ shellQuote ( sandboxName ) } 2>/dev/null || true` , { ignoreError : true } ) ;
275+ runInteractive ( `openshell sandbox connect ${ shellQuote ( sandboxName ) } ` ) ;
265276}
266277
267278function sandboxStatus ( sandboxName ) {
@@ -276,7 +287,7 @@ function sandboxStatus(sandboxName) {
276287 }
277288
278289 // openshell info
279- run ( `openshell sandbox get " ${ sandboxName } " 2>/dev/null || true` , { ignoreError : true } ) ;
290+ run ( `openshell sandbox get ${ shellQuote ( sandboxName ) } 2>/dev/null || true` , { ignoreError : true } ) ;
280291
281292 // NIM health
282293 const nimStat = nim . nimStatus ( sandboxName ) ;
@@ -288,8 +299,8 @@ function sandboxStatus(sandboxName) {
288299}
289300
290301function sandboxLogs ( sandboxName , follow ) {
291- const followFlag = follow ? " --tail " : "" ;
292- run ( `openshell logs " ${ sandboxName } " ${ followFlag } ` ) ;
302+ const followFlag = follow ? " --follow " : "" ;
303+ run ( `openshell sandbox logs ${ shellQuote ( sandboxName ) } ${ followFlag } ` ) ;
293304}
294305
295306async function sandboxPolicyAdd ( sandboxName ) {
@@ -332,7 +343,7 @@ function sandboxDestroy(sandboxName) {
332343 nim . stopNimContainer ( sandboxName ) ;
333344
334345 console . log ( ` Deleting sandbox '${ sandboxName } '...` ) ;
335- run ( `openshell sandbox delete " ${ sandboxName } " 2>/dev/null || true` , { ignoreError : true } ) ;
346+ run ( `openshell sandbox delete ${ shellQuote ( sandboxName ) } 2>/dev/null || true` , { ignoreError : true } ) ;
336347
337348 registry . removeSandbox ( sandboxName ) ;
338349 console . log ( ` ✓ Sandbox '${ sandboxName } ' destroyed` ) ;
0 commit comments