Skip to content

Commit

Permalink
osbuild: add ostree.deploy.container stage
Browse files Browse the repository at this point in the history
Creates an org.osbuild.ostree.deploy.container stage.
Validates the options with a regular expression that matches the schema.
Takes a container as input.  Validates the length of the input
references to be exactly 1.

See osbuild/osbuild#1402
  • Loading branch information
achilleas-k committed Nov 24, 2023
1 parent 420908d commit 4a61118
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions pkg/osbuild/ostree_deploy_container_stage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package osbuild

import (
"fmt"
"regexp"
)

const ostreeContainerTargetImgrefRegex = "^(ostree-remote-registry|ostree-image-signed|ostree-unverified-registry):.*$"

// Options for the org.osbuild.ostree.deploy.container stage.
type OSTreeDeployContainerStageOptions struct {

// Name of the stateroot to be used in the deployment
OsName string `json:"osname"`

// Additional kernel command line options
KernelOpts []string `json:"kernel_opts,omitempty"`

// Image ref used as the source of truth for updates
TargetImgref string `json:"target_imgref"`

// Identifier to locate the root file system (uuid or label)
Rootfs *Rootfs `json:"rootfs,omitempty"`

// Mount points of the final file system
Mounts []string `json:"mounts,omitempty"`
}

func (OSTreeDeployContainerStageOptions) isStageOptions() {}

func (options OSTreeDeployContainerStageOptions) validate() error {
exp := regexp.MustCompile(ostreeContainerTargetImgrefRegex)
if !exp.MatchString(options.TargetImgref) {
return fmt.Errorf("'target_imgref' %q doesn't conform to schema (%s)", options.TargetImgref, exp.String())
}
return nil
}

type OSTreeDeployContainerInputs struct {
Images ContainersInput `json:"images"`
}

func (OSTreeDeployContainerInputs) isStageInputs() {}

func (inputs OSTreeDeployContainerInputs) validate() error {
if ncontainers := inputs.Images.References.Len(); ncontainers != 1 {
return fmt.Errorf("stage requires exactly 1 input container (got %d)", ncontainers)
}
return nil
}

func NewOSTreeDeployContainerStage(options *OSTreeDeployContainerStageOptions, images ContainersInput) *Stage {
if err := options.validate(); err != nil {
panic(err)
}
inputs := OSTreeDeployContainerInputs{
Images: images,
}
if err := inputs.validate(); err != nil {
panic(err)
}
return &Stage{
Type: "org.osbuild.ostree.deploy.container",
Options: options,
Inputs: inputs,
}
}

0 comments on commit 4a61118

Please sign in to comment.