Skip to content

Commit e96ad12

Browse files
committed
Add open shell in docker
1 parent e89467c commit e96ad12

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,27 @@ 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", [
408+
"-f",
409+
file,
410+
"exec",
411+
service,
412+
"/bin/bash"
413+
]);
414+
terminals.push(terminal);
415+
}
416+
terminal.show(true);
417+
return terminal;
418+
}
419+
399420
/**
400421
* Alter isfs-type uri.path of /.vscode/* files or subdirectories.
401422
* Rewrite `/.vscode/path/to/file` as `/_vscode/XYZ/path/to/file`

0 commit comments

Comments
 (0)