Repository navigation
Closed
Milestone
Description
Problem
The new Docker Build API in Europa (universe.dagger.io/docker.#Build) lacks the ability to set Docker image metadata. As compared to Dockerfile features:
| Feature | Dockerfile operation | CUE operation |
|---|---|---|
| Set default working directory | WORKDIR <PATH> |
Not available |
| Set default user | USER <ID> |
Not available |
| etc. | etc. | etc. |
This feature is tricky to implement, because it is a form of override, and CUE is designed to make overrides difficult. For good reason - abuse of overrides is a huge cause of runaway configuration complexity. But in this case, well, that’s just how Docker images work: 99% of builds involve 1) pulling a base image with a config outside of our control, then 2) overriding some fields in that config. Supporting this pattern is a must-have for adoption.
Proof of concept
Thanks to @helderco, we have a working proof of concept. This can live in the universe.dagger.io/docker package.
Latest proof-of-concept:
#Set: { input: #Image config: #ImageConfig output: #Image & { rootfs: input.rootfs "config": { for field, value in input.config { // doesn't exist in config, copy away if config[field] == _|_ { "\(field)": value } } for field, value in config { // replace any field that don't need merging if !list.Contains(["Env", "Labels"], field) { "\(field)": value } // handle special Env case if field == "Env" { Env: (_#MergeEnvs & { a: input.config.Env b: config.Env }).output } // handle special Labels case if field == "Labels" { Labels: (_#MergeMaps & { a: input.config.Labels b: config.Labels }).output } } } } } _#MergeEnvs: { a: [...string] b: [...string] _a_map: (_#ListToMap & { input: a }).output _b_map: (_#ListToMap & { input: b }).output _reconcile: (_#MergeMaps & { "a": _a_map, "b": _b_map }).output "output": [ for field, value in _reconcile { "\(field)=\(value)" } ] } _#ListToMap: { sep: string | *"=" input: [...string] "output": [string]: string "output": { for value in input { let pair = strings.Split(value, sep) "\(pair[0])": pair[1] } } } _#MergeMaps: { a: [string]: string b: [string]: string "output": { for field, value in a { if b[field] == _|_ { "\(field)": value } } for field, value in b { "\(field)": value } } }
Resources
- Original discussion: [draft] Dagger Europa experiment thechangelog/changelog.com#401 (comment)
- More recent discussion: Europa: Example configuration for changelog.com CI #1227
Metadata
Metadata
Assignees
Labels
No labels
Activity
[-]Europa: override Docker image metadata in CUE[/-][+]Europa: Set Docker image metadata[/+][-]Europa: Set Docker image metadata[/-][+]Europa: Set image metadata when building a Docker image[/+][-]Europa: Set image metadata when building a Docker image[/-][+]Europa: Set image metadata in a Docker build[/+]helderco commentedon Jan 5, 2022
Thanks @shykes, but this POC is outdated. The most current comments come from #1227.
The latest POC merges correctly
EnvandLabels.https://cuelang.org/play/?id=T8K1SMLw1HC#cue@export@cue
shykes commentedon Jan 5, 2022
Thanks, updated.
helderco commentedon Jan 5, 2022
As I said:
Originally posted by @helderco in #1227 (comment)
shykes commentedon Jan 10, 2022
@helderco just confirming if you’re interested in turning your POC into a pull request, or if you’d prefer someone else to do it? Since you started the implementation, you have priority if you want your “name in the credits”, but perfectly happy to assign someone else too.
helderco commentedon Jan 10, 2022
I’m happy to do it 😄
jlongtine commentedon Jan 31, 2022
@helderco With #1505, this gets easier. What else do we need to do to get this over the line? I'm happy to help out with this, if need be.
helderco commentedon Jan 31, 2022
It’s actually ready to push, I’m just missing a good example for the PR description. Let me just take care of my kid and I’ll push it in a moment.
jlongtine commentedon Jan 31, 2022
Sounds good, @helderco! Thanks for helping out!