Skip to content
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

VSCode Ansible and remote - SSH compatibility for docker #262

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,11 @@
"type": "string",
"default": "",
"description": "Location of Azure REST specification."
},
"ansible.targetName": {
"type": "string",
"default": "",
"descritption": "Specify which folder will be used on the target."
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ export class Constants {
public static LineSeperator = Array(50).join('=');
public static AzureAccountExtensionId = 'ms-vscode.azure-account';
public static DockerImageName = 'microsoft/ansible:latest';
public static TargetName = '${workspaceFolderBasename}';
public static AnsibleTerminalName = 'Ansible';
public static UserAgentName = 'VSCODEEXT_USER_AGENT';
public static Config_cloudShellConfirmed = 'cloudShellConfirmed';
public static Config_credentialConfigured = 'credentialsConfigured';
public static Config_credentialsFile = 'credentialsFile';
public static Config_dockerImage = 'dockerImage';
public static Config_targetName = 'targetName';
public static Config_useWSL = 'useWSL';
public static Config_terminalInitCommand = 'terminalInitCommand';
public static Config_fileCopyConfig = 'fileCopyConfig';
Expand All @@ -31,4 +33,4 @@ export enum CloudShellConnectionStatus {
Init = 'init',
Succeeded = 'succeeded',
Failed = 'failed'
}
}
20 changes: 15 additions & 5 deletions src/dockerRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,39 @@ import { TerminalBaseRunner } from './terminalBaseRunner';
import * as fsExtra from 'fs-extra';
import * as child_process from 'child_process';


export class DockerRunner extends TerminalBaseRunner {
constructor(outputChannel: vscode.OutputChannel) {
super(outputChannel);
}

private getTargetName(): string {
let customTarget = utilities.getCodeConfiguration<string>('ansible', Constants.Config_targetName);
if (!customTarget) {
customTarget = Constants.TargetName;
}
return customTarget;
}

protected getCmds(playbook: string, envs: string[], terminalId: string): string[] {
var cmdsToTerminal = [];
let cmd: string = utilities.getCodeConfiguration<string>(null, Constants.Config_terminalInitCommand);

var sourcePath = path.dirname(playbook);
var targetPath = '/playbook';
var targetPlaybook = targetPath + '/' + path.basename(playbook);
targetPlaybook = path.relative(sourcePath, playbook);
targetPlaybook = targetPlaybook.replace(/\\/g, '/');
if (vscode.workspace.workspaceFolders) {
sourcePath = vscode.workspace.workspaceFolders[0].uri.fsPath;
targetPath = '/' + vscode.workspace.name;
targetPlaybook = path.relative(sourcePath, playbook);
targetPlaybook = targetPlaybook.replace(/\\/g, '/');
}
}


if (cmd === "default" || cmd === '') {
cmd = "docker run --rm -it -v \"" + sourcePath + ":" + targetPath + "\"" +
" --workdir \"" + targetPath + "\"" + " --name " + terminalId;
cmd = "docker run --rm -it -v \"" + sourcePath + ":/" + this.getTargetName() + "\"" +
" --workdir \"/" + this.getTargetName() + "\"" + " --name " + terminalId;

// add credential envs if any
if (envs) {
Expand Down Expand Up @@ -135,4 +145,4 @@ export class DockerRunner extends TerminalBaseRunner {
}
return customDocker;
}
}
}