@@ -9,12 +9,12 @@ import yargs, { Argv } from 'yargs';
99import * as jsonc from 'jsonc-parser' ;
1010
1111import { createDockerParams , createLog , experimentalImageMetadataDefault , launch , ProvisionOptions } from './devContainers' ;
12- import { SubstitutedConfig , createContainerProperties , createFeaturesTempFolder , envListToObj , inspectDockerImage , isDockerFileConfig , SubstituteConfig , addSubstitution } from './utils' ;
12+ import { SubstitutedConfig , createContainerProperties , createFeaturesTempFolder , envListToObj , inspectDockerImage , isDockerFileConfig , SubstituteConfig , addSubstitution , findContainerAndIdLabels } from './utils' ;
1313import { URI } from 'vscode-uri' ;
1414import { ContainerError } from '../spec-common/errors' ;
1515import { Log , LogLevel , makeLog , mapLogLevel } from '../spec-utils/log' ;
16- import { probeRemoteEnv , runLifecycleHooks , runRemoteCommand , UserEnvProbe , setupInContainer } from '../spec-common/injectHeadless' ;
17- import { bailOut , buildNamedImageAndExtend , findDevContainer , hostFolderLabel } from './singleContainer' ;
16+ import { probeRemoteEnv , runRemoteCommand , UserEnvProbe , setupInContainer , runLifecycleHooks } from '../spec-common/injectHeadless' ;
17+ import { bailOut , buildNamedImageAndExtend } from './singleContainer' ;
1818import { extendImage } from './containerFeatures' ;
1919import { DockerCLIParameters , dockerPtyCLI , inspectContainer } from '../spec-shutdown/dockerUtils' ;
2020import { buildAndExtendDockerCompose , dockerComposeCLIConfig , getDefaultImageName , getProjectName , readDockerComposeConfig , readVersionPrefix } from './dockerCompose' ;
@@ -193,7 +193,7 @@ async function provision({
193193 const addRemoteEnvs = addRemoteEnv ? ( Array . isArray ( addRemoteEnv ) ? addRemoteEnv as string [ ] : [ addRemoteEnv ] ) : [ ] ;
194194 const addCacheFroms = addCacheFrom ? ( Array . isArray ( addCacheFrom ) ? addCacheFrom as string [ ] : [ addCacheFrom ] ) : [ ] ;
195195 const additionalFeatures = additionalFeaturesJson ? jsonc . parse ( additionalFeaturesJson ) as Record < string , string | boolean | Record < string , string | boolean > > : { } ;
196- const idLabels = idLabel ? ( Array . isArray ( idLabel ) ? idLabel as string [ ] : [ idLabel ] ) : getDefaultIdLabels ( workspaceFolder ! ) ;
196+ const providedIdLabels = idLabel ? Array . isArray ( idLabel ) ? idLabel as string [ ] : [ idLabel ] : undefined ;
197197 const options : ProvisionOptions = {
198198 dockerPath,
199199 dockerComposePath,
@@ -245,7 +245,7 @@ async function provision({
245245 skipPersistingCustomizationsFromFeatures : false ,
246246 } ;
247247
248- const result = await doProvision ( options , idLabels ) ;
248+ const result = await doProvision ( options , providedIdLabels ) ;
249249 const exitCode = result . outcome === 'error' ? 1 : 0 ;
250250 console . log ( JSON . stringify ( result ) ) ;
251251 if ( result . outcome === 'success' ) {
@@ -255,13 +255,13 @@ async function provision({
255255 process . exit ( exitCode ) ;
256256}
257257
258- async function doProvision ( options : ProvisionOptions , idLabels : string [ ] ) {
258+ async function doProvision ( options : ProvisionOptions , providedIdLabels : string [ ] | undefined ) {
259259 const disposables : ( ( ) => Promise < unknown > | undefined ) [ ] = [ ] ;
260260 const dispose = async ( ) => {
261261 await Promise . all ( disposables . map ( d => d ( ) ) ) ;
262262 } ;
263263 try {
264- const result = await launch ( options , idLabels , disposables ) ;
264+ const result = await launch ( options , providedIdLabels , disposables ) ;
265265 return {
266266 outcome : 'success' as 'success' ,
267267 dispose,
@@ -758,8 +758,7 @@ async function doRunUserCommands({
758758 } ;
759759 try {
760760 const workspaceFolder = workspaceFolderArg ? path . resolve ( process . cwd ( ) , workspaceFolderArg ) : undefined ;
761- const idLabels = idLabel ? ( Array . isArray ( idLabel ) ? idLabel as string [ ] : [ idLabel ] ) :
762- workspaceFolder ? getDefaultIdLabels ( workspaceFolder ) : undefined ;
761+ const providedIdLabels = idLabel ? Array . isArray ( idLabel ) ? idLabel as string [ ] : [ idLabel ] : undefined ;
763762 const addRemoteEnvs = addRemoteEnv ? ( Array . isArray ( addRemoteEnv ) ? addRemoteEnv as string [ ] : [ addRemoteEnv ] ) : [ ] ;
764763 const configFile = configParam ? URI . file ( path . resolve ( process . cwd ( ) , configParam ) ) : undefined ;
765764 const overrideConfigFile = overrideConfig ? URI . file ( path . resolve ( process . cwd ( ) , overrideConfig ) ) : undefined ;
@@ -822,7 +821,7 @@ async function doRunUserCommands({
822821 substitute : value => substitute ( { platform : cliHost . platform , env : cliHost . env } , value )
823822 } ;
824823
825- const container = containerId ? await inspectContainer ( params , containerId ) : await findDevContainer ( params , idLabels ! ) ;
824+ const { container, idLabels } = await findContainerAndIdLabels ( params , containerId , providedIdLabels , workspaceFolder , configPath ?. fsPath ) ;
826825 if ( ! container ) {
827826 bailOut ( common . output , 'Dev container not found.' ) ;
828827 }
@@ -926,8 +925,7 @@ async function readConfiguration({
926925 let output : Log | undefined ;
927926 try {
928927 const workspaceFolder = workspaceFolderArg ? path . resolve ( process . cwd ( ) , workspaceFolderArg ) : undefined ;
929- const idLabels = idLabel ? ( Array . isArray ( idLabel ) ? idLabel as string [ ] : [ idLabel ] ) :
930- workspaceFolder ? getDefaultIdLabels ( workspaceFolder ) : undefined ;
928+ const providedIdLabels = idLabel ? Array . isArray ( idLabel ) ? idLabel as string [ ] : [ idLabel ] : undefined ;
931929 const configFile = configParam ? URI . file ( path . resolve ( process . cwd ( ) , configParam ) ) : undefined ;
932930 const overrideConfigFile = overrideConfig ? URI . file ( path . resolve ( process . cwd ( ) , overrideConfig ) ) : undefined ;
933931 const cwd = workspaceFolder || process . cwd ( ) ;
@@ -971,7 +969,7 @@ async function readConfiguration({
971969 env : cliHost . env ,
972970 output
973971 } ;
974- const container = containerId ? await inspectContainer ( params , containerId ) : await findDevContainer ( params , idLabels ! ) ;
972+ const { container, idLabels } = await findContainerAndIdLabels ( params , containerId , providedIdLabels , workspaceFolder , configPath ?. fsPath ) ;
975973 if ( container ) {
976974 configuration = addSubstitution ( configuration , config => beforeContainerSubstitute ( envListToObj ( idLabels ) , config ) ) ;
977975 configuration = addSubstitution ( configuration , config => containerSubstitute ( cliHost . platform , configuration . config . configFilePath , envListToObj ( container . Config . Env ) , config ) ) ;
@@ -1111,8 +1109,7 @@ export async function doExec({
11111109 } ;
11121110 try {
11131111 const workspaceFolder = workspaceFolderArg ? path . resolve ( process . cwd ( ) , workspaceFolderArg ) : undefined ;
1114- const idLabels = idLabel ? ( Array . isArray ( idLabel ) ? idLabel as string [ ] : [ idLabel ] ) :
1115- workspaceFolder ? getDefaultIdLabels ( workspaceFolder ) : undefined ;
1112+ const providedIdLabels = idLabel ? Array . isArray ( idLabel ) ? idLabel as string [ ] : [ idLabel ] : undefined ;
11161113 const addRemoteEnvs = addRemoteEnv ? ( Array . isArray ( addRemoteEnv ) ? addRemoteEnv as string [ ] : [ addRemoteEnv ] ) : [ ] ;
11171114 const configFile = configParam ? URI . file ( path . resolve ( process . cwd ( ) , configParam ) ) : undefined ;
11181115 const overrideConfigFile = overrideConfig ? URI . file ( path . resolve ( process . cwd ( ) , overrideConfig ) ) : undefined ;
@@ -1171,7 +1168,7 @@ export async function doExec({
11711168 substitute : value => substitute ( { platform : cliHost . platform , env : cliHost . env } , value )
11721169 } ;
11731170
1174- const container = containerId ? await inspectContainer ( params , containerId ) : await findDevContainer ( params , idLabels ! ) ;
1171+ const { container, idLabels } = await findContainerAndIdLabels ( params , containerId , providedIdLabels , workspaceFolder , configPath ?. fsPath ) ;
11751172 if ( ! container ) {
11761173 bailOut ( common . output , 'Dev container not found.' ) ;
11771174 }
@@ -1207,7 +1204,3 @@ export async function doExec({
12071204 } ;
12081205 }
12091206}
1210-
1211- function getDefaultIdLabels ( workspaceFolder : string ) {
1212- return [ `${ hostFolderLabel } =${ workspaceFolder } ` ] ;
1213- }
0 commit comments