Skip to content

Commit ef3e05b

Browse files
committed
Log env var before merge on Combine
Also, add debug configuration & example for Combine
1 parent fa8e25f commit ef3e05b

File tree

4 files changed

+30
-11
lines changed

4 files changed

+30
-11
lines changed

.vscode/launch.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,23 @@
1818
"."
1919
]
2020
},
21+
{
22+
"name": "Dazzle example combine",
23+
"type": "go",
24+
"request": "launch",
25+
"mode": "auto",
26+
"program": "${fileWorkspaceFolder}",
27+
"args": [
28+
"combine",
29+
"--addr",
30+
"unix:///run/buildkit/buildkitd.sock",
31+
"--context",
32+
"example",
33+
"localhost:5000/dazzle",
34+
"--all",
35+
"."
36+
]
37+
},
2138
{
2239
"name": "Dazzle runner",
2340
"type": "go",

example.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33
# Build and run the example
44
gp await-port 5000
5-
go run main.go build --context example localhost:5000/dazzle
5+
go run main.go build --context example localhost:5000/dazzle
6+
go run main.go combine --context example localhost:5000/dazzle --all

pkg/dazzle/build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func (p *Project) Build(ctx context.Context, session *BuildSession) error {
170170
for _, chk := range p.Chunks {
171171
_, _, err := chk.test(ctx, session)
172172
if err != nil {
173-
return fmt.Errorf("cannot build chunk %s: %w", chk.Name, err)
173+
return fmt.Errorf("cannot test chunk %s: %w", chk.Name, err)
174174
}
175175

176176
_, _, err = chk.build(ctx, session)

pkg/dazzle/combiner.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -286,15 +286,15 @@ func mergeEnv(base *ociv1.Image, others []*ociv1.Image, vars []EnvVarCombination
286286
envs[segs[0]] = segs[1]
287287
}
288288

289-
for _, m := range others {
290-
for _, e := range m.Config.Env {
291-
segs := strings.Split(e, "=")
289+
for _, ociImage := range others {
290+
for _, imageEnvVars := range ociImage.Config.Env {
291+
segs := strings.Split(imageEnvVars, "=")
292292
if len(segs) != 2 {
293-
return nil, fmt.Errorf("env var %s in invalid", e)
293+
return nil, fmt.Errorf("env var %s in invalid", imageEnvVars)
294294
}
295295

296296
k, v := segs[0], segs[1]
297-
if ov, exists := envs[k]; exists {
297+
if envValue, exists := envs[k]; exists {
298298
action := EnvVarCombineUseFirst
299299
for _, mv := range vars {
300300
if mv.Name == k {
@@ -312,7 +312,7 @@ func mergeEnv(base *ociv1.Image, others []*ociv1.Image, vars []EnvVarCombination
312312
envs[k] += ":" + v
313313
case EnvVarCombineMergeUnique:
314314
vs := make(map[string]struct{})
315-
for _, s := range strings.Split(ov, ":") {
315+
for _, s := range strings.Split(envValue, ":") {
316316
vs[s] = struct{}{}
317317
}
318318
vs[v] = struct{}{}
@@ -323,9 +323,10 @@ func mergeEnv(base *ociv1.Image, others []*ociv1.Image, vars []EnvVarCombination
323323
envs[k] = strings.Join(vss, ":")
324324
}
325325
log.WithFields(log.Fields{
326-
"action": action,
327-
"name": k,
328-
"new-value": envs[k],
326+
"action": action,
327+
"name": k,
328+
"image-vars": envValue,
329+
"new-value": envs[k],
329330
}).Info("merged environment variable")
330331

331332
continue

0 commit comments

Comments
 (0)