-
Notifications
You must be signed in to change notification settings - Fork 243
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
[proposal] Update the devcontainer.json
schema to be able to represent a 'mergedConfiguration'
#206
Open
joshspicer
wants to merge
12
commits into
main
Choose a base branch
from
joshspicer/consolidate-merged-lifecycle-hook-schema
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 4 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c1224a4
goal of consolidate-merged-lifecycle-hook-schema
joshspicer 3a3e262
init consolidate-merged-lifecycle-hook-schema
joshspicer 4ab251e
proposal
joshspicer 9e26125
Update consolidate-merged-lifecycle-hook-schema.md
joshspicer 3a62b33
cover all properties
joshspicer a778863
indent;
joshspicer aa048eb
proofreading
joshspicer 465381d
customizations array variant
joshspicer 56b107c
Apply suggestions from code review
joshspicer 1dc72c9
italics
joshspicer 452b918
code review edits
joshspicer b19219f
clarify $entrypoints
joshspicer 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 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,34 @@ | ||
# Goal | ||
|
||
Expand the lifecycle hook `devcontainer.json` schema to make it possible to represent a merged configuration within a `devcontainer.json`. This will allow a configuration comprised of lifecycle hooks comprised of [Feature contributed lifecycle scripts](./features-contribute-lifecycle-scripts.md) or otherwise merged onto the image to not need a separate 'mergedConfiguration' schema to represent the config. | ||
|
||
## Motivation | ||
|
||
As seen below, the current generated 'mergedConfiguration' returned by the `read-configuration` CLI command does not return a `devcontainer.json` as outlined in this repo's specification, but rather an array of hooks. [(source)](https://github.com/devcontainers/cli/pull/390#issuecomment-1430190326) | ||
|
||
![img-1](https://user-images.githubusercontent.com/23246594/218825633-cf037d97-db05-4d0d-9157-66287cd47073.png) | ||
|
||
## Proposal | ||
|
||
Update the schema of lifecycle hooks to mirror the merged configuration illustrated above. | ||
|
||
Propose to change the interface to: | ||
|
||
```typescript | ||
|
||
export type LifecycleCommand = string | string[] | ||
export type LifecycleCommandParallel = { [key: string]: LifecycleCommand }; | ||
|
||
interface DevContainerConfig { | ||
// ...other devcontainer.json properties... | ||
onCreateCommand?: LifecycleCommand | LifecycleCommandParallel | LifecycleCommandParallel[] | ||
updateContentCommand?: LifecycleCommand | LifecycleCommandParallel | LifecycleCommandParallel[] | ||
postCreateCommand?: LifecycleCommand | LifecycleCommandParallel | LifecycleCommandParallel[] | ||
postStartCommand?: LifecycleCommand | LifecycleCommandParallel | LifecycleCommandParallel[] | ||
postAttachCommand?: LifecycleCommand | LifecycleCommandParallel | LifecycleCommandParallel[] | ||
} | ||
``` | ||
|
||
The new addition is the final unioned value `LifecycleCommandParallel[]`. Every existing lifecycle command and merged command can be represented within that type. | ||
|
||
Using this property, the 'mergedConfiguration' returned by `read-configuration` can directly return a `devcontainer.json` without needing non-spec properties (ie: plural `postCreateCommands`). |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that this means that a
devcontainer-feature.json
could specify something like:Should it be considered an error if a
devcontainer-feature.json
specifies a list of objects? Should tools ignore an$origin
property when reading from a json file directly (versus from image metadata)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, this change specifically affects the schema for
devcontainer.json
, I see. I hadn't realized thatdevcontainer-feature.json
has a distinct json schema.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I don't think we'd want to update the
devcontainer-feature.json
schema, which is very close to adevcontainer.json
but distinct. The goal of the$
properties as members of thedevcontainer.json
is so that a command such asdevcontainer read-configuration
can output a json object that is also a devcontainer.json. That's not the case today without these changes.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been thinking more about this, and I'm not sure that's a good thing to have in the spec itself...it seems like an implementation detail for the specific tool in question. The way some of the other comments read indicates that it'd be "valid" in a
devcontainer.json
but not actually used (re: a comment above about$entrypoints
)...which kind of implies that the output ofread-configuration
is not actually adevcontainer.json
.That is, it seems like a "proper" implementation would use this schema to encode/decode metadata stored in the image label, and use it internally as the result of merging all of the various metadata sources, but it's not actually valid
devcontainer.json
config. Effectively splitting out merged metadata into a separate schema and leaving the existingdevcontainer.json
anddevcontainer-feature.json
alone.The way I've been thinking about it lately is that a
*.json
contains two sets of data: config and metadata. I parse eitherdevcontainer.json
ordevcontainer-feature.json
intoConfig
orFeatureConfig
respectively, plus aMetadata
entry. I parse the image label into aMergedMetadata
entry. Internally I store the config and the merged metadata to drive the build process. I use the merged metadata to render into an image label. I print the config and merged metadata during debug output as two separate entities.edit: The main reason I'm bringing this up is because it seems to me that this change may require significant explanation in the docs to reduce confusion for implementors vs declaring it as a distinct schema and indicating that it represents the results of the "merge logic table" and should be used as the entry for the
devcontainer.metadata
image label.