Skip to content

Commit

Permalink
main: SilenceUsage: true by default
Browse files Browse the repository at this point in the history
This pairs with usage of `RunE`, xref
38ce0da

Signed-off-by: Colin Walters <[email protected]>
  • Loading branch information
cgwalters authored and mvo5 committed Jan 24, 2024
1 parent 38ce0da commit 156a764
Show file tree
Hide file tree
Showing 5 changed files with 201 additions and 58 deletions.
2 changes: 1 addition & 1 deletion Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ FROM registry.fedoraproject.org/fedora:39
# - https://github.com/osbuild/bootc-image-builder/issues/9
# - https://github.com/osbuild/osbuild/pull/1468
COPY ./group_osbuild-osbuild-fedora-39.repo /etc/yum.repos.d/
RUN dnf install -y osbuild osbuild-ostree osbuild-depsolve-dnf && dnf clean all
RUN dnf install -y osbuild osbuild-ostree osbuild-depsolve-dnf podman qemu-img && dnf clean all
COPY --from=builder /build/bin/bootc-image-builder /usr/bin/bootc-image-builder
COPY entrypoint.sh /

Expand Down
54 changes: 24 additions & 30 deletions bib/cmd/bootc-image-builder/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,49 +47,32 @@ type ManifestConfig struct {
func Manifest(c *ManifestConfig) (*manifest.Manifest, error) {
rng := createRand()

var img image.ImageKind
var err error

switch c.ImgType {
case "ami", "qcow2", "raw":
img, err = pipelinesForDiskImage(c, rng)
return manifestForDiskImage(c, rng)
case "iso":
img, err = pipelinesForISO(c, rng)
return manifestForISO(c, rng)
default:
return nil, fmt.Errorf("Manifest(): unsupported image type %q", c.ImgType)
}

if err != nil {
return nil, err
}

mf := manifest.New()
mf.Distro = manifest.DISTRO_FEDORA
runner := &runner.Fedora{Version: 39}
_, err = img.InstantiateManifest(&mf, c.Repos, runner, rng)

return &mf, err
}

func pipelinesForDiskImage(c *ManifestConfig, rng *rand.Rand) (image.ImageKind, error) {
func manifestForDiskImage(c *ManifestConfig, rng *rand.Rand) (*manifest.Manifest, error) {
if c.Imgref == "" {
return nil, fmt.Errorf("pipeline: no base image defined")
}
ref := "ostree/1/1/0"
containerSource := container.SourceSpec{
Source: c.Imgref,
Name: c.Imgref,
TLSVerify: &c.TLSVerify,
}

img := image.NewOSTreeDiskImageFromContainer(containerSource, ref)
img.ContainerBuildable = true

var customizations *blueprint.Customizations
if c.Config != nil && c.Config.Blueprint != nil {
customizations = c.Config.Blueprint.Customizations
}

img := image.NewBootcDiskImage(containerSource)
img.Users = users.UsersFromBP(customizations.GetUsers())
img.Groups = users.GroupsFromBP(customizations.GetGroups())

Expand Down Expand Up @@ -120,8 +103,7 @@ func pipelinesForDiskImage(c *ManifestConfig, rng *rand.Rand) (image.ImageKind,
BasePlatform: platform.BasePlatform{
ImageFormat: imageFormat,
},
BIOS: true,
UEFIVendor: "fedora",
BIOS: true,
}
case arch.ARCH_AARCH64:
img.Platform = &platform.Aarch64{
Expand All @@ -133,14 +115,10 @@ func pipelinesForDiskImage(c *ManifestConfig, rng *rand.Rand) (image.ImageKind,
}
}

img.OSName = "default"

if kopts := customizations.GetKernel(); kopts != nil && kopts.Append != "" {
img.KernelOptionsAppend = append(img.KernelOptionsAppend, kopts.Append)
}

img.Workload = &NullWorkload{}

basept, ok := partitionTables[c.Architecture.String()]
if !ok {
return nil, fmt.Errorf("pipelines: no partition tables defined for %s", c.Architecture)
Expand All @@ -153,10 +131,22 @@ func pipelinesForDiskImage(c *ManifestConfig, rng *rand.Rand) (image.ImageKind,

img.Filename = filename

return img, nil
mf := manifest.New()
mf.Distro = manifest.DISTRO_FEDORA
runner := &runner.Fedora{Version: 39}
containerSources := []container.SourceSpec{
{
Source: c.Imgref,
Name: c.Imgref,
TLSVerify: &c.TLSVerify,
},
}
_, err = img.InstantiateManifestFromContainers(&mf, containerSources, runner, rng)

return &mf, err
}

func pipelinesForISO(c *ManifestConfig, rng *rand.Rand) (image.ImageKind, error) {
func manifestForISO(c *ManifestConfig, rng *rand.Rand) (*manifest.Manifest, error) {
if c.Imgref == "" {
return nil, fmt.Errorf("pipeline: no base image defined")
}
Expand Down Expand Up @@ -320,7 +310,11 @@ func pipelinesForISO(c *ManifestConfig, rng *rand.Rand) (image.ImageKind, error)
img.OSName = "default"
img.Filename = "install.iso"

return img, nil
mf := manifest.New()
mf.Distro = manifest.DISTRO_FEDORA
runner := &runner.Fedora{Version: 39}
_, err := img.InstantiateManifest(&mf, c.Repos, runner, rng)
return &mf, err
}

func createRand() *rand.Rand {
Expand Down
2 changes: 2 additions & 0 deletions bib/cmd/bootc-image-builder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ func run() error {
Args: cobra.ExactArgs(1),
DisableFlagsInUseLine: true,
RunE: cmdBuild,
SilenceUsage: true,
}
rootCmd.AddCommand(buildCmd)
manifestCmd := &cobra.Command{
Expand All @@ -307,6 +308,7 @@ func run() error {
Args: cobra.ExactArgs(1),
DisableFlagsInUseLine: true,
RunE: cmdManifest,
SilenceUsage: true,
}
rootCmd.AddCommand(manifestCmd)
manifestCmd.Flags().String("rpmmd", "/var/cache/osbuild/rpmmd", "rpm metadata cache directory")
Expand Down
37 changes: 28 additions & 9 deletions bib/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ module github.com/osbuild/bootc-image-builder/bib
go 1.19

require (
github.com/aws/aws-sdk-go v1.49.18
github.com/aws/aws-sdk-go v1.50.0
github.com/google/uuid v1.5.0
github.com/osbuild/images v0.29.0
github.com/osbuild/images v0.32.1-0.20240124173944-a8de56fabb8c
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5
Expand All @@ -14,16 +14,23 @@ require (
)

require (
dario.cat/mergo v1.0.0 // indirect
github.com/BurntSushi/toml v1.3.2 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/Microsoft/hcsshim v0.12.0-rc.1 // indirect
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/containerd/cgroups/v3 v3.0.2 // indirect
github.com/containerd/containerd v1.7.9 // indirect
github.com/containerd/stargz-snapshotter/estargz v0.15.1 // indirect
github.com/containers/common v0.57.1 // indirect
github.com/containers/image/v5 v5.29.0 // indirect
github.com/containers/image/v5 v5.29.1 // indirect
github.com/containers/libtrust v0.0.0-20230121012942-c1716e8a8d01 // indirect
github.com/containers/ocicrypt v1.1.9 // indirect
github.com/containers/storage v1.51.0 // indirect
github.com/cyberphone/json-canonicalization v0.0.0-20231011164504-785e29786b46 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/distribution/reference v0.5.0 // indirect
github.com/docker/distribution v2.8.3+incompatible // indirect
Expand All @@ -43,8 +50,11 @@ require (
github.com/go-openapi/swag v0.22.4 // indirect
github.com/go-openapi/validate v0.22.1 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-containerregistry v0.16.1 // indirect
github.com/google/go-intervals v0.0.2 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
Expand All @@ -58,8 +68,10 @@ require (
github.com/letsencrypt/boulder v0.0.0-20230213213521-fdfea0d469b6 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mattn/go-shellwords v1.0.12 // indirect
github.com/mattn/go-sqlite3 v1.14.18 // indirect
github.com/miekg/pkcs11 v1.1.1 // indirect
github.com/mistifyio/go-zfs/v3 v3.0.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/moby/sys/mountinfo v0.7.1 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
Expand All @@ -69,6 +81,8 @@ require (
github.com/opencontainers/image-spec v1.1.0-rc5 // indirect
github.com/opencontainers/runc v1.1.10 // indirect
github.com/opencontainers/runtime-spec v1.1.0 // indirect
github.com/opencontainers/selinux v1.11.0 // indirect
github.com/ostreedev/ostree-go v0.0.0-20210805093236-719684c64e4f // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/proglottis/gpgme v0.1.3 // indirect
Expand All @@ -78,22 +92,27 @@ require (
github.com/sigstore/rekor v1.2.2 // indirect
github.com/sigstore/sigstore v1.7.5 // indirect
github.com/stefanberger/go-pkcs11uri v0.0.0-20201008174630-78d3cae3a980 // indirect
github.com/sylabs/sif/v2 v2.15.0 // indirect
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 // indirect
github.com/tchap/go-patricia/v2 v2.3.1 // indirect
github.com/titanous/rocacheck v0.0.0-20171023193734-afe73141d399 // indirect
github.com/ulikunitz/xz v0.5.11 // indirect
github.com/vbatts/tar-split v0.11.5 // indirect
github.com/vbauerster/mpb/v8 v8.6.2 // indirect
go.mongodb.org/mongo-driver v1.11.3 // indirect
go.mozilla.org/pkcs7 v0.0.0-20210826202110-33d05740a352 // indirect
golang.org/x/crypto v0.17.0 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/mod v0.13.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/term v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231212172506-995d672761c0 // indirect
golang.org/x/tools v0.14.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240116215550-a9fa1716bcac // indirect
google.golang.org/grpc v1.60.1 // indirect
google.golang.org/protobuf v1.31.0 // indirect
google.golang.org/protobuf v1.32.0 // indirect
gopkg.in/go-jose/go-jose.v2 v2.6.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading

0 comments on commit 156a764

Please sign in to comment.