Skip to content

Commit a56419c

Browse files
committed
feat: ✨ Support ${remoteUser} in feature definitions
This change allows using `${remoteUser}` inside of devcontainer-feature.json similar to the exising ${devcontainerId}.
1 parent a74814e commit a56419c

File tree

5 files changed

+30
-0
lines changed

5 files changed

+30
-0
lines changed

src/spec-common/variableSubstitution.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface SubstitutionContext {
1515
localWorkspaceFolder?: string;
1616
containerWorkspaceFolder?: string;
1717
env: NodeJS.ProcessEnv;
18+
remoteUser?: string;
1819
}
1920

2021
export function substitute<T extends object>(context: SubstitutionContext, value: T): T {
@@ -109,6 +110,9 @@ function replaceWithContext(isWindows: boolean, context: SubstitutionContext, ma
109110
case 'containerWorkspaceFolderBasename':
110111
return context.containerWorkspaceFolder !== undefined ? path.posix.basename(context.containerWorkspaceFolder) : match;
111112

113+
case 'remoteUser':
114+
return context.remoteUser !== undefined ? context.remoteUser : match;
115+
112116
default:
113117
return match;
114118
}

src/spec-node/configContainer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ export async function readDevContainerConfigFile(cliHost: CLIHost, workspace: Wo
9797
containerWorkspaceFolder: workspaceConfig.workspaceFolder,
9898
configFile,
9999
env: cliHost.env,
100+
remoteUser: updated.remoteUser
100101
}, value);
101102
const config: DevContainerConfig = substitute0(updated);
102103
if (typeof config.workspaceFolder === 'string') {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "Demo container",
3+
"image": "mcr.microsoft.com/devcontainers/base:bullseye",
4+
"features": {
5+
"./test-feature": {}
6+
},
7+
"remoteUser": "vscode"
8+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/devcontainers/spec/main/schemas/devContainerFeature.schema.json",
3+
"id": "test-feature",
4+
"name": "test-feature",
5+
"version": "0.0.1",
6+
"description": "Testing a feature",
7+
"mounts": [
8+
{
9+
"source": "test-${devcontainerId}",
10+
"target": "/home/${remoteUser}",
11+
"type": "volume"
12+
}
13+
]
14+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
echo "I am the install script and I do nothing."

0 commit comments

Comments
 (0)