diff --git a/modules/mesh-build-image/cmd/mesh-build-image/build.go b/modules/mesh-build-image/cmd/mesh-build-image/build.go index 037583836..cb28d0ac1 100644 --- a/modules/mesh-build-image/cmd/mesh-build-image/build.go +++ b/modules/mesh-build-image/cmd/mesh-build-image/build.go @@ -165,7 +165,10 @@ func (m *Module) build(ctx context.Context, args map[string]any) (any, error) { // --network pasta: a RUN step's network is pasta's, in user space. buildah's default for a rootless RUN is a // netavark bridge whose nftables rules cannot be applied for an account without a user session, so every RUN // failed before it started ("setup network: netavark: nftables error"; issue 1703, reproduced with buildah 1.45.2). - argv := append(m.storeFlags(), "bud", "--isolation", "oci", "--network", "pasta", "--tag", local, "--file", dockerfile) + // --timestamp 0: the image's creation time and the time of every file in its layers are the Unix epoch, so one source at one + // version is one digest in any folder at any time; no label or annotation below names a commit, a folder, a time or a node + // (design 47 H2 H-A-591 (3)). + argv := append(m.storeFlags(), "bud", "--isolation", "oci", "--network", "pasta", "--timestamp", "0", "--tag", local, "--file", dockerfile) if art.Target != "" { argv = append(argv, "--target", art.Target) } diff --git a/modules/mesh-build-image/cmd/mesh-build-image/build_test.go b/modules/mesh-build-image/cmd/mesh-build-image/build_test.go index b8a6cdf14..69be6e909 100644 --- a/modules/mesh-build-image/cmd/mesh-build-image/build_test.go +++ b/modules/mesh-build-image/cmd/mesh-build-image/build_test.go @@ -85,7 +85,7 @@ func TestBuildRunsBuildahRootlessAndAnswersTheDigest(t *testing.T) { } dir := filepath.Join(m.Work, "ws1", "tree", "modules", "demo") for _, want := range []string{ - "--root " + m.Store + "/root", "--runroot " + m.Store + "/run", "--isolation oci", "--network pasta", + "--root " + m.Store + "/root", "--runroot " + m.Store + "/run", "--isolation oci", "--network pasta", "--timestamp 0 ", "--file " + dir + "/Dockerfile", "--target final", "--build-arg DEMO_BASE=docker.io/library/busybox@sha256:0000000000000000000000000000000000000000000000000000000000000001", } { @@ -343,7 +343,7 @@ func TestTheImageBuildGetsTheVersionTheAskCarriesAsMeshVersion(t *testing.T) { } m, f, states = setup(t, same) runBuild(t, m, states, nil) - if bud := f.called("bud"); len(bud) != 1 || (strings.Contains(bud[0].line, "MESH_VERSION") || strings.Contains(bud[0].line, "image.version")) { + if bud := f.called("bud"); len(bud) != 1 || (strings.Contains(bud[0].line, "MESH_VERSION") || strings.Contains(bud[0].line, "image.version") || strings.Contains(bud[0].line, "--label")) { t.Fatalf("a build with no version: %+v", bud) } } diff --git a/modules/mesh-build-image/cmd/mesh-build-image/integration_test.go b/modules/mesh-build-image/cmd/mesh-build-image/integration_test.go index 0e71cd816..3240f5ab6 100644 --- a/modules/mesh-build-image/cmd/mesh-build-image/integration_test.go +++ b/modules/mesh-build-image/cmd/mesh-build-image/integration_test.go @@ -10,6 +10,7 @@ package main import ( "context" "encoding/json" + "fmt" "os" "os/exec" "os/user" @@ -20,6 +21,7 @@ import ( sdkstep "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/steprun" + "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/steprun/conformance" ) func needTools(t *testing.T, what string, tools ...string) { @@ -159,6 +161,37 @@ func TestARealBuildAnswersTheImagesDigest(t *testing.T) { } } +// The kit's `reproducible` case over a real build (design 47 H2 H-A-591 (3), H-A-593 (3)): the image fixture, with no step that +// fetches, built by real buildah in two workspace folders of other names and other file times gives one manifest digest. +func TestARealImageBuildIsOneDigestInAnyFolder(t *testing.T) { + needTools(t, "a rootless build", "buildah", "newuidmap") + fill := func(dir string) error { + module := filepath.Join(dir, "ws1", "tree", "modules", "img") + if err := os.MkdirAll(module, 0o755); err != nil { + return err + } + for name, body := range map[string]string{ + "module.json": `{"module":"img","version":"1","build":{"artifacts":[{"name":"server","kind":"image","from":"Dockerfile"}]}}`, + "Dockerfile": "FROM scratch\nCOPY hello.txt /hello.txt\n", + "hello.txt": "hello\n", + } { + if err := os.WriteFile(filepath.Join(module, name), []byte(body), 0o644); err != nil { + return err + } + } + return nil + } + conformance.Reproducible(t, fill, func(dir string) (map[string]string, error) { + m, states := realModule(t) + m.Work = dir + res, st := buildReal(t, m, states) + if st.State != sdkstep.StepPassed { + return nil, fmt.Errorf("the build step ended %s: %s", st.State, st.Reason) + } + return map[string]string{"server": res.Digest}, nil + }) +} + // needBase skips unless the build node can pull the small base the isolation Dockerfiles run in. func needBase(t *testing.T, m *Module) string { t.Helper()