Skip to content
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
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

joshspicer
Copy link
Member

@joshspicer joshspicer commented Feb 28, 2023

The goal of this proposal is to:

  • Consolidate merged lifecycle hook and devcontainer.json schema
  • Keep track of the 'origin' of contributions to the merged config for purposes such as logging.

@joshspicer joshspicer changed the title Joshspicer/consolidate merged lifecycle hook schema Consolidate date merged lifecycle hook and devcontainer.json schema Feb 28, 2023
@joshspicer joshspicer changed the title Consolidate date merged lifecycle hook and devcontainer.json schema Consolidate merged lifecycle hook and devcontainer.json schema Feb 28, 2023
@joshspicer joshspicer marked this pull request as ready for review February 28, 2023 22:17
@joshspicer joshspicer requested a review from a team as a code owner February 28, 2023 22:17
Copy link
Contributor

@chrmarti chrmarti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally:

  • customizations is a map of objects in the devcontainer.json and a map of object arrays in the merged config.
  • entrypoints is not in the devcontainer.json, but is an array of strings in the merged config.

How would we represent the origins of the lifecycle commands, so we can log them?

@joshspicer joshspicer changed the title Consolidate merged lifecycle hook and devcontainer.json schema [proposal] Consolidate merged lifecycle hook and devcontainer.json schema Mar 3, 2023
@joshspicer joshspicer changed the title [proposal] Consolidate merged lifecycle hook and devcontainer.json schema [proposal] Update the devcontainer.json schema to be able to represent a 'mergedConfiguration' Mar 3, 2023
@joshspicer joshspicer marked this pull request as draft March 3, 2023 21:27
@joshspicer joshspicer marked this pull request as ready for review March 13, 2023 16:59
joshspicer and others added 3 commits March 16, 2023 21:58
Co-authored-by: Brigit Murtaugh <brigit.murtaugh@microsoft.com>
@joshspicer
Copy link
Member Author

📢 Open questions

<NONE>

proposals/consolidate-merged-lifecycle-hook-schema.md Outdated Show resolved Hide resolved
proposals/consolidate-merged-lifecycle-hook-schema.md Outdated Show resolved Hide resolved
}
```

An optional parameter `$origin` is added to the `LifecycleCommandParallel` that supporting tools can use to indicate the source of the command. For example, this is useful for outputting in the creation log which Feature provided a certain lifecycle hook. The `$` notation is used to indicate this property is additional tooling metadata that should not be present in a user `devcontainer.json`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would $origin be the qualified feature id with the version OR devcontainer.json?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we have Feature dependencies and may have more than one Feature contributing configuration, we should use the "canonical ID" (for OCI Features, expanded with the SHA hash).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although i'm going back and forth here. At the end of the day, the intention I have for $origin is to make it easier to understand from the logs what is happening. It may be more intuitive to print verbatim what is in the devcontainer.json.

proposals/consolidate-merged-lifecycle-hook-schema.md Outdated Show resolved Hide resolved
In the below example, the `entrypoint` property is contributed from two different sources. The merged `$entrypoints` property would be an array of two strings, one for each entrypoint.

```json
"$entrypoints": [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we ok with users including this in their devcontainer.json? I guess we might see this if we don't add a regular entrypoint property.

We don't have the $origin here which would make sense for consistency.

Copy link
Member Author

@joshspicer joshspicer Jun 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is ok. I don't think we'll necessarily do anything with this value if it's in a devcontainer.json as input, right? The source of truth is still in the image label - this section of the spec is as a standardized output for read-configuration. I imagine all the $ are ignored during a build and used by humans/loggers.

@avidal
Copy link

avidal commented Jun 27, 2023

Is there still an appetite for this? In our SDK/CLI I'm tempted to implement something similar to help wrangle types (ours is written in Go, so I unfortunately can't leverage such rich types to keep everything in one place).

Something that would help additionally would be some test cases for how to merge configuration that implementing tools can run against, but that's a matter for another time I think.

@joshspicer
Copy link
Member Author

Thanks for the nudge @avidal, this is definitely something I still want us to move forward with. I'll give this spec's comments another pass right now

}
```

An optional parameter `$origin` is added to the `LifecycleCommandParallel` that supporting tools can use to indicate the source of the command. For example, this is useful for outputting in the creation log which Feature provided a certain lifecycle hook. The `$` notation is used to indicate this property is additional tooling metadata that should not be present in a user `devcontainer.json`.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the $origin of a bit of config that comes from the devcontainer.metadata image label (assuming it doesn't carry one already)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a section of metadata in devcontainer.metadata doesn't already have an $origin, we wouldn't anything. It had to come from somewhere (either a base dev container that defined the image, a Feature, or the user's current dev container). If omitted, we don't have any insight into where it came from and we'd need to log something generically in those cases.

```typescript
{
// ...other devcontainer.json properties...
onCreateCommand?: LifecycleCommand | LifecycleCommandParallel | LifecycleCommandParallel[]
Copy link

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:

{"onCreateCommand": [{
  "foo": "script/foo",
  "$origin": "foo"
}, {
  "foo": ["date > /tmp/last-ran"]
}]

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)?

Copy link

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 that devcontainer-feature.json has a distinct json schema.

Copy link
Member Author

@joshspicer joshspicer Jun 28, 2023

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 a devcontainer.json but distinct. The goal of the $ properties as members of the devcontainer.json is so that a command such as devcontainer read-configuration can output a json object that is also a devcontainer.json. That's not the case today without these changes.

Copy link

@avidal avidal Nov 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goal of the $ properties as members of the devcontainer.json is so that a command such as devcontainer read-configuration can output a json object that is also a devcontainer.json. That's not the case today without these changes.

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 of read-configuration is not actually a devcontainer.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 existing devcontainer.json and devcontainer-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 either devcontainer.json or devcontainer-feature.json into Config or FeatureConfig respectively, plus a Metadata entry. I parse the image label into a MergedMetadata 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.

@joshspicer joshspicer requested a review from chrmarti June 28, 2023 23:27
@avidal
Copy link

avidal commented Nov 3, 2023

Another couple of questions, since this is still in review: this proposal adds an $origin for lifecycle commands when they are merged, as well as $entrypoints to collect entrypoints from features. What about other properties that are merged, such as mounts or securityOpt? What about last-value such as containerUser or the specific semantics of init and privileged?

Do we think it's just not important to be able to report on the origin of those properties? Whereas lifecycle commands can use the origin for output logging?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants