forked from osbuild/images
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
osbuild: add ostree.deploy.container stage
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
1 parent
420908d
commit 4a61118
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} | ||
} |