From 5ba8fc36b8536f44f65c7dc3cddaddd146ee1cb6 Mon Sep 17 00:00:00 2001 From: Evan Sangaline Date: Thu, 22 Feb 2024 20:37:44 -0700 Subject: [PATCH] Get `sindri x circomspect` working. --- compose.yaml | 1 + src/cli/exec.ts | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/compose.yaml b/compose.yaml index 25b7a4f..408b988 100644 --- a/compose.yaml +++ b/compose.yaml @@ -13,6 +13,7 @@ services: - socat-docker-bridge environment: - DOCKER_HOST=tcp://localhost:2375 + - SINDRI_DEVELOPMENT_HOST_ROOT=${PWD} init: true network_mode: host extra_hosts: diff --git a/src/cli/exec.ts b/src/cli/exec.ts index 942b77b..612030d 100644 --- a/src/cli/exec.ts +++ b/src/cli/exec.ts @@ -48,6 +48,26 @@ const circomspectCommand = new Command() return process.exit(1); } + // Remap the root directory to its location on the host system when running in development mode. + let mountDirectory: string = rootDirectory; + if (process.env.SINDRI_DEVELOPMENT_HOST_ROOT) { + if (rootDirectory === "/sindri" || rootDirectory.startsWith("/sindri/")) { + mountDirectory = rootDirectory.replace( + "/sindri", + process.env.SINDRI_DEVELOPMENT_HOST_ROOT, + ); + sindri.logger.debug( + `Remapped "${rootDirectory}" to "${mountDirectory}" for bind mount on the Docker host.`, + ); + } else { + sindri.logger.fatal( + `The root directory path "${rootDirectory}" must be under "/sindri/"` + + 'when using "SINDRI_DEVELOPMENT_HOST_ROOT".', + ); + return process.exit(1); + } + } + // Run circomspect with the project root mounted and pipe the output to stdout. let status: number; try { @@ -59,7 +79,7 @@ const circomspectCommand = new Command() process.stdout, { HostConfig: { - Binds: [`${rootDirectory}:/sindri`], + Binds: [`${mountDirectory}:/sindri`], }, }, (error, data) => { @@ -102,6 +122,7 @@ export const execCommand = new Command() `using the current directory as the project root.`, ); } + rootDirectory = path.normalize(path.resolve(rootDirectory)); // Check that docker is installed. docker = new Docker();