From a56419c3191644763bb1bfde761954a1245db6f1 Mon Sep 17 00:00:00 2001 From: max06 Date: Tue, 25 Jul 2023 21:52:09 +0000 Subject: [PATCH] feat: :sparkles: Support ${remoteUser} in feature definitions This change allows using `${remoteUser}` inside of devcontainer-feature.json similar to the exising ${devcontainerId}. --- src/spec-common/variableSubstitution.ts | 4 ++++ src/spec-node/configContainer.ts | 1 + .../.devcontainer/devcontainer.json | 8 ++++++++ .../test-feature/devcontainer-feature.json | 14 ++++++++++++++ .../.devcontainer/test-feature/install.sh | 3 +++ 5 files changed, 30 insertions(+) create mode 100644 src/test/configs/image-with-local-feature/.devcontainer/devcontainer.json create mode 100644 src/test/configs/image-with-local-feature/.devcontainer/test-feature/devcontainer-feature.json create mode 100644 src/test/configs/image-with-local-feature/.devcontainer/test-feature/install.sh diff --git a/src/spec-common/variableSubstitution.ts b/src/spec-common/variableSubstitution.ts index d973f0cd6..accdff3bb 100644 --- a/src/spec-common/variableSubstitution.ts +++ b/src/spec-common/variableSubstitution.ts @@ -15,6 +15,7 @@ export interface SubstitutionContext { localWorkspaceFolder?: string; containerWorkspaceFolder?: string; env: NodeJS.ProcessEnv; + remoteUser?: string; } export function substitute(context: SubstitutionContext, value: T): T { @@ -109,6 +110,9 @@ function replaceWithContext(isWindows: boolean, context: SubstitutionContext, ma case 'containerWorkspaceFolderBasename': return context.containerWorkspaceFolder !== undefined ? path.posix.basename(context.containerWorkspaceFolder) : match; + case 'remoteUser': + return context.remoteUser !== undefined ? context.remoteUser : match; + default: return match; } diff --git a/src/spec-node/configContainer.ts b/src/spec-node/configContainer.ts index dddd08d58..ecffa5c87 100644 --- a/src/spec-node/configContainer.ts +++ b/src/spec-node/configContainer.ts @@ -97,6 +97,7 @@ export async function readDevContainerConfigFile(cliHost: CLIHost, workspace: Wo containerWorkspaceFolder: workspaceConfig.workspaceFolder, configFile, env: cliHost.env, + remoteUser: updated.remoteUser }, value); const config: DevContainerConfig = substitute0(updated); if (typeof config.workspaceFolder === 'string') { diff --git a/src/test/configs/image-with-local-feature/.devcontainer/devcontainer.json b/src/test/configs/image-with-local-feature/.devcontainer/devcontainer.json new file mode 100644 index 000000000..0749ce284 --- /dev/null +++ b/src/test/configs/image-with-local-feature/.devcontainer/devcontainer.json @@ -0,0 +1,8 @@ +{ + "name": "Demo container", + "image": "mcr.microsoft.com/devcontainers/base:bullseye", + "features": { + "./test-feature": {} + }, + "remoteUser": "vscode" +} \ No newline at end of file diff --git a/src/test/configs/image-with-local-feature/.devcontainer/test-feature/devcontainer-feature.json b/src/test/configs/image-with-local-feature/.devcontainer/test-feature/devcontainer-feature.json new file mode 100644 index 000000000..f2da6e155 --- /dev/null +++ b/src/test/configs/image-with-local-feature/.devcontainer/test-feature/devcontainer-feature.json @@ -0,0 +1,14 @@ +{ + "$schema": "https://raw.githubusercontent.com/devcontainers/spec/main/schemas/devContainerFeature.schema.json", + "id": "test-feature", + "name": "test-feature", + "version": "0.0.1", + "description": "Testing a feature", + "mounts": [ + { + "source": "test-${devcontainerId}", + "target": "/home/${remoteUser}", + "type": "volume" + } + ] +} \ No newline at end of file diff --git a/src/test/configs/image-with-local-feature/.devcontainer/test-feature/install.sh b/src/test/configs/image-with-local-feature/.devcontainer/test-feature/install.sh new file mode 100644 index 000000000..41cde2f90 --- /dev/null +++ b/src/test/configs/image-with-local-feature/.devcontainer/test-feature/install.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +echo "I am the install script and I do nothing." \ No newline at end of file