Skip to content

Add option to open shell in docker #778

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/commands/serverActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
FILESYSTEM_READONLY_SCHEMA,
explorerProvider,
} from "../extension";
import { connectionTarget, terminalWithDocker, currentFile } from "../utils";
import { connectionTarget, terminalWithDocker, shellWithDocker, currentFile } from "../utils";
import { mainCommandMenu, mainSourceControlMenu } from "./studio";
import { AtelierAPI } from "../api";
import { getCSPToken } from "../utils/getCSPToken";
Expand Down Expand Up @@ -107,6 +107,13 @@ export async function serverActions(): Promise<void> {
detail: "Use docker-compose to start session inside configured service",
});
}
if (workspaceState.get(workspaceFolder + ":docker", false)) {
actions.push({
id: "openDockerShell",
label: "Open Shell in Docker",
detail: "Use docker-compose to start shell inside configured service",
});
}
actions.push({
id: "openPortal",
label: "Open Management Portal",
Expand Down Expand Up @@ -159,6 +166,10 @@ export async function serverActions(): Promise<void> {
terminalWithDocker();
break;
}
case "openDockerShell": {
shellWithDocker();
break;
}
case "serverSourceControlMenu": {
mainSourceControlMenu();
break;
Expand Down
15 changes: 15 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,21 @@ export async function terminalWithDocker(): Promise<vscode.Terminal> {
return terminal;
}

export async function shellWithDocker(): Promise<vscode.Terminal> {
const { "docker-compose": dockerCompose } = config("conn");
const { service, file = "docker-compose.yml" } = dockerCompose;
const workspace = currentWorkspaceFolder();

const terminalName = `Shell:${workspace}`;
let terminal = terminals.find((t) => t.name == terminalName && t.exitStatus == undefined);
if (!terminal) {
terminal = vscode.window.createTerminal(terminalName, "docker-compose", ["-f", file, "exec", service, "/bin/bash"]);
terminals.push(terminal);
}
terminal.show(true);
return terminal;
}

/**
* Alter isfs-type uri.path of /.vscode/* files or subdirectories.
* Rewrite `/.vscode/path/to/file` as `/_vscode/XYZ/path/to/file`
Expand Down