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

How to reference a devcontainer-template / create a hierarchy of templates in a repo? #26

Open
meastp opened this issue Aug 16, 2023 · 2 comments

Comments

@meastp
Copy link

meastp commented Aug 16, 2023

Hi,

I'm trying to get started with devcontainers but I can not use the cpp devcontainer image because its base image (base-ubuntu in my case) does not support a recent enough version for me (I need a recent version of gcc, currently only available in ubuntu lunar).

So, I tried authoring both a custom base-ubuntu and a custom cpp template. I'm struggling with using base-ubuntu as the base of my cpp template. I must be missing something. Does the devcontainer template package in ghcr.io need to be built to a docker image and hosted elsewhere?

The whole point of doing this in two templates is that cpp depend on some of the decontainer features being available from base-ubuntu (git, common).

Here is my repo and the most recent pull request smoke test, with trace output for devcontainer cli's up command: https://github.com/meastp/devcontainer-templates/actions/runs/5878222841/job/15939860188?pr=5

I suspect the problem is that I'm trying to reference the base-ubuntu image in src/cpp/Dockerfile:

FROM ghcr.io/meastp/devcontainer-templates/base-ubuntu:latest

I'm not sure how to solve this, if it should be supported or if I need to build the image out of band?

@samruddhikhandale
Copy link
Member

Hi 👋

So, I tried authoring both a custom base-ubuntu and a custom cpp template. I'm struggling with using base-ubuntu as the base of my cpp template.

Looks like you are trying to create two Templates (ubuntu and cpp) and extend cpp from the ubuntu Template? Unfortunately, the spec currently does not support building a Template on top of another one. All the templates are isolated and are built on top of an image rather than a Template.

In your case, can you create a new ubuntu Docker image and push it to a registry of your choice? Then, you'd be able to reference it in your cpp Template. Let me know if that makes sense, thanks!

Another alternative, create the cpp template whose Dockerfile would also contain the ubuntu contents (ie. which you would ideally put in your ubuntu Template or the contents used to build that image). However, I think the first approach is a bit cleaner.

@meastp
Copy link
Author

meastp commented Aug 16, 2023

Another alternative, create the cpp template whose Dockerfile would also contain the ubuntu contents (ie. which you would ideally put in your ubuntu Template or the contents used to build that image). However, I think the first approach is a bit cleaner.

This won't work, because the cpp template (content/script in Dockerfile) depends on some devcontainer features being installed. It does look like devcontainer features are added after the content of the Dockerfile is executed, that's why this needs to be in two images/templates/..

In your case, can you create a new ubuntu Docker image and push it to a registry of your choice? Then, you'd be able to reference it in your cpp Template. Let me know if that makes sense, thanks!

This does make sense, but I'm not sure how to do it. Is it possible to create a github action on the template repository to generate and push docker image(s) for base-ubuntu as well? If it is, could you please explain how? Using the devcontainer ci somehow? devcontainer-ci build command? How does this work with template parameters?
I feel there is some documentation around this missing (or I haven't been able to find it).

Thank you for helping with this! :)

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

No branches or pull requests

3 participants
@meastp @samruddhikhandale and others