-
Notifications
You must be signed in to change notification settings - Fork 341
[proposal] Sharing code between Dev Container Features #209
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1dcea4c
include property
joshspicer 6ba5282
Update features-library.md
joshspicer 073b3b0
Apply suggestions from code review
joshspicer 9dec55f
clarify
joshspicer 0249dc3
update proposal to mirror repo structure
joshspicer 5b490bd
clean up proposal
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 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,76 @@ | ||
# Sharing code between Dev Container Features | ||
|
||
ref: https://github.com/devcontainers/spec/issues/129 | ||
|
||
# Motivation | ||
|
||
The current model for authoring Features encourages significant copy and paste between individual Features. Most of the Features published under the `devcontainers/features` namespace contain approximately 100 lines of [identifical helper functions](https://github.com/devcontainers/features/blob/main/src/azure-cli/install.sh#L29-L164) before the first line of the script is executed. The process of maintaining these helper functions is tedious, error-prone, and leads to less readable Features. | ||
|
||
Additionally, [members of the Feature authoring community have expressed interest in sharing code between Features](https://github.com/orgs/devcontainers/discussions/10). Exploring the source code of self-published Features, it is evident that many authors have copy/pasted code from other Features. This is a sign that there is a need for a more efficient way to share code between Features. | ||
|
||
# Goal | ||
|
||
Provide a generic and efficient way to share code between Features. | ||
|
||
# Proposal | ||
|
||
Add an `include` property to the `devcontainer-feature.json`. This will be honored during the Feature [packaging stage](https://containers.dev/implementors/features-distribution/#packaging). The contents of the provided relative path is copied into the packaged Feature archive. | ||
|
||
Property | Type | Description | ||
--- | --- | --- | ||
`include` | `string[]` | An array of relative paths to package with the Feature. Paths are relative to root directory when packaging (often the git root directory). If the element is a folder, it is copied recursively. | ||
joshspicer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Example | ||
|
||
```json | ||
{ | ||
"name": "my-feature", | ||
"version": "0.0.1", | ||
"include": [ | ||
"utils/", | ||
] | ||
} | ||
``` | ||
|
||
The preceeding example will recursively copy the contents of the the `utils` folder into the temporary folder used to package the Feature. The `utils` folder will be included with the published Features. | ||
joshspicer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
This functionality will enable sharing a common set of helper functions between Features. The following example shows how a Feature could include a `utils` folder that contains a `common.sh` file. | ||
|
||
```bash | ||
# utils/common.sh | ||
function common_function() { | ||
echo "Hello, '$1'" | ||
} | ||
``` | ||
|
||
```bash | ||
# my-feature/install.sh | ||
|
||
# Include common functions | ||
source "./utils/common.sh" | ||
joshspicer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# Use common function | ||
common_function "devcontainers" | ||
``` | ||
|
||
----- | ||
|
||
# Possible Extensions | ||
|
||
This section provides hints to possible future work that could extend the proposal above. These are not part of the proposal, but are provided to help the community understand the potential future impact of this proposal. | ||
|
||
## Distributing shared library Features | ||
|
||
In an effort to reduce the need for authors to copy/paste auxillary scripts between Feature namespaces, provide the ability to publish "library" Features. These Features would be published [following the Feature distribution spec](https://containers.dev/implementors/features-distribution/#distribution) under a new manifest type. | ||
|
||
A "library" can be included in a Feature's `include` property as an alterative to a relative path. By themselves, a "library" Feature would not be installable. | ||
joshspicer marked this conversation as resolved.
Show resolved
Hide resolved
joshspicer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```json | ||
|
||
{ | ||
"name": "my-feature", | ||
"version": "0.0.1", | ||
"include": [ | ||
"ghcr.io/devcontainers/features/utils:0.0.1" | ||
] | ||
} |
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.