Skip to content

Commit 34fe749

Browse files
Merge pull request #778 from grongierisc/master
Add option to open shell in docker
2 parents e89467c + 5ce41fe commit 34fe749

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/commands/serverActions.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
FILESYSTEM_READONLY_SCHEMA,
88
explorerProvider,
99
} from "../extension";
10-
import { connectionTarget, terminalWithDocker, currentFile } from "../utils";
10+
import { connectionTarget, terminalWithDocker, shellWithDocker, currentFile } from "../utils";
1111
import { mainCommandMenu, mainSourceControlMenu } from "./studio";
1212
import { AtelierAPI } from "../api";
1313
import { getCSPToken } from "../utils/getCSPToken";
@@ -107,6 +107,13 @@ export async function serverActions(): Promise<void> {
107107
detail: "Use docker-compose to start session inside configured service",
108108
});
109109
}
110+
if (workspaceState.get(workspaceFolder + ":docker", false)) {
111+
actions.push({
112+
id: "openDockerShell",
113+
label: "Open Shell in Docker",
114+
detail: "Use docker-compose to start shell inside configured service",
115+
});
116+
}
110117
actions.push({
111118
id: "openPortal",
112119
label: "Open Management Portal",
@@ -159,6 +166,10 @@ export async function serverActions(): Promise<void> {
159166
terminalWithDocker();
160167
break;
161168
}
169+
case "openDockerShell": {
170+
shellWithDocker();
171+
break;
172+
}
162173
case "serverSourceControlMenu": {
163174
mainSourceControlMenu();
164175
break;

src/utils/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,21 @@ export async function terminalWithDocker(): Promise<vscode.Terminal> {
396396
return terminal;
397397
}
398398

399+
export async function shellWithDocker(): Promise<vscode.Terminal> {
400+
const { "docker-compose": dockerCompose } = config("conn");
401+
const { service, file = "docker-compose.yml" } = dockerCompose;
402+
const workspace = currentWorkspaceFolder();
403+
404+
const terminalName = `Shell:${workspace}`;
405+
let terminal = terminals.find((t) => t.name == terminalName && t.exitStatus == undefined);
406+
if (!terminal) {
407+
terminal = vscode.window.createTerminal(terminalName, "docker-compose", ["-f", file, "exec", service, "/bin/bash"]);
408+
terminals.push(terminal);
409+
}
410+
terminal.show(true);
411+
return terminal;
412+
}
413+
399414
/**
400415
* Alter isfs-type uri.path of /.vscode/* files or subdirectories.
401416
* Rewrite `/.vscode/path/to/file` as `/_vscode/XYZ/path/to/file`

0 commit comments

Comments
 (0)