Skip to content

Commit

Permalink
Give priority to folder-specific docker-compose.yml once again (#1464)
Browse files Browse the repository at this point in the history
* Give priority to folder-specific docker-compose.yml file once again

* Make compareConns function docker-compose aware
  • Loading branch information
gjsjohnmurray authored Jan 3, 2025
1 parent 203c016 commit e3d6460
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
21 changes: 17 additions & 4 deletions src/providers/DocumentContentProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,30 @@ import { config, FILESYSTEM_SCHEMA, FILESYSTEM_READONLY_SCHEMA, OBJECTSCRIPT_FIL
import { currentWorkspaceFolder, uriOfWorkspaceFolder } from "../utils";

export function compareConns(
conn1: { ns: any; server: any; host: any; port: any },
conn2: { ns: any; server: any; host: any; port: any }
conn1: { ns: any; server: any; host: any; port: any; "docker-compose": any },
conn2: { ns: any; server: any; host: any; port: any; "docker-compose": any }
): boolean {
if (conn1.ns === conn2.ns) {
// Same namespace name
if (conn1.server && conn2.server) {
// Both connections name an entry in intersystems.servers
if (conn1.server === conn2.server) {
return true;
}
} else if (!conn1.server && !conn2.server) {
if (conn1.host === conn2.host && conn1.port === conn2.port) {
return true;
if (conn1.port && conn2.port) {
// Both connections specify a target port
if (conn1.host === conn2.host && conn1.port === conn2.port) {
return true;
}
} else if (conn1["docker-compose"] && conn2["docker-compose"]) {
// Both connections specify a docker-compose object
if (conn1["docker-compose"].service === conn2["docker-compose"].service) {
// Assume that if the service names match then the connection is to the same place.
// This may not be true (e.g. if the same service name is used in folder-specific docker-compose files)
// but it's the best we can do here without more information.
return true;
}
}
}
}
Expand Down
18 changes: 12 additions & 6 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,12 +473,18 @@ export async function portFromDockerCompose(): Promise<{ port: number; docker: b
const workspaceFolderPath = workspaceFolder.fsPath;
const workspaceRootPath = vscode.workspace.workspaceFolders[0].uri.fsPath;

const cwd: string = await fileExists(vscode.Uri.file(path.join(workspaceFolderPath, file))).then((exists) => {
const cwd: string = await fileExists(vscode.Uri.file(path.join(workspaceFolderPath, file))).then(async (exists) => {
if (exists) {
return workspaceRootPath;
} else {
throw new Error(`File '${file}' not found.`);
return workspaceFolderPath;
}
if (workspaceFolderPath !== workspaceRootPath) {
exists = await fileExists(vscode.Uri.file(path.join(workspaceRootPath, file)));
if (exists) {
return workspaceRootPath;
}
throw new Error(`File '${file}' not found in ${workspaceFolderPath} or ${workspaceRootPath}.`);
}
throw new Error(`File '${file}' not found in ${workspaceFolderPath}.`);
});

if (!cwd) {
Expand All @@ -494,7 +500,7 @@ export async function portFromDockerCompose(): Promise<{ port: number; docker: b
reject(error.message);
}
if (!stdout.replaceAll("\r", "").split("\n").includes(service)) {
reject(`Service '${service}' not found in '${file}', or not running.`);
reject(`Service '${service}' not found in '${path.join(cwd, file)}', or not running.`);
}

exec(`${cmd} port --protocol=tcp ${service} ${internalPort}`, { cwd }, (error, stdout) => {
Expand All @@ -503,7 +509,7 @@ export async function portFromDockerCompose(): Promise<{ port: number; docker: b
}
const [, port] = stdout.match(/:(\d+)/) || [];
if (!port) {
reject(`Port ${internalPort} not published for service '${service}'.`);
reject(`Port ${internalPort} not published for service '${service}' in '${path.join(cwd, file)}'.`);
}
resolve({ port: parseInt(port, 10), docker: true, service });
});
Expand Down

0 comments on commit e3d6460

Please sign in to comment.