Skip to content

Commit 92ac06b

Browse files
committed
main: move legacy ISO code into legacy_iso.go
This commit moves the rpm based ISO handling from images.go and main.go into the new legacy_iso.go file to make clear that the parts in there are only needed for the legacy (rpm) ISO handling and can be removed once we no longer need to support this.
1 parent e114f85 commit 92ac06b

File tree

2 files changed

+163
-166
lines changed

2 files changed

+163
-166
lines changed

bib/cmd/bootc-image-builder/image.go renamed to bib/cmd/bootc-image-builder/legacy_iso.go

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/osbuild/images/pkg/container"
1414
"github.com/osbuild/images/pkg/customizations/anaconda"
1515
"github.com/osbuild/images/pkg/customizations/kickstart"
16+
"github.com/osbuild/images/pkg/depsolvednf"
1617
"github.com/osbuild/images/pkg/disk"
1718
"github.com/osbuild/images/pkg/image"
1819
"github.com/osbuild/images/pkg/manifest"
@@ -22,9 +23,20 @@ import (
2223
"github.com/osbuild/images/pkg/runner"
2324
"github.com/sirupsen/logrus"
2425

26+
podman_container "github.com/osbuild/images/pkg/bib/container"
27+
2528
"github.com/osbuild/bootc-image-builder/bib/internal/distrodef"
2629
)
2730

31+
// all possible locations for the bib's distro definitions
32+
// ./data/defs and ./bib/data/defs are for development
33+
// /usr/share/bootc-image-builder/defs is for the production, containerized version
34+
var distroDefPaths = []string{
35+
"./data/defs",
36+
"./bib/data/defs",
37+
"/usr/share/bootc-image-builder/defs",
38+
}
39+
2840
type ManifestConfig struct {
2941
// OCI image path (without the transport, that is always docker://)
3042
Imgref string
@@ -50,6 +62,155 @@ type ManifestConfig struct {
5062
UseLibrepo bool
5163
}
5264

65+
func manifestFromCobraForLegacyISO(imgref, buildImgref, imgTypeStr, rootFs, rpmCacheRoot string, config *blueprint.Blueprint, useLibrepo bool, cntArch arch.Arch) ([]byte, *mTLSConfig, error) {
66+
container, err := podman_container.New(imgref)
67+
if err != nil {
68+
return nil, nil, err
69+
}
70+
defer func() {
71+
if err := container.Stop(); err != nil {
72+
logrus.Warnf("error stopping container: %v", err)
73+
}
74+
}()
75+
76+
var rootfsType string
77+
if rootFs != "" {
78+
rootfsType = rootFs
79+
} else {
80+
rootfsType, err = container.DefaultRootfsType()
81+
if err != nil {
82+
return nil, nil, fmt.Errorf("cannot get rootfs type for container: %w", err)
83+
}
84+
if rootfsType == "" {
85+
return nil, nil, fmt.Errorf(`no default root filesystem type specified in container, please use "--rootfs" to set manually`)
86+
}
87+
}
88+
89+
// Gather some data from the containers distro
90+
sourceinfo, err := osinfo.Load(container.Root())
91+
if err != nil {
92+
return nil, nil, err
93+
}
94+
95+
buildContainer := container
96+
buildSourceinfo := sourceinfo
97+
startedBuildContainer := false
98+
defer func() {
99+
if startedBuildContainer {
100+
if err := buildContainer.Stop(); err != nil {
101+
logrus.Warnf("error stopping container: %v", err)
102+
}
103+
}
104+
}()
105+
106+
if buildImgref != "" {
107+
buildContainer, err = podman_container.New(buildImgref)
108+
if err != nil {
109+
return nil, nil, err
110+
}
111+
startedBuildContainer = true
112+
113+
// Gather some data from the containers distro
114+
buildSourceinfo, err = osinfo.Load(buildContainer.Root())
115+
if err != nil {
116+
return nil, nil, err
117+
}
118+
} else {
119+
buildImgref = imgref
120+
}
121+
122+
// This is needed just for RHEL and RHSM in most cases, but let's run it every time in case
123+
// the image has some non-standard dnf plugins.
124+
if err := buildContainer.InitDNF(); err != nil {
125+
return nil, nil, err
126+
}
127+
solver, err := buildContainer.NewContainerSolver(rpmCacheRoot, cntArch, sourceinfo)
128+
if err != nil {
129+
return nil, nil, err
130+
}
131+
132+
manifestConfig := &ManifestConfig{
133+
Architecture: cntArch,
134+
Config: config,
135+
Imgref: imgref,
136+
BuildImgref: buildImgref,
137+
DistroDefPaths: distroDefPaths,
138+
SourceInfo: sourceinfo,
139+
BuildSourceInfo: buildSourceinfo,
140+
RootFSType: rootfsType,
141+
UseLibrepo: useLibrepo,
142+
}
143+
144+
manifest, repos, err := makeISOManifest(manifestConfig, solver, rpmCacheRoot)
145+
if err != nil {
146+
return nil, nil, err
147+
}
148+
149+
mTLS, err := extractTLSKeys(repos)
150+
if err != nil {
151+
return nil, nil, err
152+
}
153+
154+
return manifest, mTLS, nil
155+
}
156+
157+
func makeISOManifest(c *ManifestConfig, solver *depsolvednf.Solver, cacheRoot string) (manifest.OSBuildManifest, map[string][]rpmmd.RepoConfig, error) {
158+
rng := createRand()
159+
mani, err := manifestForISO(c, rng)
160+
if err != nil {
161+
return nil, nil, fmt.Errorf("cannot get manifest: %w", err)
162+
}
163+
164+
// depsolve packages
165+
depsolvedSets := make(map[string]depsolvednf.DepsolveResult)
166+
depsolvedRepos := make(map[string][]rpmmd.RepoConfig)
167+
for name, pkgSet := range mani.GetPackageSetChains() {
168+
res, err := solver.Depsolve(pkgSet, 0)
169+
if err != nil {
170+
return nil, nil, fmt.Errorf("cannot depsolve: %w", err)
171+
}
172+
depsolvedSets[name] = *res
173+
depsolvedRepos[name] = res.Repos
174+
}
175+
176+
// Resolve container - the normal case is that host and target
177+
// architecture are the same. However it is possible to build
178+
// cross-arch images by using qemu-user. This will run everything
179+
// (including the build-root) with the target arch then, it
180+
// is fast enough (given that it's mostly I/O and all I/O is
181+
// run naively via syscall translation)
182+
183+
// XXX: should NewResolver() take "arch.Arch"?
184+
resolver := container.NewResolver(c.Architecture.String())
185+
186+
containerSpecs := make(map[string][]container.Spec)
187+
for plName, sourceSpecs := range mani.GetContainerSourceSpecs() {
188+
for _, c := range sourceSpecs {
189+
resolver.Add(c)
190+
}
191+
specs, err := resolver.Finish()
192+
if err != nil {
193+
return nil, nil, fmt.Errorf("cannot resolve containers: %w", err)
194+
}
195+
for _, spec := range specs {
196+
if spec.Arch != c.Architecture {
197+
return nil, nil, fmt.Errorf("image found is for unexpected architecture %q (expected %q), if that is intentional, please make sure --target-arch matches", spec.Arch, c.Architecture)
198+
}
199+
}
200+
containerSpecs[plName] = specs
201+
}
202+
203+
var opts manifest.SerializeOptions
204+
if c.UseLibrepo {
205+
opts.RpmDownloader = osbuild.RpmDownloaderLibrepo
206+
}
207+
mf, err := mani.Serialize(depsolvedSets, containerSpecs, nil, &opts)
208+
if err != nil {
209+
return nil, nil, fmt.Errorf("[ERROR] manifest serialization failed: %s", err.Error())
210+
}
211+
return mf, depsolvedRepos, nil
212+
}
213+
53214
func labelForISO(os *osinfo.OSRelease, arch *arch.Arch) string {
54215
switch os.ID {
55216
case "fedora":

bib/cmd/bootc-image-builder/main.go

Lines changed: 2 additions & 166 deletions
Original file line numberDiff line numberDiff line change
@@ -26,32 +26,18 @@ import (
2626
"github.com/osbuild/images/pkg/bib/blueprintload"
2727
"github.com/osbuild/images/pkg/cloud"
2828
"github.com/osbuild/images/pkg/cloud/awscloud"
29-
"github.com/osbuild/images/pkg/container"
30-
"github.com/osbuild/images/pkg/depsolvednf"
3129
"github.com/osbuild/images/pkg/distro/bootc"
3230
"github.com/osbuild/images/pkg/experimentalflags"
3331
"github.com/osbuild/images/pkg/manifest"
3432
"github.com/osbuild/images/pkg/manifestgen"
35-
"github.com/osbuild/images/pkg/osbuild"
3633
"github.com/osbuild/images/pkg/reporegistry"
3734
"github.com/osbuild/images/pkg/rpmmd"
3835

39-
"github.com/osbuild/bootc-image-builder/bib/internal/imagetypes"
40-
podman_container "github.com/osbuild/images/pkg/bib/container"
41-
"github.com/osbuild/images/pkg/bib/osinfo"
42-
4336
"github.com/osbuild/image-builder-cli/pkg/progress"
4437
"github.com/osbuild/image-builder-cli/pkg/setup"
45-
)
4638

47-
// all possible locations for the bib's distro definitions
48-
// ./data/defs and ./bib/data/defs are for development
49-
// /usr/share/bootc-image-builder/defs is for the production, containerized version
50-
var distroDefPaths = []string{
51-
"./data/defs",
52-
"./bib/data/defs",
53-
"/usr/share/bootc-image-builder/defs",
54-
}
39+
"github.com/osbuild/bootc-image-builder/bib/internal/imagetypes"
40+
)
5541

5642
var (
5743
osGetuid = os.Getuid
@@ -71,63 +57,6 @@ func inContainerOrUnknown() bool {
7157
return err == nil
7258
}
7359

74-
func makeISOManifest(c *ManifestConfig, solver *depsolvednf.Solver, cacheRoot string) (manifest.OSBuildManifest, map[string][]rpmmd.RepoConfig, error) {
75-
rng := createRand()
76-
mani, err := manifestForISO(c, rng)
77-
if err != nil {
78-
return nil, nil, fmt.Errorf("cannot get manifest: %w", err)
79-
}
80-
81-
// depsolve packages
82-
depsolvedSets := make(map[string]depsolvednf.DepsolveResult)
83-
depsolvedRepos := make(map[string][]rpmmd.RepoConfig)
84-
for name, pkgSet := range mani.GetPackageSetChains() {
85-
res, err := solver.Depsolve(pkgSet, 0)
86-
if err != nil {
87-
return nil, nil, fmt.Errorf("cannot depsolve: %w", err)
88-
}
89-
depsolvedSets[name] = *res
90-
depsolvedRepos[name] = res.Repos
91-
}
92-
93-
// Resolve container - the normal case is that host and target
94-
// architecture are the same. However it is possible to build
95-
// cross-arch images by using qemu-user. This will run everything
96-
// (including the build-root) with the target arch then, it
97-
// is fast enough (given that it's mostly I/O and all I/O is
98-
// run naively via syscall translation)
99-
100-
// XXX: should NewResolver() take "arch.Arch"?
101-
resolver := container.NewResolver(c.Architecture.String())
102-
103-
containerSpecs := make(map[string][]container.Spec)
104-
for plName, sourceSpecs := range mani.GetContainerSourceSpecs() {
105-
for _, c := range sourceSpecs {
106-
resolver.Add(c)
107-
}
108-
specs, err := resolver.Finish()
109-
if err != nil {
110-
return nil, nil, fmt.Errorf("cannot resolve containers: %w", err)
111-
}
112-
for _, spec := range specs {
113-
if spec.Arch != c.Architecture {
114-
return nil, nil, fmt.Errorf("image found is for unexpected architecture %q (expected %q), if that is intentional, please make sure --target-arch matches", spec.Arch, c.Architecture)
115-
}
116-
}
117-
containerSpecs[plName] = specs
118-
}
119-
120-
var opts manifest.SerializeOptions
121-
if c.UseLibrepo {
122-
opts.RpmDownloader = osbuild.RpmDownloaderLibrepo
123-
}
124-
mf, err := mani.Serialize(depsolvedSets, containerSpecs, nil, &opts)
125-
if err != nil {
126-
return nil, nil, fmt.Errorf("[ERROR] manifest serialization failed: %s", err.Error())
127-
}
128-
return mf, depsolvedRepos, nil
129-
}
130-
13160
func saveManifest(ms manifest.OSBuildManifest, fpath string) (err error) {
13261
b, err := json.MarshalIndent(ms, "", " ")
13362
if err != nil {
@@ -271,99 +200,6 @@ func manifestFromCobraForDisk(imgref, buildImgref, imgTypeStr, rootFs, rpmCacheR
271200
return nil, nil, err
272201
}
273202
return buf.Bytes(), nil, nil
274-
275-
}
276-
277-
func manifestFromCobraForISO(imgref, buildImgref, imgTypeStr, rootFs, rpmCacheRoot string, config *blueprint.Blueprint, useLibrepo bool, cntArch arch.Arch) ([]byte, *mTLSConfig, error) {
278-
container, err := podman_container.New(imgref)
279-
if err != nil {
280-
return nil, nil, err
281-
}
282-
defer func() {
283-
if err := container.Stop(); err != nil {
284-
logrus.Warnf("error stopping container: %v", err)
285-
}
286-
}()
287-
288-
var rootfsType string
289-
if rootFs != "" {
290-
rootfsType = rootFs
291-
} else {
292-
rootfsType, err = container.DefaultRootfsType()
293-
if err != nil {
294-
return nil, nil, fmt.Errorf("cannot get rootfs type for container: %w", err)
295-
}
296-
if rootfsType == "" {
297-
return nil, nil, fmt.Errorf(`no default root filesystem type specified in container, please use "--rootfs" to set manually`)
298-
}
299-
}
300-
301-
// Gather some data from the containers distro
302-
sourceinfo, err := osinfo.Load(container.Root())
303-
if err != nil {
304-
return nil, nil, err
305-
}
306-
307-
buildContainer := container
308-
buildSourceinfo := sourceinfo
309-
startedBuildContainer := false
310-
defer func() {
311-
if startedBuildContainer {
312-
if err := buildContainer.Stop(); err != nil {
313-
logrus.Warnf("error stopping container: %v", err)
314-
}
315-
}
316-
}()
317-
318-
if buildImgref != "" {
319-
buildContainer, err = podman_container.New(buildImgref)
320-
if err != nil {
321-
return nil, nil, err
322-
}
323-
startedBuildContainer = true
324-
325-
// Gather some data from the containers distro
326-
buildSourceinfo, err = osinfo.Load(buildContainer.Root())
327-
if err != nil {
328-
return nil, nil, err
329-
}
330-
} else {
331-
buildImgref = imgref
332-
}
333-
334-
// This is needed just for RHEL and RHSM in most cases, but let's run it every time in case
335-
// the image has some non-standard dnf plugins.
336-
if err := buildContainer.InitDNF(); err != nil {
337-
return nil, nil, err
338-
}
339-
solver, err := buildContainer.NewContainerSolver(rpmCacheRoot, cntArch, sourceinfo)
340-
if err != nil {
341-
return nil, nil, err
342-
}
343-
344-
manifestConfig := &ManifestConfig{
345-
Architecture: cntArch,
346-
Config: config,
347-
Imgref: imgref,
348-
BuildImgref: buildImgref,
349-
DistroDefPaths: distroDefPaths,
350-
SourceInfo: sourceinfo,
351-
BuildSourceInfo: buildSourceinfo,
352-
RootFSType: rootfsType,
353-
UseLibrepo: useLibrepo,
354-
}
355-
356-
manifest, repos, err := makeISOManifest(manifestConfig, solver, rpmCacheRoot)
357-
if err != nil {
358-
return nil, nil, err
359-
}
360-
361-
mTLS, err := extractTLSKeys(repos)
362-
if err != nil {
363-
return nil, nil, err
364-
}
365-
366-
return manifest, mTLS, nil
367203
}
368204

369205
func cmdManifest(cmd *cobra.Command, args []string) error {

0 commit comments

Comments
 (0)