@@ -20,7 +20,7 @@ const parseExecOutput = (output: unknown): string => {
2020} ;
2121
2222const execProcess = async (
23- command : string ,
23+ command : string
2424) : Promise < { stdout : string ; stderr : string ; exitCode : number } > => {
2525 try {
2626 const output = await exec ( command , { } ) ;
@@ -42,7 +42,9 @@ const execProcess = async (
4242 }
4343} ;
4444
45- const dockerWorkspaceInfoSchema = z . object ( {
45+ const dockerWorkspaceInfoSchema : z . ZodObject < {
46+ containerName : z . ZodString ;
47+ } > = z . object ( {
4648 containerName : z . string ( ) ,
4749} ) ;
4850
@@ -86,13 +88,13 @@ export const initializeDockerWorkspace =
8688 const { exitCode : versionExitCode } = await execProcess ( "docker --version" ) ;
8789 if ( versionExitCode !== 0 ) {
8890 throw new Error (
89- `Docker is not available. Please install it or choose a different workspace provider.` ,
91+ `Docker is not available. Please install it or choose a different workspace provider.`
9092 ) ;
9193 }
9294
9395 const imageName = `blink-workspace:${ DOCKERFILE_HASH } ` ;
9496 const { exitCode : dockerImageExistsExitCode } = await execProcess (
95- `docker image inspect ${ imageName } ` ,
97+ `docker image inspect ${ imageName } `
9698 ) ;
9799 if ( dockerImageExistsExitCode !== 0 ) {
98100 const buildCmd = `echo "${ DOCKERFILE_BASE64 } " | base64 -d | docker build -t ${ imageName } -f - .` ;
@@ -103,14 +105,14 @@ export const initializeDockerWorkspace =
103105 } = await execProcess ( buildCmd ) ;
104106 if ( buildExitCode !== 0 ) {
105107 throw new Error (
106- `Failed to build docker image ${ imageName } . Build output: ${ buildStdout } \n${ buildStderr } ` ,
108+ `Failed to build docker image ${ imageName } . Build output: ${ buildStdout } \n${ buildStderr } `
107109 ) ;
108110 }
109111 }
110112
111113 const containerName = `blink-workspace-${ crypto . randomUUID ( ) } ` ;
112114 const { exitCode : runExitCode } = await execProcess (
113- `docker run -d --publish ${ COMPUTE_SERVER_PORT } --name ${ containerName } ${ imageName } bash -c 'echo "${ BOOTSTRAP_SCRIPT_BASE64 } " | base64 -d | bash'` ,
115+ `docker run -d --publish ${ COMPUTE_SERVER_PORT } --name ${ containerName } ${ imageName } bash -c 'echo "${ BOOTSTRAP_SCRIPT_BASE64 } " | base64 -d | bash'`
114116 ) ;
115117 if ( runExitCode !== 0 ) {
116118 throw new Error ( `Failed to run docker container ${ containerName } ` ) ;
@@ -124,11 +126,11 @@ export const initializeDockerWorkspace =
124126 stdout,
125127 stderr,
126128 } = await execProcess (
127- `docker container inspect -f json ${ containerName } ` ,
129+ `docker container inspect -f json ${ containerName } `
128130 ) ;
129131 if ( inspectExitCode !== 0 ) {
130132 throw new Error (
131- `Failed to run docker container ${ containerName } . Inspect failed: ${ stdout } \n${ stderr } ` ,
133+ `Failed to run docker container ${ containerName } . Inspect failed: ${ stdout } \n${ stderr } `
132134 ) ;
133135 }
134136 const inspectOutput = dockerInspectSchema . parse ( JSON . parse ( stdout ) ) ;
@@ -137,7 +139,7 @@ export const initializeDockerWorkspace =
137139 }
138140 if ( Date . now ( ) - start > timeout ) {
139141 throw new Error (
140- `Timeout waiting for docker container ${ containerName } to start.` ,
142+ `Timeout waiting for docker container ${ containerName } to start.`
141143 ) ;
142144 }
143145 const {
@@ -147,7 +149,7 @@ export const initializeDockerWorkspace =
147149 } = await execProcess ( `docker container logs ${ containerName } ` ) ;
148150 if ( logsExitCode !== 0 ) {
149151 throw new Error (
150- `Failed to get logs for docker container ${ containerName } . Logs: ${ logsOutput } \n${ logsStderr } ` ,
152+ `Failed to get logs for docker container ${ containerName } . Logs: ${ logsOutput } \n${ logsStderr } `
151153 ) ;
152154 }
153155 if ( logsOutput . includes ( "Compute server running" ) ) {
@@ -166,15 +168,15 @@ const dockerInspectSchema = z.array(
166168 IPAddress : z . string ( ) ,
167169 Ports : z . object ( {
168170 [ `${ COMPUTE_SERVER_PORT } /tcp` ] : z . array (
169- z . object ( { HostPort : z . string ( ) } ) ,
171+ z . object ( { HostPort : z . string ( ) } )
170172 ) ,
171173 } ) ,
172174 } ) ,
173- } ) ,
175+ } )
174176) ;
175177
176178export const getDockerWorkspaceClient = async (
177- workspaceInfoRaw : unknown ,
179+ workspaceInfoRaw : unknown
178180) : Promise < Client > => {
179181 const {
180182 data : workspaceInfo ,
@@ -187,33 +189,33 @@ export const getDockerWorkspaceClient = async (
187189
188190 const { stdout : dockerInspectRawOutput , exitCode : inspectExitCode } =
189191 await execProcess (
190- `docker container inspect -f json ${ workspaceInfo . containerName } ` ,
192+ `docker container inspect -f json ${ workspaceInfo . containerName } `
191193 ) ;
192194 if ( inspectExitCode !== 0 ) {
193195 throw new Error (
194- `Failed to inspect docker container ${ workspaceInfo . containerName } . Initialize a new workspace with initialize_workspace first.` ,
196+ `Failed to inspect docker container ${ workspaceInfo . containerName } . Initialize a new workspace with initialize_workspace first.`
195197 ) ;
196198 }
197199 const dockerInspect = dockerInspectSchema . parse (
198- JSON . parse ( dockerInspectRawOutput ) ,
200+ JSON . parse ( dockerInspectRawOutput )
199201 ) ;
200202 const ipAddress = dockerInspect [ 0 ] ?. NetworkSettings . IPAddress ;
201203 if ( ! ipAddress ) {
202204 throw new Error (
203- `Could not find IP address for docker container ${ workspaceInfo . containerName } ` ,
205+ `Could not find IP address for docker container ${ workspaceInfo . containerName } `
204206 ) ;
205207 }
206208 if ( ! dockerInspect [ 0 ] ?. State . Running ) {
207209 throw new Error (
208- `Docker container ${ workspaceInfo . containerName } is not running.` ,
210+ `Docker container ${ workspaceInfo . containerName } is not running.`
209211 ) ;
210212 }
211213 const hostPort =
212214 dockerInspect [ 0 ] ?. NetworkSettings . Ports [ `${ COMPUTE_SERVER_PORT } /tcp` ] ?. [ 0 ]
213215 ?. HostPort ;
214216 if ( ! hostPort ) {
215217 throw new Error (
216- `Could not find host port for docker container ${ workspaceInfo . containerName } ` ,
218+ `Could not find host port for docker container ${ workspaceInfo . containerName } `
217219 ) ;
218220 }
219221 return newComputeClient ( new WebSocket ( `ws://localhost:${ hostPort } ` ) ) ;
0 commit comments