Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
chrmarti committed Jan 19, 2023
1 parent 6b71a6e commit ff99677
Show file tree
Hide file tree
Showing 11 changed files with 388 additions and 60 deletions.
14 changes: 7 additions & 7 deletions src/spec-common/variableSubstitution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import { URI } from 'vscode-uri';

export interface SubstitutionContext {
platform: NodeJS.Platform;
configFile: URI;
localWorkspaceFolder: string | undefined;
containerWorkspaceFolder: string | undefined;
configFile?: URI;
localWorkspaceFolder?: string;
containerWorkspaceFolder?: string;
env: NodeJS.ProcessEnv;
}

Expand All @@ -33,9 +33,9 @@ export function substitute<T extends object>(context: SubstitutionContext, value
return substitute0(replace, value);
}

export function beforeContainerSubstitute<T extends object>(idLabels: Record<string, string>, value: T): T {
export function beforeContainerSubstitute<T extends object>(idLabels: Record<string, string> | undefined, value: T): T {
let devcontainerId: string | undefined;
return substitute0(replaceDevContainerId.bind(undefined, () => devcontainerId || (devcontainerId = devcontainerIdForLabels(idLabels))), value);
return substitute0(replaceDevContainerId.bind(undefined, () => devcontainerId || (idLabels && (devcontainerId = devcontainerIdForLabels(idLabels)))), value);
}

export function containerSubstitute<T extends object>(platform: NodeJS.Platform, configFile: URI | undefined, containerEnv: NodeJS.ProcessEnv, value: T): T {
Expand Down Expand Up @@ -124,10 +124,10 @@ function replaceContainerEnv(isWindows: boolean, configFile: URI | undefined, co
}
}

function replaceDevContainerId(getDevContainerId: () => string, match: string, variable: string) {
function replaceDevContainerId(getDevContainerId: () => string | undefined, match: string, variable: string) {
switch (variable) {
case 'devcontainerId':
return getDevContainerId();
return getDevContainerId() || match;

default:
return match;
Expand Down
4 changes: 2 additions & 2 deletions src/spec-configuration/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export interface DevContainerFeature {
}

export interface DevContainerFromImageConfig {
configFilePath: URI;
image: string;
configFilePath?: URI;
image?: string; // Only optional when setting up an existing container as a dev container.
name?: string;
forwardPorts?: (number | string)[];
appPort?: number | string | (number | string)[];
Expand Down
8 changes: 6 additions & 2 deletions src/spec-configuration/containerFeaturesConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ function featuresToArray(config: DevContainerConfig, additionalFeatures: Record<
async function processUserFeatures(params: ContainerFeatureInternalParams, config: DevContainerConfig, workspaceRoot: string, userFeatures: DevContainerFeature[], featuresConfig: FeaturesConfig): Promise<FeaturesConfig> {
const { platform, output } = params;

let configPath = uriToFsPath(config.configFilePath, platform);
let configPath = config.configFilePath && uriToFsPath(config.configFilePath, platform);
output.write(`configPath: ${configPath}`, LogLevel.Trace);

for (const userFeature of userFeatures) {
Expand Down Expand Up @@ -673,7 +673,7 @@ export function getBackwardCompatibleFeatureId(output: Log, id: string) {

// Strictly processes the user provided feature identifier to determine sourceInformation type.
// Returns a featureSet per feature.
export async function processFeatureIdentifier(params: CommonParams, configPath: string, _workspaceRoot: string, userFeature: DevContainerFeature, skipFeatureAutoMapping?: boolean): Promise<FeatureSet | undefined> {
export async function processFeatureIdentifier(params: CommonParams, configPath: string | undefined, _workspaceRoot: string, userFeature: DevContainerFeature, skipFeatureAutoMapping?: boolean): Promise<FeatureSet | undefined> {
const { output } = params;

output.write(`* Processing feature: ${userFeature.id}`);
Expand Down Expand Up @@ -765,6 +765,10 @@ export async function processFeatureIdentifier(params: CommonParams, configPath:
}

// Local-path features are expected to be a sub-folder of the '$WORKSPACE_ROOT/.devcontainer' folder.
if (!configPath) {
output.write('A local feature requires a configuration path.', LogLevel.Error);
return undefined;
}
const featureFolderPath = path.join(path.dirname(configPath), userFeature.id);

// Ensure we aren't escaping .devcontainer folder
Expand Down
5 changes: 2 additions & 3 deletions src/spec-node/devContainers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export interface ProvisionOptions {
workspaceFolder: string | undefined;
workspaceMountConsistency?: BindMountConsistency;
mountWorkspaceGitRoot: boolean;
idLabels: string[];
configFile: URI | undefined;
overrideConfigFile: URI | undefined;
logLevel: LogLevel;
Expand Down Expand Up @@ -66,13 +65,13 @@ export interface ProvisionOptions {
};
}

export async function launch(options: ProvisionOptions, disposables: (() => Promise<unknown> | undefined)[]) {
export async function launch(options: ProvisionOptions, idLabels: string[], disposables: (() => Promise<unknown> | undefined)[]) {
const params = await createDockerParams(options, disposables);
const output = params.common.output;
const text = 'Resolving Remote';
const start = output.start(text);

const result = await resolve(params, options.configFile, options.overrideConfigFile, options.idLabels, options.additionalFeatures ?? {});
const result = await resolve(params, options.configFile, options.overrideConfigFile, idLabels, options.additionalFeatures ?? {});
output.stop(text, start);
const { dockerContainerId, composeProjectName } = result;
return {
Expand Down
Loading

0 comments on commit ff99677

Please sign in to comment.