Skip to content

Commit

Permalink
more cleanly separate out getting ports from converting them into flags
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Gilgur <[email protected]>
  • Loading branch information
agilgur5 committed Jul 16, 2024
1 parent 5356a4d commit a8b9491
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/spec-node/ports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ function normalizePorts(ports: number | string | (number | string)[] | undefined
return ports.map((port) => typeof port === 'number' ? `127.0.0.1:${port}:${port}`: port);
}

export function getStaticPortsArgs(config: DevContainerFromDockerfileConfig | DevContainerFromImageConfig): string[] {
const staticPorts = normalizePorts(config.forwardPorts).concat(normalizePorts(config.appPort));
return staticPorts.flatMap((port) => ['-p', port]);
export function getStaticPorts(config: DevContainerFromDockerfileConfig | DevContainerFromImageConfig): string[] {
return normalizePorts(config.forwardPorts).concat(normalizePorts(config.appPort));
}
5 changes: 3 additions & 2 deletions src/spec-node/singleContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { LogLevel, Log, makeLog } from '../spec-utils/log';
import { extendImage, getExtendImageBuildInfo, updateRemoteUserUID } from './containerFeatures';
import { getDevcontainerMetadata, getImageBuildInfoFromDockerfile, getImageMetadataFromContainer, ImageMetadataEntry, lifecycleCommandOriginMapFromMetadata, mergeConfiguration, MergedDevContainerConfig } from './imageMetadata';
import { ensureDockerfileHasFinalStageName, generateMountCommand } from './dockerfileUtils';
import { getStaticPortsArgs } from './ports';
import { getStaticPorts } from './ports';

export const hostFolderLabel = 'devcontainer.local_folder'; // used to label containers created from a workspace/folder
export const configFileLabel = 'devcontainer.config_file';
Expand Down Expand Up @@ -349,7 +349,8 @@ export async function spawnDevContainer(params: DockerResolverParameters, config
const { common } = params;
common.progress(ResolverProgress.StartingContainer);

const exposed = getStaticPortsArgs(config);
const exposedPorts = getStaticPorts(config);
const exposed = exposedPorts.flatMap((port) => ['-p', port]);

const cwdMount = workspaceMount ? ['--mount', workspaceMount] : [];

Expand Down

0 comments on commit a8b9491

Please sign in to comment.