private async inferVolumes()

in src/tasks/netcore/NetCoreTaskHelper.ts [194:274]


    private async inferVolumes(folder: WorkspaceFolder, runOptions: DockerRunOptions, helperOptions: NetCoreTaskOptions, ssl: boolean, userSecrets: boolean): Promise<DockerContainerVolume[]> {
        const volumes: DockerContainerVolume[] = [];

        if (runOptions.volumes) {
            for (const volume of runOptions.volumes) {
                addVolumeWithoutConflicts(volumes, volume);
            }
        }

        if (helperOptions.enableDebugging) {
            const appVolume: DockerContainerVolume = {
                localPath: path.dirname(helperOptions.appProject),
                containerPath: runOptions.os === 'Windows' ? 'C:\\app' : '/app',
                permissions: 'rw,z'
            };

            const srcVolume: DockerContainerVolume = {
                localPath: folder.uri.fsPath,
                containerPath: runOptions.os === 'Windows' ? 'C:\\src' : '/src',
                permissions: 'rw,z'
            };

            const debuggerVolume: DockerContainerVolume = {
                localPath: vsDbgInstallBasePath,
                containerPath: runOptions.os === 'Windows' ? 'C:\\remote_debugger' : '/remote_debugger',
                permissions: 'ro,z'
            };

            const nugetRootVolume: DockerContainerVolume = {
                localPath: path.join(os.homedir(), '.nuget', 'packages'),
                containerPath: runOptions.os === 'Windows' ? 'C:\\.nuget\\packages' : '/root/.nuget/packages',
                permissions: 'ro,z'
            };

            const nugetUserVolume: DockerContainerVolume = {
                localPath: nugetRootVolume.localPath, // Same local path as the root one
                containerPath: runOptions.os === 'Windows' ? 'C:\\Users\\ContainerUser\\.nuget\\packages' : '/home/appuser/.nuget/packages',
                permissions: 'ro,z'
            };

            addVolumeWithoutConflicts(volumes, appVolume);
            addVolumeWithoutConflicts(volumes, srcVolume);
            addVolumeWithoutConflicts(volumes, debuggerVolume);
            addVolumeWithoutConflicts(volumes, nugetRootVolume);
            addVolumeWithoutConflicts(volumes, nugetUserVolume);
        }

        if (userSecrets || ssl) {
            // Try to get a container username from the image (best effort only)
            let userName: string | undefined;
            try {
                const imageInspection = await ext.dockerClient.inspectImage(undefined, runOptions.image);
                userName = imageInspection?.Config?.User;
            } catch {
                // Best effort
            }

            const hostSecretsFolders = getHostSecretsFolders();
            const containerSecretsFolders = getContainerSecretsFolders(runOptions.os, userName);

            const userSecretsVolume: DockerContainerVolume = {
                localPath: hostSecretsFolders.hostUserSecretsFolder,
                containerPath: containerSecretsFolders.containerUserSecretsFolder,
                permissions: 'ro,z'
            };

            addVolumeWithoutConflicts(volumes, userSecretsVolume);

            if (ssl) {
                const certVolume: DockerContainerVolume = {
                    localPath: hostSecretsFolders.hostCertificateFolder,
                    containerPath: containerSecretsFolders.containerCertificateFolder,
                    permissions: 'ro,z'
                };

                addVolumeWithoutConflicts(volumes, certVolume);
            }
        }

        return volumes;
    }