osbuild: add support for the first-boot stage

This commit is contained in:
sanne raymaekers 2020-06-19 11:13:45 +02:00 committed by Lars Karlitski
parent 6bab73f378
commit 96c1de9f98
4 changed files with 58 additions and 2 deletions

View file

@ -83,8 +83,9 @@ type ImageType interface {
// The ImageOptions specify options for a specific image build
type ImageOptions struct {
OSTree OSTreeImageOptions
Size uint64
OSTree OSTreeImageOptions
Size uint64
Subscription *SubscriptionImageOptions
}
// The OSTreeImageOptions specify ostree-specific image options
@ -93,6 +94,15 @@ type OSTreeImageOptions struct {
Parent string
}
// The SubscriptionImageOptions specify subscription-specific image options
type SubscriptionImageOptions struct {
Organization int
ActivationKey string
ServerUrl string
BaseUrl string
Insights bool
}
// A Manifest is an opaque JSON object, which is a valid input to osbuild
type Manifest []byte

View file

@ -310,6 +310,21 @@ func (t *imageType) pipeline(c *blueprint.Customizations, options distro.ImageOp
}))
}
if options.Subscription != nil {
commands := []string{
fmt.Sprintf("/usr/sbin/subscription-manager register --org=%d --activationkey=%s --serverurl %s --baseurl %s", options.Subscription.Organization, options.Subscription.ActivationKey, options.Subscription.ServerUrl, options.Subscription.BaseUrl),
}
if options.Subscription.Insights {
commands = append(commands, "/usr/bin/insights-client --register")
}
p.AddStage(osbuild.NewFirstBootStage(&osbuild.FirstBootStageOptions{
Commands: commands,
WaitForNetwork: true,
},
))
}
p.Assembler = t.assembler(t.arch.uefi, options, t.arch)
return p, nil

View file

@ -0,0 +1,15 @@
package osbuild
type FirstBootStageOptions struct {
Commands []string `json:"commands"`
WaitForNetwork bool `json:"wait_for_network,omitempty"`
}
func (FirstBootStageOptions) isStageOptions() {}
func NewFirstBootStage(options *FirstBootStageOptions) *Stage {
return &Stage{
Name: "org.osbuild.first-boot",
Options: options,
}
}

View file

@ -0,0 +1,16 @@
package osbuild
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestNewFirstBootStage(t *testing.T) {
expectedStage := &Stage{
Name: "org.osbuild.first-boot",
Options: &FirstBootStageOptions{},
}
actualStage := NewFirstBootStage(&FirstBootStageOptions{})
assert.Equal(t, expectedStage, actualStage)
}