Skip to content

Commit c35883b

Browse files
committed
Caching user home location before every feature is installed
1 parent c1c8b08 commit c35883b

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/spec-configuration/containerFeaturesConfiguration.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -293,15 +293,21 @@ export function getFeatureLayers(featuresConfig: FeaturesConfig, containerUser:
293293

294294
const useSELinuxLabel = process.platform === 'linux' && isBuildah;
295295
const builtinsEnvFile = `${path.posix.join(FEATURES_CONTAINER_TEMP_DEST_FOLDER, 'devcontainer-features.builtin.env')}`;
296-
let result = `RUN \\
296+
const tempUserHome = `RUN \\
297297
echo "_CONTAINER_USER_HOME=$(${getEntPasswdShellCommand(containerUser)} | cut -d: -f6)" >> ${builtinsEnvFile} && \\
298298
echo "_REMOTE_USER_HOME=$(${getEntPasswdShellCommand(remoteUser)} | cut -d: -f6)" >> ${builtinsEnvFile}
299299
300300
`;
301301

302+
// placeholder empty string to concatenate the feature layers
303+
let result = '';
304+
302305
// Features version 1
303306
const folders = (featuresConfig.featureSets || []).filter(y => y.internalVersion !== '2').map(x => x.features[0].consecutiveId);
304307
folders.forEach(folder => {
308+
// calculate container user home and remote user home before feature installation
309+
result += tempUserHome;
310+
305311
const source = path.posix.join(contentSourceRootPath, folder!);
306312
const dest = path.posix.join(FEATURES_CONTAINER_TEMP_DEST_FOLDER, folder!);
307313
if (!useBuildKitBuildContexts) {
@@ -327,6 +333,9 @@ RUN chmod -R 0755 ${dest} \\
327333
// Features version 2
328334
featuresConfig.featureSets.filter(y => y.internalVersion === '2').forEach(featureSet => {
329335
featureSet.features.forEach(feature => {
336+
// recalculate container user home and remote user home if feature modifies it
337+
result += tempUserHome;
338+
330339
result += generateContainerEnvs(feature.containerEnv);
331340
const source = path.posix.join(contentSourceRootPath, feature.consecutiveId!);
332341
const dest = path.posix.join(FEATURES_CONTAINER_TEMP_DEST_FOLDER, feature.consecutiveId!);

src/test/container-features/generateFeaturesConfig.test.ts

+4
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ RUN chmod -R 0755 /tmp/dev-container-features/color_0 \\
7676
&& chmod +x ./devcontainer-features-install.sh \\
7777
&& ./devcontainer-features-install.sh
7878
79+
RUN \\
80+
echo "_CONTAINER_USER_HOME=$(${getEntPasswdShellCommand('testContainerUser')} | cut -d: -f6)" >> /tmp/dev-container-features/devcontainer-features.builtin.env && \\
81+
echo "_REMOTE_USER_HOME=$(${getEntPasswdShellCommand('testRemoteUser')} | cut -d: -f6)" >> /tmp/dev-container-features/devcontainer-features.builtin.env
82+
7983
8084
COPY --chown=root:root --from=dev_containers_feature_content_source /tmp/build-features/hello_1 /tmp/dev-container-features/hello_1
8185
RUN chmod -R 0755 /tmp/dev-container-features/hello_1 \\

0 commit comments

Comments
 (0)