Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.

Commit c099b3e

Browse files
fix(devcontainers-cli): set yarn install prefix to be one level up (#458)
Unfortunately I missed that `--prefix=/tmp/coder-script-data/bin` will install into `/tmp/coder-script-data/bin/bin`. This asks for the parent directory, resulting in `--prefix=/tmp/coder-script-data`.
1 parent f285eef commit c099b3e

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

devcontainers-cli/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ The devcontainers-cli module provides an easy way to install [`@devcontainers/cl
1616
```tf
1717
module "devcontainers-cli" {
1818
source = "registry.coder.com/modules/devcontainers-cli/coder"
19-
version = "1.0.2"
19+
version = "1.0.3"
2020
agent_id = coder_agent.example.id
2121
}
2222
```

devcontainers-cli/main.test.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,21 @@ const executeScriptInContainerWithPackageManager = async (
4040
]);
4141
}
4242

43-
const resp = await execContainer(id, [shell, "-c", instance.script]);
43+
const pathResp = await execContainer(id, [shell, "-c", "echo $PATH"]);
44+
const path = pathResp.stdout.trim();
45+
46+
console.log(path);
47+
48+
const resp = await execContainer(
49+
id,
50+
[shell, "-c", instance.script],
51+
[
52+
"--env",
53+
"CODER_SCRIPT_BIN_DIR=/tmp/coder-script-data/bin",
54+
"--env",
55+
`PATH=${path}:/tmp/coder-script-data/bin`,
56+
],
57+
);
4458
const stdout = resp.stdout.trim().split("\n");
4559
const stderr = resp.stderr.trim().split("\n");
4660
return {
@@ -104,7 +118,7 @@ describe("devcontainers-cli", async () => {
104118
"Installing @devcontainers/cli using yarn...",
105119
);
106120
expect(output.stdout[output.stdout.length - 1]).toEqual(
107-
"🥳 @devcontainers/cli has been installed into /usr/local/bin/devcontainer!",
121+
"🥳 @devcontainers/cli has been installed into /tmp/coder-script-data/bin/devcontainer!",
108122
);
109123
}, 15000);
110124

devcontainers-cli/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ install() {
3838
fi
3939
pnpm add -g @devcontainers/cli
4040
elif [ "$PACKAGE_MANAGER" = "yarn" ]; then
41-
yarn global add @devcontainers/cli --prefix "$CODER_SCRIPT_BIN_DIR"
41+
yarn global add @devcontainers/cli --prefix "$(dirname "$CODER_SCRIPT_BIN_DIR")"
4242
fi
4343
}
4444

test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,13 @@ export const executeScriptInContainer = async (
6666
export const execContainer = async (
6767
id: string,
6868
cmd: string[],
69+
args?: string[],
6970
): Promise<{
7071
exitCode: number;
7172
stderr: string;
7273
stdout: string;
7374
}> => {
74-
const proc = spawn(["docker", "exec", id, ...cmd], {
75+
const proc = spawn(["docker", "exec", ...(args ?? []), id, ...cmd], {
7576
stderr: "pipe",
7677
stdout: "pipe",
7778
});

0 commit comments

Comments
 (0)