Skip to content

Commit

Permalink
Change scope the 'dockerRunArgs' to 'resource'; add dockerRunArgs a…
Browse files Browse the repository at this point in the history
…s a member of TaskProvider
  • Loading branch information
bigspider committed Jul 24, 2024
1 parent 0eaa644 commit b47a1a2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@
},
"ledgerDevTools.dockerRunArgs": {
"type": "string",
"scope": "resource",
"default": "",
"description": "Additional arguments to pass to the 'docker run' command for the Ledger developer tools Docker image."
},
Expand Down
15 changes: 9 additions & 6 deletions src/taskProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export class TaskProvider implements vscode.TaskProvider {
private packageName?: string;
private tasks: MyTask[] = [];
private currentApp?: App;
private dockerRunArgs: string = "";
private taskSpecs: TaskSpec[] = [
{
group: "Docker Container",
Expand Down Expand Up @@ -244,8 +245,13 @@ export class TaskProvider implements vscode.TaskProvider {
this.buildDir = this.currentApp.buildDirPath;
this.workspacePath = this.currentApp.folderUri.path;
this.packageName = this.currentApp.packageName;

const appConf = vscode.workspace.getConfiguration("ledgerDevTools", this.appFolderUri);
this.dockerRunArgs = appConf.get<string>("dockerRunArgs") || "";

this.checkDisabledTasks();
this.pushAllTasks();

this.treeProvider.addAllTasksToTree(this.taskSpecs);
}
}
Expand Down Expand Up @@ -276,21 +282,18 @@ export class TaskProvider implements vscode.TaskProvider {
private runDevToolsImageExec(): string {
let exec = "";

const conf = vscode.workspace.getConfiguration("ledgerDevTools");
const dockerRunArgs = conf.get<string>("dockerRunArgs");

if (this.currentApp) {
// Checks if a container with the name ${this.containerName} exists, and if it does, it is stopped and removed before a new container is created using the same name and other specified configuration parameters
if (platform === "linux") {
// Linux
exec = `docker ps -a --format '{{.Names}}' | grep -q ${this.containerName} && (docker container stop ${this.containerName} && docker container rm ${this.containerName}) ; docker pull ${this.image} && docker run --user $(id -u):$(id -g) --privileged -e DISPLAY=$DISPLAY -v '/dev/bus/usb:/dev/bus/usb' -v '/tmp/.X11-unix:/tmp/.X11-unix' -v '${this.workspacePath}:/app' ${dockerRunArgs} -t -d --name ${this.containerName} ${this.image}`;
exec = `docker ps -a --format '{{.Names}}' | grep -q ${this.containerName} && (docker container stop ${this.containerName} && docker container rm ${this.containerName}) ; docker pull ${this.image} && docker run --user $(id -u):$(id -g) --privileged -e DISPLAY=$DISPLAY -v '/dev/bus/usb:/dev/bus/usb' -v '/tmp/.X11-unix:/tmp/.X11-unix' -v '${this.workspacePath}:/app' ${this.dockerRunArgs} -t -d --name ${this.containerName} ${this.image}`;
} else if (platform === "darwin") {
// macOS
exec = `xhost + ; docker ps -a --format '{{.Names}}' | grep -q ${this.containerName} && (docker container stop ${this.containerName} && docker container rm ${this.containerName}) ; docker pull ${this.image} && docker run --user $(id -u):$(id -g) --privileged -e DISPLAY='host.docker.internal:0' -v '/tmp/.X11-unix:/tmp/.X11-unix' -v '${this.workspacePath}:/app' ${dockerRunArgs} -t -d --name ${this.containerName} ${this.image}`;
exec = `xhost + ; docker ps -a --format '{{.Names}}' | grep -q ${this.containerName} && (docker container stop ${this.containerName} && docker container rm ${this.containerName}) ; docker pull ${this.image} && docker run --user $(id -u):$(id -g) --privileged -e DISPLAY='host.docker.internal:0' -v '/tmp/.X11-unix:/tmp/.X11-unix' -v '${this.workspacePath}:/app' ${this.dockerRunArgs} -t -d --name ${this.containerName} ${this.image}`;
} else {
// Assume windows
const winWorkspacePath = this.workspacePath.substring(1); // Remove first '/' from windows workspace path URI. Otherwise it is not valid.
exec = `if (docker ps -a --format '{{.Names}}' | Select-String -Quiet ${this.containerName}) { docker container stop ${this.containerName}; docker container rm ${this.containerName} }; docker pull ${this.image}; docker run --privileged -e DISPLAY='host.docker.internal:0' -v '${winWorkspacePath}:/app' ${dockerRunArgs} -t -d --name ${this.containerName} ${this.image}`;
exec = `if (docker ps -a --format '{{.Names}}' | Select-String -Quiet ${this.containerName}) { docker container stop ${this.containerName}; docker container rm ${this.containerName} }; docker pull ${this.image}; docker run --privileged -e DISPLAY='host.docker.internal:0' -v '${winWorkspacePath}:/app' ${this.dockerRunArgs} -t -d --name ${this.containerName} ${this.image}`;
}
}

Expand Down

0 comments on commit b47a1a2

Please sign in to comment.