Skip to content

Commit

Permalink
feat: ✨ Support ${remoteUser} in feature definitions
Browse files Browse the repository at this point in the history
This change allows using `${remoteUser}` inside of devcontainer-feature.json similar to the exising ${devcontainerId}.
  • Loading branch information
max06 committed Jul 25, 2023
1 parent a74814e commit a56419c
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/spec-common/variableSubstitution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface SubstitutionContext {
localWorkspaceFolder?: string;
containerWorkspaceFolder?: string;
env: NodeJS.ProcessEnv;
remoteUser?: string;
}

export function substitute<T extends object>(context: SubstitutionContext, value: T): T {
Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions src/spec-node/configContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "Demo container",
"image": "mcr.microsoft.com/devcontainers/base:bullseye",
"features": {
"./test-feature": {}
},
"remoteUser": "vscode"
}
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

echo "I am the install script and I do nothing."

0 comments on commit a56419c

Please sign in to comment.