Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimal image builds #182

Merged
merged 13 commits into from
Oct 3, 2023
Merged
1 change: 1 addition & 0 deletions cmd/build/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type crBlueprint struct {
Containers []blueprint.Container `json:"containers,omitempty"`
Customizations *blueprint.Customizations `json:"customizations,omitempty"`
Distro string `json:"distro,omitempty"`
Minimal bool `json:"minimal,omitempty"`
}

type BuildConfig struct {
Expand Down
1 change: 1 addition & 0 deletions cmd/gen-manifests/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type crBlueprint struct {
Containers []blueprint.Container `json:"containers,omitempty"`
Customizations *blueprint.Customizations `json:"customizations,omitempty"`
Distro string `json:"distro,omitempty"`
Minimal bool `json:"minimal,omitempty"`
}

type buildRequest struct {
Expand Down
13 changes: 11 additions & 2 deletions internal/environment/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,18 @@ type Azure struct {
}

func (p *Azure) GetPackages() []string {
return []string{"WALinuxAgent"}
return []string{
"cloud-init",
thozza marked this conversation as resolved.
Show resolved Hide resolved
"WALinuxAgent",
}
}

func (p *Azure) GetServices() []string {
return []string{"waagent"}
return []string{
"cloud-init.service",
"cloud-config.service",
"cloud-final.service",
"cloud-init-local.service",
"waagent",
}
}
7 changes: 6 additions & 1 deletion internal/environment/ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,10 @@ func (p *EC2) GetPackages() []string {
}

func (p *EC2) GetServices() []string {
return []string{"cloud-init.service"}
return []string{
"cloud-init.service",
"cloud-config.service",
"cloud-final.service",
"cloud-init-local.service",
}
thozza marked this conversation as resolved.
Show resolved Hide resolved
}
21 changes: 21 additions & 0 deletions internal/environment/kvm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package environment

type KVM struct {
BaseEnvironment
}

func (e *KVM) GetPackages() []string {
return []string{
"cloud-init",
"qemu-guest-agent",
}
}

func (e *KVM) GetServices() []string {
return []string{
"cloud-init.service",
"cloud-config.service",
"cloud-final.service",
"cloud-init-local.service",
}
}
9 changes: 2 additions & 7 deletions pkg/blueprint/blueprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,9 @@ type Blueprint struct {
Containers []Container `json:"containers,omitempty" toml:"containers,omitempty"`
Customizations *Customizations `json:"customizations,omitempty" toml:"customizations"`
Distro string `json:"distro" toml:"distro"`
}

type Change struct {
Commit string `json:"commit" toml:"commit"`
Message string `json:"message" toml:"message"`
Revision *int `json:"revision" toml:"revision"`
Timestamp string `json:"timestamp" toml:"timestamp"`
Blueprint Blueprint `json:"-" toml:"-"`
// EXPERIMENTAL
Minimal bool `json:"minimal" toml:"minimal"`
}

// A Package specifies an RPM package.
Expand Down
13 changes: 4 additions & 9 deletions pkg/distro/fedora/distro.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,20 +233,15 @@ var (
}

qcow2ImgType = imageType{
name: "qcow2",
filename: "disk.qcow2",
mimeType: "application/x-qemu-disk",
name: "qcow2",
filename: "disk.qcow2",
mimeType: "application/x-qemu-disk",
environment: &environment.KVM{},
thozza marked this conversation as resolved.
Show resolved Hide resolved
packageSets: map[string]packageSetFunc{
osPkgsKey: qcow2CommonPackageSet,
},
defaultImageConfig: &distro.ImageConfig{
DefaultTarget: common.ToPtr("multi-user.target"),
EnabledServices: []string{
"cloud-init.service",
"cloud-config.service",
"cloud-final.service",
"cloud-init-local.service",
},
},
kernelOptions: cloudKernelOptions,
bootable: true,
Expand Down
36 changes: 22 additions & 14 deletions pkg/distro/fedora/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,20 +235,24 @@ func osCustomizations(

func diskImage(workload workload.Workload,
t *imageType,
customizations *blueprint.Customizations,
bp *blueprint.Blueprint,
options distro.ImageOptions,
packageSets map[string]rpmmd.PackageSet,
containers []container.SourceSpec,
rng *rand.Rand) (image.ImageKind, error) {

img := image.NewDiskImage()
img.Platform = t.platform
img.OSCustomizations = osCustomizations(t, packageSets[osPkgsKey], containers, customizations)
img.OSCustomizations = osCustomizations(t, packageSets[osPkgsKey], containers, bp.Customizations)
img.Environment = t.environment
img.Workload = workload
img.Compression = t.compression
if bp.Minimal {
// Disable weak dependencies if the 'minimal' option is enabled
img.InstallWeakDeps = common.ToPtr(false)
}
// TODO: move generation into LiveImage
pt, err := t.getPartitionTable(customizations.GetFilesystems(), options, rng)
pt, err := t.getPartitionTable(bp.Customizations.GetFilesystems(), options, rng)
if err != nil {
return nil, err
}
Expand All @@ -261,15 +265,15 @@ func diskImage(workload workload.Workload,

func containerImage(workload workload.Workload,
t *imageType,
c *blueprint.Customizations,
bp *blueprint.Blueprint,
options distro.ImageOptions,
packageSets map[string]rpmmd.PackageSet,
containers []container.SourceSpec,
rng *rand.Rand) (image.ImageKind, error) {
img := image.NewBaseContainer()

img.Platform = t.platform
img.OSCustomizations = osCustomizations(t, packageSets[osPkgsKey], containers, c)
img.OSCustomizations = osCustomizations(t, packageSets[osPkgsKey], containers, bp.Customizations)
img.Environment = t.environment
img.Workload = workload

Expand All @@ -280,7 +284,7 @@ func containerImage(workload workload.Workload,

func liveInstallerImage(workload workload.Workload,
t *imageType,
customizations *blueprint.Customizations,
bp *blueprint.Blueprint,
options distro.ImageOptions,
packageSets map[string]rpmmd.PackageSet,
containers []container.SourceSpec,
Expand All @@ -307,7 +311,7 @@ func liveInstallerImage(workload workload.Workload,

func imageInstallerImage(workload workload.Workload,
t *imageType,
customizations *blueprint.Customizations,
bp *blueprint.Blueprint,
options distro.ImageOptions,
packageSets map[string]rpmmd.PackageSet,
containers []container.SourceSpec,
Expand All @@ -327,6 +331,7 @@ func imageInstallerImage(workload workload.Workload,
}
img.AdditionalAnacondaModules = append(img.AdditionalAnacondaModules, "org.fedoraproject.Anaconda.Modules.Users")

customizations := bp.Customizations
img.Platform = t.platform
img.Workload = workload
img.OSCustomizations = osCustomizations(t, packageSets[osPkgsKey], containers, customizations)
Expand All @@ -351,7 +356,7 @@ func imageInstallerImage(workload workload.Workload,

func iotCommitImage(workload workload.Workload,
t *imageType,
customizations *blueprint.Customizations,
bp *blueprint.Blueprint,
options distro.ImageOptions,
packageSets map[string]rpmmd.PackageSet,
containers []container.SourceSpec,
Expand All @@ -363,7 +368,7 @@ func iotCommitImage(workload workload.Workload,
d := t.arch.distro

img.Platform = t.platform
img.OSCustomizations = osCustomizations(t, packageSets[osPkgsKey], containers, customizations)
img.OSCustomizations = osCustomizations(t, packageSets[osPkgsKey], containers, bp.Customizations)
if !common.VersionLessThan(d.Releasever(), "38") {
// see https://github.com/ostreedev/ostree/issues/2840
img.OSCustomizations.Presets = []osbuild.Preset{
Expand Down Expand Up @@ -393,7 +398,7 @@ func iotCommitImage(workload workload.Workload,

func iotContainerImage(workload workload.Workload,
t *imageType,
customizations *blueprint.Customizations,
bp *blueprint.Blueprint,
options distro.ImageOptions,
packageSets map[string]rpmmd.PackageSet,
containers []container.SourceSpec,
Expand All @@ -403,7 +408,7 @@ func iotContainerImage(workload workload.Workload,
img := image.NewOSTreeContainer(commitRef)
d := t.arch.distro
img.Platform = t.platform
img.OSCustomizations = osCustomizations(t, packageSets[osPkgsKey], containers, customizations)
img.OSCustomizations = osCustomizations(t, packageSets[osPkgsKey], containers, bp.Customizations)
if !common.VersionLessThan(d.Releasever(), "38") {
// see https://github.com/ostreedev/ostree/issues/2840
img.OSCustomizations.Presets = []osbuild.Preset{
Expand Down Expand Up @@ -434,7 +439,7 @@ func iotContainerImage(workload workload.Workload,

func iotInstallerImage(workload workload.Workload,
t *imageType,
customizations *blueprint.Customizations,
bp *blueprint.Blueprint,
options distro.ImageOptions,
packageSets map[string]rpmmd.PackageSet,
containers []container.SourceSpec,
Expand All @@ -449,6 +454,7 @@ func iotInstallerImage(workload workload.Workload,

img := image.NewAnacondaOSTreeInstaller(commit)

customizations := bp.Customizations
img.Platform = t.platform
img.ExtraBasePackages = packageSets[installerPkgsKey]
img.Users = users.UsersFromBP(customizations.GetUsers())
Expand All @@ -475,7 +481,7 @@ func iotInstallerImage(workload workload.Workload,

func iotImage(workload workload.Workload,
t *imageType,
customizations *blueprint.Customizations,
bp *blueprint.Blueprint,
options distro.ImageOptions,
packageSets map[string]rpmmd.PackageSet,
containers []container.SourceSpec,
Expand All @@ -489,6 +495,7 @@ func iotImage(workload workload.Workload,

distro := t.Arch().Distro()

customizations := bp.Customizations
img.Users = users.UsersFromBP(customizations.GetUsers())
img.Groups = users.GroupsFromBP(customizations.GetGroups())

Expand Down Expand Up @@ -551,7 +558,7 @@ func iotImage(workload workload.Workload,

func iotSimplifiedInstallerImage(workload workload.Workload,
t *imageType,
customizations *blueprint.Customizations,
bp *blueprint.Blueprint,
options distro.ImageOptions,
packageSets map[string]rpmmd.PackageSet,
containers []container.SourceSpec,
Expand All @@ -563,6 +570,7 @@ func iotSimplifiedInstallerImage(workload workload.Workload,
}
rawImg := image.NewOSTreeDiskImage(commit)

customizations := bp.Customizations
rawImg.Users = users.UsersFromBP(customizations.GetUsers())
rawImg.Groups = users.GroupsFromBP(customizations.GetGroups())

Expand Down
11 changes: 7 additions & 4 deletions pkg/distro/fedora/imagetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"golang.org/x/exp/slices"
)

type imageFunc func(workload workload.Workload, t *imageType, customizations *blueprint.Customizations, options distro.ImageOptions, packageSets map[string]rpmmd.PackageSet, containers []container.SourceSpec, rng *rand.Rand) (image.ImageKind, error)
type imageFunc func(workload workload.Workload, t *imageType, bp *blueprint.Blueprint, options distro.ImageOptions, packageSets map[string]rpmmd.PackageSet, containers []container.SourceSpec, rng *rand.Rand) (image.ImageKind, error)

type packageSetFunc func(t *imageType) rpmmd.PackageSet

Expand Down Expand Up @@ -174,8 +174,11 @@ func (t *imageType) Manifest(bp *blueprint.Blueprint,
// of the same name from the distro and arch
staticPackageSets := make(map[string]rpmmd.PackageSet)

for name, getter := range t.packageSets {
staticPackageSets[name] = getter(t)
// don't add any static packages if Minimal was selected
if !bp.Minimal {
for name, getter := range t.packageSets {
staticPackageSets[name] = getter(t)
}
}

// amend with repository information and collect payload repos
Expand Down Expand Up @@ -219,7 +222,7 @@ func (t *imageType) Manifest(bp *blueprint.Blueprint,
/* #nosec G404 */
rng := rand.New(source)

img, err := t.image(w, t, bp.Customizations, options, staticPackageSets, containerSources, rng)
img, err := t.image(w, t, bp, options, staticPackageSets, containerSources, rng)
if err != nil {
return nil, nil, err
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/image/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ type DiskImage struct {
OSProduct string
OSVersion string
OSNick string

// InstallWeakDeps enables installation of weak dependencies for packages
// that are statically defined for the payload pipeline of the image.
InstallWeakDeps *bool
}

func NewDiskImage() *DiskImage {
Expand All @@ -57,6 +61,9 @@ func (img *DiskImage) InstantiateManifest(m *manifest.Manifest,
osPipeline.OSProduct = img.OSProduct
osPipeline.OSVersion = img.OSVersion
osPipeline.OSNick = img.OSNick
if img.InstallWeakDeps != nil {
osPipeline.InstallWeakDeps = *img.InstallWeakDeps
}

rawImagePipeline := manifest.NewRawImage(buildPipeline, osPipeline)
rawImagePipeline.PartTool = img.PartTool
Expand Down
3 changes: 3 additions & 0 deletions pkg/manifest/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ type OS struct {
OSVersion string
OSNick string

// InstallWeakDeps enables installation of weak dependencies for packages
// that are statically defined for the pipeline.
// Defaults to True.
InstallWeakDeps bool
}

Expand Down
16 changes: 16 additions & 0 deletions test/config-map.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,21 @@
"centos*",
"fedora*"
]
},
"./configs/minimal.json": {
"image-types": [
"qcow2"
],
"distros": [
"fedora*"
]
},
"./configs/minimal-pkgs.json": {
"image-types": [
"qcow2"
],
"distros": [
"fedora*"
]
}
}
14 changes: 14 additions & 0 deletions test/configs/minimal-pkgs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "minimal-pkgs",
"blueprint": {
"minimal": true,
"packages": [
{
"name": "tmux"
},
{
"name": "vim-enhanced"
}
]
}
}
6 changes: 6 additions & 0 deletions test/configs/minimal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "minimal",
"blueprint": {
"minimal": true
}
}
Loading