-
Notifications
You must be signed in to change notification settings - Fork 231
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
Share code between features #129
Comments
Or: The It could be nice if the file structure in the tar file was the same as in the source repository, but currently the |
I like this suggestion since I think even in devcontainers/features there are common utilities we could have in a utils.sh file that is sourced in install.sh. Right now I think we'd need to setup a CI job to copy files around given how much code is copied between them right now. FYI on non-root user, #91 is in the CLI and in flight getting released which would allow you to just use a _REMOTE_USER env var. But, there's many other utility functions beyond this one in that repository. |
19 days have passed and I have a new view on that. That's how fast the software world changes ;-) Current setup unintentionally allows a powerful reuse of those scripts we have, for example: Of course there are a bunch of such install scripts, but generally speaking those that are used for devcontainers are well tested due to ease of testing in different environments. |
+1 to this. Below is just some spitballing, but an idea i've been tossing around is the concept of library Features. They cannot be referenced directly in a devcontainer.json, but rather a Feature will declare that it depends on a library. {
"id": "ruby":,
"version": "1.2.3",
"libraries": [
"ghcr.io/devcontainers/features/lib:1"
]
} The CLI would then automatically fetch For the devcontainers maintainers team, we would publish and maintain a |
The issue with this approach is that you're loading an unversioned script file in a versioned feature. I think a way you can counter this is by pinning the version using a commit hash, but that also makes it a hassle for maintainers. |
I really like this idea and I'm currently experimenting with this using the The issue I'm currently facing is the exact same one I mentioned in my other comment: how do we make sure we allow different library versions to coexist without breaking stuff ? I've come up with the following way to avoid this problem :
That way you can simply depend on a major version but if you need to depend on a specific minor one then the different minor versions won't interfere with eachother (i.e if they used the same folder, they could overwrite eachother). The issue I currently have though is that the library feature should know it's own version from within the EDIT: So whilst the environment variables available in the environment don't tell you what version is currently being installed, the VERSION=$(jq -r ".version" devcontainer-feature.json) It's a bit hacky and does require an external dependency (i need |
Motivation
While devcontainers features aim to enable modern software development, the feature code itself is stuck in a lot of code duplication.
For example we can find
# Determine the appropriate non-root user
17 times within the features repo. It's the same for me for detecting python version etc etc.One of the main principles in software development is DRY: Don't Repeat Yourself. That is currently not possible for features!
Proposal
Variant: generic pre-build
Add support for pre-build.sh (in src/_pre_build.sh, src/_pre_build/pre_build.sh, src/_special_cli_stuff/pre_build.sh) which would be executed upon build and feature test calls with an appropriate set of parameters. This way the script can do arbitrary things like copy common code. But it could do even more like downloading common code from yet another source. It could merge code into single files. etc.
Variant: common code
Add support for src/_common which could contain code that is used throughout my features. Build and feature test calls will package that code as well as the install.sh script of the feature. Within install.sh one can simply source/call anything from _common as it's part of the package.
P.S. I wasn't sure whether to put this to cli or spec, please move if incorrect.
The text was updated successfully, but these errors were encountered: