Skip to content

Commit 5d94f50

Browse files
committed
rpm: install all target packages in containers
Restore default containers to install every generated binary RPM and keep supplemental package integration coverage with the RPM implementation. Signed-off-by: Brian Goff <cpuguy83@gmail.com>
1 parent 82d8c17 commit 5d94f50

7 files changed

Lines changed: 392 additions & 68 deletions

File tree

targets/linux/rpm/distro/container.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,8 @@ func (cfg *Config) BuildContainer(ctx context.Context, client gwclient.Client, s
4646

4747
baseMountPath := rpmMountDir + "-base"
4848
basePkgs := llb.Scratch().File(llb.Mkdir("/RPMS", 0o755), opts...)
49-
revision := spec.Revision
50-
if revision == "" {
51-
revision = "1"
52-
}
53-
// Anchor the glob on the primary package's NVR so supplemental RPMs built
54-
// into the same output tree are not installed by the default container target.
5549
pkgs := []string{
56-
filepath.Join(rpmMountDir, "*", spec.Name+"-"+spec.Version+"-"+revision+".*.rpm"),
50+
filepath.Join(rpmMountDir, "*/*.rpm"),
5751
}
5852

5953
if !skipBase && len(cfg.BasePackages) > 0 {

targets/linux/rpm/distro/container_test.go

Lines changed: 50 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -10,85 +10,74 @@ import (
1010
"gotest.tools/v3/assert"
1111
)
1212

13-
func TestBuildContainerInstallsOnlyThePrimaryRPM(t *testing.T) {
13+
func TestBuildContainerInstallsAllGeneratedBinaryRPMs(t *testing.T) {
1414
t.Parallel()
1515

1616
cases := []struct {
17-
name string
18-
packageName string
19-
version string
20-
revision string
21-
archDir string
22-
primaryRPM string
23-
supplementalRPM string
17+
name string
18+
archDir string
19+
rpm string
2420
}{
2521
{
26-
name: "versions beginning with a digit",
27-
packageName: "myapp",
28-
version: "1.0.0",
29-
revision: "1",
30-
archDir: "x86_64",
31-
primaryRPM: "myapp-1.0.0-1.azl3.x86_64.rpm",
32-
supplementalRPM: "myapp-debug-1.0.0-1.azl3.x86_64.rpm",
22+
name: "the primary package is selected",
23+
archDir: "x86_64",
24+
rpm: "myapp-1.0.0-1.azl3.x86_64.rpm",
3325
},
3426
{
35-
name: "versions beginning with a letter",
36-
packageName: "myapp",
37-
version: "v1.0",
38-
revision: "2",
39-
archDir: "x86_64",
40-
primaryRPM: "myapp-v1.0-2.x86_64.rpm",
41-
supplementalRPM: "myapp-docs-v1.0-2.x86_64.rpm",
27+
name: "a default supplemental package is selected",
28+
archDir: "x86_64",
29+
rpm: "myapp-contrib-1.0.0-1.azl3.x86_64.rpm",
4230
},
4331
{
44-
name: "architecture-independent packages",
45-
packageName: "my-complex-app",
46-
version: "1.0~beta1",
47-
revision: "42",
48-
archDir: "noarch",
49-
primaryRPM: "my-complex-app-1.0~beta1-42.azl3.noarch.rpm",
50-
supplementalRPM: "my-complex-app-compat-1.0~beta1-42.azl3.noarch.rpm",
32+
name: "a custom-named supplemental package is selected",
33+
archDir: "x86_64",
34+
rpm: "my-custom-pkg-1.0.0-1.azl3.x86_64.rpm",
35+
},
36+
{
37+
name: "a documentation package is selected",
38+
archDir: "noarch",
39+
rpm: "myapp-docs-1.0.0-1.azl3.noarch.rpm",
40+
},
41+
{
42+
name: "a debug package is selected",
43+
archDir: "x86_64",
44+
rpm: "myapp-debuginfo-1.0.0-1.azl3.x86_64.rpm",
45+
},
46+
{
47+
name: "a compatibility package is selected",
48+
archDir: "aarch64",
49+
rpm: "myapp-compat-1.0.0-1.azl3.aarch64.rpm",
50+
},
51+
}
52+
53+
var installed []string
54+
cfg := &Config{
55+
ContextRef: "worker",
56+
InstallFunc: func(_ *dnfInstallConfig, _ string, pkgs []string) llb.RunOption {
57+
installed = append(installed, pkgs...)
58+
return llb.Args([]string{"true"})
5159
},
5260
}
61+
sOpt := dalec.SourceOpts{
62+
GetContext: func(string, ...llb.LocalOption) (*llb.State, error) {
63+
st := llb.Scratch()
64+
return &st, nil
65+
},
66+
}
67+
68+
cfg.BuildContainer(t.Context(), &containerTestClient{}, sOpt, &dalec.Spec{}, "target", llb.Scratch())
69+
70+
assert.Assert(t, len(installed) == 1)
71+
assert.Equal(t, installed[0], filepath.Join("/tmp/rpms", "*/*.rpm"))
5372

5473
for _, tc := range cases {
5574
tc := tc
5675
t.Run(tc.name, func(t *testing.T) {
5776
t.Parallel()
5877

59-
var installed []string
60-
cfg := &Config{
61-
ContextRef: "worker",
62-
InstallFunc: func(_ *dnfInstallConfig, _ string, pkgs []string) llb.RunOption {
63-
installed = append(installed, pkgs...)
64-
return llb.Args([]string{"true"})
65-
},
66-
}
67-
sOpt := dalec.SourceOpts{
68-
GetContext: func(string, ...llb.LocalOption) (*llb.State, error) {
69-
st := llb.Scratch()
70-
return &st, nil
71-
},
72-
}
73-
spec := &dalec.Spec{
74-
Name: tc.packageName,
75-
Version: tc.version,
76-
Revision: tc.revision,
77-
}
78-
79-
cfg.BuildContainer(t.Context(), &containerTestClient{}, sOpt, spec, "target", llb.Scratch())
80-
81-
assert.Assert(t, len(installed) == 1)
82-
wantPattern := filepath.Join("/tmp/rpms", "*", tc.packageName+"-"+tc.version+"-"+tc.revision+".*.rpm")
83-
assert.Equal(t, installed[0], wantPattern)
84-
85-
primaryMatches, err := filepath.Match(installed[0], filepath.Join("/tmp/rpms", tc.archDir, tc.primaryRPM))
86-
assert.NilError(t, err)
87-
assert.Assert(t, primaryMatches, "pattern %q should select primary RPM %q", installed[0], tc.primaryRPM)
88-
89-
supplementalMatches, err := filepath.Match(installed[0], filepath.Join("/tmp/rpms", tc.archDir, tc.supplementalRPM))
78+
matches, err := filepath.Match(installed[0], filepath.Join("/tmp/rpms", tc.archDir, tc.rpm))
9079
assert.NilError(t, err)
91-
assert.Assert(t, !supplementalMatches, "pattern %q should exclude supplemental RPM %q", installed[0], tc.supplementalRPM)
80+
assert.Assert(t, matches, "pattern %q should select RPM %q", installed[0], tc.rpm)
9281
})
9382
}
9483
}

test/linux_target_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ type targetConfig struct {
7777
// Sysext is the target for creating a systemd system extension.
7878
Sysext string
7979

80+
Subpackages *subpackageTestConfig
81+
8082
// FormatDepEqual, when set, alters the provided dependency version to match
8183
// what is necessary for the target distro to set a dependency for an equals
8284
// operator.
@@ -3864,6 +3866,14 @@ func Value() string {
38643866
ctx := startTestSpan(baseCtx, t)
38653867
testArtifactCapabilities(ctx, t, testConfig)
38663868
})
3869+
3870+
if testConfig.Target.Subpackages != nil {
3871+
t.Run("subpackages", func(t *testing.T) {
3872+
t.Parallel()
3873+
ctx := startTestSpan(baseCtx, t)
3874+
testSubpackages(ctx, t, testConfig.Target, testConfig.Target.Subpackages)
3875+
})
3876+
}
38673877
}
38683878

38693879
func testNodeNpmGenerator(ctx context.Context, t *testing.T, targetCfg targetConfig, opts ...srOpt) {

0 commit comments

Comments
 (0)