-
Notifications
You must be signed in to change notification settings - Fork 461
Add support for the extends keyword
#1306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Sam Frost (SamuelFrost)
wants to merge
5
commits into
devcontainers:main
Choose a base branch
from
SamuelFrost:extends
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2585113
Add support for the extends keyword
SamuelFrost 7c7d1ca
Add extendsMergeMode for combine vs override extends merging
SamuelFrost ff4be89
Add extends and extendsMergeMode integration tests
SamuelFrost c4e9697
Use spread semantics for extendsMergeMode override
SamuelFrost 6302f11
Refine extends tests with fixtures and unit merge coverage.
SamuelFrost File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
SamuelFrost marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All rights reserved. | ||
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| import * as path from 'path'; | ||
| import { assert } from 'chai'; | ||
| import { URI } from 'vscode-uri'; | ||
| import { getCLIHost, loadNativeModule } from '../spec-common/commonUtils'; | ||
| import { DevContainerFromImageConfig } from '../spec-configuration/configuration'; | ||
| import { readDevContainerConfigFile } from '../spec-node/configContainer'; | ||
| import { Workspace } from '../spec-utils/workspaces'; | ||
| import { nullLog } from '../spec-utils/log'; | ||
|
|
||
| const workspace: Workspace = { | ||
| isWorkspaceFile: false, | ||
| workspaceOrFolderPath: '/foo/bar', | ||
| rootFolderPath: '/foo/bar', | ||
| configFolderPath: '/foo/bar', | ||
| }; | ||
|
|
||
| async function readConfig(relativePath: string) { | ||
| const cliHost = await getCLIHost(process.cwd(), loadNativeModule, false); | ||
| const configFile = URI.file(path.resolve(relativePath)); | ||
| return readDevContainerConfigFile(cliHost, workspace, configFile, false, false, nullLog); | ||
| } | ||
|
|
||
| async function expectReadConfigError(relativePath: string, pattern: RegExp) { | ||
| try { | ||
| await readConfig(relativePath); | ||
| assert.fail('expected read to throw'); | ||
| } catch (err: any) { | ||
| assert.match(String(err.description || err.message), pattern); | ||
| } | ||
| } | ||
|
|
||
| describe('readDevContainerConfigFile', function () { | ||
| it('can read a basic configuration file', async function () { | ||
| const configs = await readConfig('./src/test/configs/example/.devcontainer.json'); | ||
| assert.isOk(configs); | ||
| assert.property(configs, 'config'); | ||
| assert.isOk(configs?.config.config); | ||
|
|
||
| const features = configs?.config.config.features as Record<string, string | boolean | Record<string, string | boolean>>; | ||
| assert.hasAllKeys(features, ['ghcr.io/devcontainers/features/github-cli:1']); | ||
| }); | ||
|
|
||
| it('can resolve an "extends" file reference', async function () { | ||
| const configs = await readConfig('./src/test/configs/extends/.devcontainer.json'); | ||
| assert.isOk(configs); | ||
| const raw = configs?.config.raw as DevContainerFromImageConfig; | ||
| assert.strictEqual(raw.name, 'Overrides'); | ||
| assert.strictEqual(raw.image, 'ubuntu:latest'); | ||
| assert.deepEqual(raw.forwardPorts, [80, 443]); | ||
| assert.deepEqual(raw.capAdd, ['SYS_PTRACE', 'NET_ADMIN']); | ||
| assert.strictEqual(raw.hostRequirements?.cpus, 2); | ||
| assert.strictEqual(raw.hostRequirements?.memory, `${8 * 2 ** 30}`); | ||
| assert.deepEqual(raw.remoteEnv, { FROM_BASE: 'base', OVERRIDE_ME: 'child' }); | ||
| assert.notProperty(raw, 'extends'); | ||
| assert.notProperty(raw, 'extendsMergeMode'); | ||
| }); | ||
|
|
||
| it('can resolve nested "extends" file references', async function () { | ||
| const configs = await readConfig('./src/test/configs/extends/.devcontainer.nested.json'); | ||
| assert.isOk(configs); | ||
| assert.strictEqual(configs?.config.raw.name, 'Nested'); | ||
| assert.deepEqual(configs?.config.raw.forwardPorts, [80, 443, 2222]); | ||
| assert.strictEqual((configs?.config.raw as DevContainerFromImageConfig).image, 'ubuntu:latest'); | ||
| }); | ||
|
|
||
| it('rejects a cyclic "extends" reference', async function () { | ||
| await expectReadConfigError('./src/test/configs/extends/.devcontainer.cycle-a.json', /cyclic "extends" reference/); | ||
| }); | ||
|
|
||
| it('can resolve "extends" with extendsMergeMode override', async function () { | ||
| const configs = await readConfig('./src/test/configs/extends/.devcontainer.override.json'); | ||
| assert.isOk(configs); | ||
| const raw = configs?.config.raw as DevContainerFromImageConfig; | ||
| assert.strictEqual(raw.name, 'Override merge'); | ||
| assert.strictEqual(raw.image, 'ubuntu:latest'); | ||
| assert.deepEqual(raw.forwardPorts, [443]); | ||
| assert.strictEqual(raw.init, false); | ||
| assert.deepEqual(raw.remoteEnv, { OVERRIDE_ME: 'child' }); | ||
| assert.deepEqual(raw.hostRequirements, { memory: '4gb' }); | ||
| assert.notProperty(raw, 'extends'); | ||
| assert.notProperty(raw, 'extendsMergeMode'); | ||
| }); | ||
|
|
||
| it('rejects an invalid "extendsMergeMode" value', async function () { | ||
| await expectReadConfigError('./src/test/configs/extends/.devcontainer.invalid-merge.json', /extendsMergeMode.*combine.*override/); | ||
| }); | ||
|
|
||
| it('rejects a missing "extends" file', async function () { | ||
| await expectReadConfigError('./src/test/configs/extends/.devcontainer.missing.json', /was not found/); | ||
| }); | ||
| }); |
|
SamuelFrost marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| { | ||
| "image": "ubuntu:latest", | ||
| "forwardPorts": [80], | ||
| "capAdd": ["SYS_PTRACE"], | ||
| "hostRequirements": { | ||
| "cpus": 2, | ||
| "memory": "8gb" | ||
| }, | ||
| "remoteEnv": { | ||
| "FROM_BASE": "base", | ||
| "OVERRIDE_ME": "base" | ||
| } | ||
| } |
|
SamuelFrost marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "extends": "./.devcontainer.cycle-b.json", | ||
| "image": "mcr.microsoft.com/devcontainers/base:latest" | ||
| } |
|
SamuelFrost marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "extends": "./.devcontainer.cycle-a.json", | ||
| "name": "cycle" | ||
| } |
|
SamuelFrost marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "extends": "./.devcontainer.base.json", | ||
| "extendsMergeMode": "deepmerge" | ||
| } |
|
SamuelFrost marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| "extends": "./.devcontainer.base.json", | ||
| "name": "Overrides", | ||
| "forwardPorts": [443], | ||
| "capAdd": ["NET_ADMIN"], | ||
| "hostRequirements": { | ||
| "memory": "4gb" | ||
| }, | ||
| "remoteEnv": { | ||
| "OVERRIDE_ME": "child" | ||
| } | ||
| } |
|
SamuelFrost marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "extends": "./does-not-exist.json", | ||
| "image": "mcr.microsoft.com/devcontainers/base:latest" | ||
| } |
|
SamuelFrost marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "extends": "./.devcontainer.json", | ||
| "name": "Nested", | ||
| "forwardPorts": [2222] | ||
| } |
|
SamuelFrost marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| { | ||
| "extends": "./.devcontainer.base.json", | ||
| "extendsMergeMode": "override", | ||
| "name": "Override merge", | ||
| "forwardPorts": [443], | ||
| "hostRequirements": { | ||
| "memory": "4gb" | ||
| }, | ||
| "remoteEnv": { | ||
| "OVERRIDE_ME": "child" | ||
| }, | ||
| "init": false | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.