@@ -9,12 +9,12 @@ import yargs, { Argv } from 'yargs';
9
9
import * as jsonc from 'jsonc-parser' ;
10
10
11
11
import { 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' ;
13
13
import { URI } from 'vscode-uri' ;
14
14
import { ContainerError } from '../spec-common/errors' ;
15
15
import { Log , LogLevel , makeLog , mapLogLevel } from '../spec-utils/log' ;
16
16
import { probeRemoteEnv , runPostCreateCommands , runRemoteCommand , UserEnvProbe , setupInContainer } from '../spec-common/injectHeadless' ;
17
- import { bailOut , buildNamedImageAndExtend , findDevContainer , hostFolderLabel } from './singleContainer' ;
17
+ import { bailOut , buildNamedImageAndExtend } from './singleContainer' ;
18
18
import { extendImage } from './containerFeatures' ;
19
19
import { DockerCLIParameters , dockerPtyCLI , inspectContainer } from '../spec-shutdown/dockerUtils' ;
20
20
import { buildAndExtendDockerCompose , dockerComposeCLIConfig , getDefaultImageName , getProjectName , readDockerComposeConfig , readVersionPrefix } from './dockerCompose' ;
@@ -193,7 +193,7 @@ async function provision({
193
193
const addRemoteEnvs = addRemoteEnv ? ( Array . isArray ( addRemoteEnv ) ? addRemoteEnv as string [ ] : [ addRemoteEnv ] ) : [ ] ;
194
194
const addCacheFroms = addCacheFrom ? ( Array . isArray ( addCacheFrom ) ? addCacheFrom as string [ ] : [ addCacheFrom ] ) : [ ] ;
195
195
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 ;
197
197
const options : ProvisionOptions = {
198
198
dockerPath,
199
199
dockerComposePath,
@@ -245,7 +245,7 @@ async function provision({
245
245
skipPersistingCustomizationsFromFeatures : false ,
246
246
} ;
247
247
248
- const result = await doProvision ( options , idLabels ) ;
248
+ const result = await doProvision ( options , providedIdLabels ) ;
249
249
const exitCode = result . outcome === 'error' ? 1 : 0 ;
250
250
console . log ( JSON . stringify ( result ) ) ;
251
251
if ( result . outcome === 'success' ) {
@@ -255,13 +255,13 @@ async function provision({
255
255
process . exit ( exitCode ) ;
256
256
}
257
257
258
- async function doProvision ( options : ProvisionOptions , idLabels : string [ ] ) {
258
+ async function doProvision ( options : ProvisionOptions , providedIdLabels : string [ ] | undefined ) {
259
259
const disposables : ( ( ) => Promise < unknown > | undefined ) [ ] = [ ] ;
260
260
const dispose = async ( ) => {
261
261
await Promise . all ( disposables . map ( d => d ( ) ) ) ;
262
262
} ;
263
263
try {
264
- const result = await launch ( options , idLabels , disposables ) ;
264
+ const result = await launch ( options , providedIdLabels , disposables ) ;
265
265
return {
266
266
outcome : 'success' as 'success' ,
267
267
dispose,
@@ -758,8 +758,7 @@ async function doRunUserCommands({
758
758
} ;
759
759
try {
760
760
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 ;
763
762
const addRemoteEnvs = addRemoteEnv ? ( Array . isArray ( addRemoteEnv ) ? addRemoteEnv as string [ ] : [ addRemoteEnv ] ) : [ ] ;
764
763
const configFile = configParam ? URI . file ( path . resolve ( process . cwd ( ) , configParam ) ) : undefined ;
765
764
const overrideConfigFile = overrideConfig ? URI . file ( path . resolve ( process . cwd ( ) , overrideConfig ) ) : undefined ;
@@ -822,7 +821,7 @@ async function doRunUserCommands({
822
821
substitute : value => substitute ( { platform : cliHost . platform , env : cliHost . env } , value )
823
822
} ;
824
823
825
- const container = containerId ? await inspectContainer ( params , containerId ) : await findDevContainer ( params , idLabels ! ) ;
824
+ const { container, idLabels } = await findContainerAndIdLabels ( params , containerId , providedIdLabels , workspaceFolder , configPath ?. fsPath ) ;
826
825
if ( ! container ) {
827
826
bailOut ( common . output , 'Dev container not found.' ) ;
828
827
}
@@ -926,8 +925,7 @@ async function readConfiguration({
926
925
let output : Log | undefined ;
927
926
try {
928
927
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 ;
931
929
const configFile = configParam ? URI . file ( path . resolve ( process . cwd ( ) , configParam ) ) : undefined ;
932
930
const overrideConfigFile = overrideConfig ? URI . file ( path . resolve ( process . cwd ( ) , overrideConfig ) ) : undefined ;
933
931
const cwd = workspaceFolder || process . cwd ( ) ;
@@ -971,7 +969,7 @@ async function readConfiguration({
971
969
env : cliHost . env ,
972
970
output
973
971
} ;
974
- const container = containerId ? await inspectContainer ( params , containerId ) : await findDevContainer ( params , idLabels ! ) ;
972
+ const { container, idLabels } = await findContainerAndIdLabels ( params , containerId , providedIdLabels , workspaceFolder , configPath ?. fsPath ) ;
975
973
if ( container ) {
976
974
configuration = addSubstitution ( configuration , config => beforeContainerSubstitute ( envListToObj ( idLabels ) , config ) ) ;
977
975
configuration = addSubstitution ( configuration , config => containerSubstitute ( cliHost . platform , configuration . config . configFilePath , envListToObj ( container . Config . Env ) , config ) ) ;
@@ -1111,8 +1109,7 @@ export async function doExec({
1111
1109
} ;
1112
1110
try {
1113
1111
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 ;
1116
1113
const addRemoteEnvs = addRemoteEnv ? ( Array . isArray ( addRemoteEnv ) ? addRemoteEnv as string [ ] : [ addRemoteEnv ] ) : [ ] ;
1117
1114
const configFile = configParam ? URI . file ( path . resolve ( process . cwd ( ) , configParam ) ) : undefined ;
1118
1115
const overrideConfigFile = overrideConfig ? URI . file ( path . resolve ( process . cwd ( ) , overrideConfig ) ) : undefined ;
@@ -1171,7 +1168,7 @@ export async function doExec({
1171
1168
substitute : value => substitute ( { platform : cliHost . platform , env : cliHost . env } , value )
1172
1169
} ;
1173
1170
1174
- const container = containerId ? await inspectContainer ( params , containerId ) : await findDevContainer ( params , idLabels ! ) ;
1171
+ const { container, idLabels } = await findContainerAndIdLabels ( params , containerId , providedIdLabels , workspaceFolder , configPath ?. fsPath ) ;
1175
1172
if ( ! container ) {
1176
1173
bailOut ( common . output , 'Dev container not found.' ) ;
1177
1174
}
@@ -1207,7 +1204,3 @@ export async function doExec({
1207
1204
} ;
1208
1205
}
1209
1206
}
1210
-
1211
- function getDefaultIdLabels ( workspaceFolder : string ) {
1212
- return [ `${ hostFolderLabel } =${ workspaceFolder } ` ] ;
1213
- }
0 commit comments