async function compose()

in src/commands/compose/compose.ts [16:71]


async function compose(context: IActionContext, commands: ('up' | 'down' | 'upSubset')[], message: string, dockerComposeFileUri?: vscode.Uri, selectedComposeFileUris?: vscode.Uri[]): Promise<void> {
    if (!vscode.workspace.isTrusted) {
        throw new UserCancelledError('enforceTrust');
    }

    // If a file is chosen, get its workspace folder, otherwise, require the user to choose
    // If a file is chosen that is not in a workspace, it will automatically fall back to quickPickWorkspaceFolder
    const folder: vscode.WorkspaceFolder = (dockerComposeFileUri ? vscode.workspace.getWorkspaceFolder(dockerComposeFileUri) : undefined) ||
        await quickPickWorkspaceFolder(context, localize('vscode-docker.commands.compose.workspaceFolder', 'To run Docker compose you must first open a folder or workspace in VS Code.'));

    let commandParameterFileUris: vscode.Uri[];
    if (selectedComposeFileUris && selectedComposeFileUris.length) {
        commandParameterFileUris = selectedComposeFileUris;
    } else if (dockerComposeFileUri) {
        commandParameterFileUris = [dockerComposeFileUri];
    } else {
        commandParameterFileUris = [];
    }

    let selectedItems: Item[] = commandParameterFileUris.map(uri => createFileItem(folder, uri));
    if (!selectedItems.length) {
        // prompt for compose file
        const selectedItem = await quickPickDockerComposeFileItem(context, folder, message);
        selectedItems = selectedItem ? [selectedItem] : [];
    }

    const configOptions: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration('docker');
    const build: boolean = configOptions.get('dockerComposeBuild', true);
    const detached: boolean = configOptions.get('dockerComposeDetached', true);

    for (const command of commands) {
        if (selectedItems.length === 0) {
            // Push a dummy item in so that we can use the looping logic below
            selectedItems.push(undefined);
        }

        for (const item of selectedItems) {
            let terminalCommand = await selectComposeCommand(
                context,
                folder,
                command,
                item?.relativeFilePath,
                detached,
                build
            );

            // Add the service list if needed
            terminalCommand = await addServicesOrProfilesIfNeeded(context, folder, terminalCommand);

            // Rewrite for the new CLI if needed
            terminalCommand = await rewriteComposeCommandIfNeeded(terminalCommand);

            await executeAsTask(context, terminalCommand, 'Docker Compose', { addDockerEnv: true, workspaceFolder: folder });
        }
    }
}