Skip to content

Commit 5175083

Browse files
committed
Add more tests to building deb containers
Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com>
1 parent e604b15 commit 5175083

5 files changed

Lines changed: 844 additions & 59 deletions

File tree

internal/test/llb.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package test
2+
3+
import (
4+
"bytes"
5+
"context"
6+
"encoding/json"
7+
"fmt"
8+
9+
"github.com/moby/buildkit/client/llb"
10+
"github.com/moby/buildkit/solver/pb"
11+
"github.com/opencontainers/go-digest"
12+
)
13+
14+
// LLBOpsFromState extracts the list of LLB operations from the provided LLB state.
15+
//
16+
// This function and LLBOp type has been inspired by
17+
// https://github.com/moby/buildkit/blob/c70e8e666f8f6ee3c0d83b20c338be5aedeaa97a/cmd/buildctl/debug/dumpllb.go#L59.
18+
func LLBOpsFromState(ctx context.Context, state llb.State) ([]LLBOp, error) {
19+
def, err := state.Marshal(ctx)
20+
if err != nil {
21+
return nil, fmt.Errorf("marshaling state: %w", err)
22+
}
23+
24+
var ops []LLBOp
25+
for _, dt := range def.Def {
26+
var op pb.Op
27+
if err := op.UnmarshalVT(dt); err != nil {
28+
return nil, fmt.Errorf("parsing op: %w", err)
29+
}
30+
dgst := digest.FromBytes(dt)
31+
ent := LLBOp{Op: &op, OpMetadata: def.Metadata[dgst].ToPB()}
32+
33+
ops = append(ops, ent)
34+
}
35+
36+
if len(ops) > 0 {
37+
ops = ops[:len(ops)-1] // Last operation is a final export, it has no operations.
38+
}
39+
40+
return ops, nil
41+
}
42+
43+
// LLBOpsToJSON converts a list of LLB operations to a JSON string.
44+
func LLBOpsToJSON(ops []LLBOp) (string, error) {
45+
var buf bytes.Buffer
46+
47+
enc := json.NewEncoder(&buf)
48+
for _, op := range ops {
49+
if err := enc.Encode(op); err != nil {
50+
return "", err
51+
}
52+
}
53+
54+
return buf.String(), nil
55+
}
56+
57+
// LLBOp represents a single LLB operation along with its metadata.
58+
type LLBOp struct {
59+
Op *pb.Op
60+
OpMetadata *pb.OpMetadata
61+
}

targets/linux/deb/distro/container.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ func (c *Config) BuildContainer(ctx context.Context, client gwclient.Client, sOp
2424
baseImg = bi.ToState(sOpt, opts...)
2525
}
2626

27+
// Those base repos come from distro configuration.
2728
repos := dalec.GetExtraRepos(c.ExtraRepos, "install")
29+
30+
// These are user specified via spec.
2831
repos = append(repos, spec.GetInstallRepos(targetKey)...)
2932

3033
withRepos := c.RepoMounts(repos, sOpt, opts...)
@@ -57,8 +60,6 @@ func (c *Config) BuildContainer(ctx context.Context, client gwclient.Client, sOp
5760
opts := append(opts, dalec.ProgressGroup("Install base image packages"))
5861
baseImg = baseImg.Run(
5962
dalec.WithConstraints(opts...),
60-
llb.AddEnv("DEBIAN_FRONTEND", "noninteractive"),
61-
dalec.WithMountedAptCache(c.AptCachePrefix, opts...),
6263
InstallLocalPkg(basePkg, true, opts...),
6364
dalec.WithMountedAptCache(c.AptCachePrefix, opts...),
6465
).Root()
@@ -69,7 +70,6 @@ func (c *Config) BuildContainer(ctx context.Context, client gwclient.Client, sOp
6970
return baseImg.Run(
7071
dalec.WithConstraints(opts...),
7172
withRepos,
72-
llb.AddEnv("DEBIAN_FRONTEND", "noninteractive"),
7373
dalec.WithMountedAptCache(c.AptCachePrefix, opts...),
7474
// This file makes dpkg give more verbose output which can be useful when things go awry.
7575
llb.AddMount("/etc/dpkg/dpkg.cfg.d/99-dalec-debug", debug, llb.SourcePath("debug"), llb.Readonly),

0 commit comments

Comments
 (0)