ostree: define type for handling ostree remote config

A new struct in ostree can be used to define configuration options for
the ostree remote of an image.  So far remotes were always set up with
the remote URL used to pull the commit.  Now we support setting a
different remote with extra configuration options.

This is used by the fedora-iot-raw-image to set up the remote
configuration of the final image, separately from the source of the
commit.

Test manifests updated.
This commit is contained in:
Achilleas Koutsou 2022-08-23 18:44:09 +02:00 committed by Tom Gundersen
parent 0386d68db4
commit 1de55c73e6
10 changed files with 70 additions and 25 deletions

View file

@ -8,6 +8,7 @@ import (
"github.com/osbuild/osbuild-composer/internal/image" "github.com/osbuild/osbuild-composer/internal/image"
"github.com/osbuild/osbuild-composer/internal/manifest" "github.com/osbuild/osbuild-composer/internal/manifest"
"github.com/osbuild/osbuild-composer/internal/osbuild" "github.com/osbuild/osbuild-composer/internal/osbuild"
"github.com/osbuild/osbuild-composer/internal/ostree"
"github.com/osbuild/osbuild-composer/internal/rpmmd" "github.com/osbuild/osbuild-composer/internal/rpmmd"
"github.com/osbuild/osbuild-composer/internal/workload" "github.com/osbuild/osbuild-composer/internal/workload"
) )
@ -290,7 +291,12 @@ func iotRawImage(workload workload.Workload,
img.Platform = t.platform img.Platform = t.platform
img.Workload = workload img.Workload = workload
img.Remote = "fedora-iot" img.Remote = ostree.Remote{
Name: "fedora-iot",
URL: "https://ostree.fedoraproject.org/iot",
ContentURL: "mirrorlist=https://ostree.fedoraproject.org/iot/mirrorlist",
GPGKeyPaths: []string{"/etc/pki/rpm-gpg/"},
}
img.OSName = "fedora-iot" img.OSName = "fedora-iot"
img.OSTreeURL = options.OSTree.URL img.OSTreeURL = options.OSTree.URL

View file

@ -6,6 +6,7 @@ import (
"github.com/osbuild/osbuild-composer/internal/artifact" "github.com/osbuild/osbuild-composer/internal/artifact"
"github.com/osbuild/osbuild-composer/internal/disk" "github.com/osbuild/osbuild-composer/internal/disk"
"github.com/osbuild/osbuild-composer/internal/manifest" "github.com/osbuild/osbuild-composer/internal/manifest"
"github.com/osbuild/osbuild-composer/internal/ostree"
"github.com/osbuild/osbuild-composer/internal/platform" "github.com/osbuild/osbuild-composer/internal/platform"
"github.com/osbuild/osbuild-composer/internal/rpmmd" "github.com/osbuild/osbuild-composer/internal/rpmmd"
"github.com/osbuild/osbuild-composer/internal/runner" "github.com/osbuild/osbuild-composer/internal/runner"
@ -23,7 +24,7 @@ type OSTreeRawImage struct {
OSTreeRef string OSTreeRef string
OSTreeCommit string OSTreeCommit string
Remote string Remote ostree.Remote
OSName string OSName string
KernelOptionsAppend []string KernelOptionsAppend []string
@ -46,8 +47,9 @@ func (img *OSTreeRawImage) InstantiateManifest(m *manifest.Manifest,
buildPipeline := manifest.NewBuild(m, runner, repos) buildPipeline := manifest.NewBuild(m, runner, repos)
buildPipeline.Checkpoint() buildPipeline.Checkpoint()
osPipeline := manifest.NewOSTreeDeployment(m, buildPipeline, img.OSTreeRef, img.OSTreeCommit, img.OSTreeURL, img.OSName, img.Remote, img.Platform) osPipeline := manifest.NewOSTreeDeployment(m, buildPipeline, img.OSTreeRef, img.OSTreeCommit, img.OSTreeURL, img.OSName, img.Platform)
osPipeline.PartitionTable = img.PartitionTable osPipeline.PartitionTable = img.PartitionTable
osPipeline.Remote = img.Remote
osPipeline.KernelOptionsAppend = img.KernelOptionsAppend osPipeline.KernelOptionsAppend = img.KernelOptionsAppend
osPipeline.Keyboard = img.Keyboard osPipeline.Keyboard = img.Keyboard
osPipeline.Locale = img.Locale osPipeline.Locale = img.Locale

View file

@ -6,6 +6,7 @@ import (
"github.com/osbuild/osbuild-composer/internal/common" "github.com/osbuild/osbuild-composer/internal/common"
"github.com/osbuild/osbuild-composer/internal/disk" "github.com/osbuild/osbuild-composer/internal/disk"
"github.com/osbuild/osbuild-composer/internal/osbuild" "github.com/osbuild/osbuild-composer/internal/osbuild"
"github.com/osbuild/osbuild-composer/internal/ostree"
"github.com/osbuild/osbuild-composer/internal/platform" "github.com/osbuild/osbuild-composer/internal/platform"
) )
@ -14,6 +15,8 @@ import (
type OSTreeDeployment struct { type OSTreeDeployment struct {
Base Base
Remote ostree.Remote
OSVersion string OSVersion string
osTreeCommit string osTreeCommit string
@ -21,7 +24,6 @@ type OSTreeDeployment struct {
osTreeRef string osTreeRef string
osName string osName string
remote string
KernelOptionsAppend []string KernelOptionsAppend []string
Keyboard string Keyboard string
@ -40,7 +42,6 @@ func NewOSTreeDeployment(m *Manifest,
commit string, commit string,
url string, url string,
osName string, osName string,
remote string,
platform platform.Platform) *OSTreeDeployment { platform platform.Platform) *OSTreeDeployment {
p := &OSTreeDeployment{ p := &OSTreeDeployment{
@ -49,7 +50,6 @@ func NewOSTreeDeployment(m *Manifest,
osTreeURL: url, osTreeURL: url,
osTreeRef: ref, osTreeRef: ref,
osName: osName, osName: osName,
remote: remote,
platform: platform, platform: platform,
} }
buildPipeline.addDependent(p) buildPipeline.addDependent(p)
@ -80,7 +80,7 @@ func (p *OSTreeDeployment) serialize() osbuild.Pipeline {
pipeline.AddStage(osbuild.OSTreeInitFsStage()) pipeline.AddStage(osbuild.OSTreeInitFsStage())
pipeline.AddStage(osbuild.NewOSTreePullStage( pipeline.AddStage(osbuild.NewOSTreePullStage(
&osbuild.OSTreePullStageOptions{Repo: repoPath, Remote: p.remote}, &osbuild.OSTreePullStageOptions{Repo: repoPath, Remote: p.Remote.Name},
osbuild.NewOstreePullStageInputs("org.osbuild.source", p.osTreeCommit, p.osTreeRef), osbuild.NewOstreePullStageInputs("org.osbuild.source", p.osTreeCommit, p.osTreeRef),
)) ))
pipeline.AddStage(osbuild.NewOSTreeOsInitStage( pipeline.AddStage(osbuild.NewOSTreeOsInitStage(
@ -114,7 +114,7 @@ func (p *OSTreeDeployment) serialize() osbuild.Pipeline {
&osbuild.OSTreeDeployStageOptions{ &osbuild.OSTreeDeployStageOptions{
OsName: p.osName, OsName: p.osName,
Ref: p.osTreeRef, Ref: p.osTreeRef,
Remote: p.remote, Remote: p.Remote.Name,
Mounts: []string{"/boot", "/boot/efi"}, Mounts: []string{"/boot", "/boot/efi"},
Rootfs: osbuild.Rootfs{ Rootfs: osbuild.Rootfs{
Label: "root", Label: "root",
@ -123,19 +123,24 @@ func (p *OSTreeDeployment) serialize() osbuild.Pipeline {
}, },
)) ))
if p.osTreeURL != "" { // TODO: this should never be empty; fail early instead remoteURL := p.Remote.URL
pipeline.AddStage(osbuild.NewOSTreeRemotesStage( if remoteURL == "" {
&osbuild.OSTreeRemotesStageOptions{ // if the remote URL for the image is not specified, use the source commit URL
Repo: "/ostree/repo", remoteURL = p.osTreeURL
Remotes: []osbuild.OSTreeRemote{ }
{ pipeline.AddStage(osbuild.NewOSTreeRemotesStage(
Name: p.remote, &osbuild.OSTreeRemotesStageOptions{
URL: p.osTreeURL, Repo: "/ostree/repo",
}, Remotes: []osbuild.OSTreeRemote{
{
Name: p.Remote.Name,
URL: remoteURL,
ContentURL: p.Remote.ContentURL,
GPGKeyPaths: p.Remote.GPGKeyPaths,
}, },
}, },
)) },
} ))
pipeline.AddStage(osbuild.NewOSTreeFillvarStage( pipeline.AddStage(osbuild.NewOSTreeFillvarStage(
&osbuild.OSTreeFillvarStageOptions{ &osbuild.OSTreeFillvarStageOptions{

View file

@ -24,6 +24,14 @@ type CommitSource struct {
URL string URL string
} }
// Remote defines the options that can be set for an OSTree Remote configuration.
type Remote struct {
Name string
URL string
ContentURL string
GPGKeyPaths []string
}
func VerifyRef(ref string) bool { func VerifyRef(ref string) bool {
return len(ref) > 0 && ostreeRefRE.MatchString(ref) return len(ref) > 0 && ostreeRefRE.MatchString(ref)
} }

View file

@ -1843,7 +1843,11 @@
"remotes": [ "remotes": [
{ {
"name": "fedora-iot", "name": "fedora-iot",
"url": "http://fedora.example.com/repo" "url": "https://ostree.fedoraproject.org/iot",
"contenturl": "mirrorlist=https://ostree.fedoraproject.org/iot/mirrorlist",
"gpgkeypaths": [
"/etc/pki/rpm-gpg/"
]
} }
] ]
} }

View file

@ -1867,7 +1867,11 @@
"remotes": [ "remotes": [
{ {
"name": "fedora-iot", "name": "fedora-iot",
"url": "http://fedora.example.com/repo" "url": "https://ostree.fedoraproject.org/iot",
"contenturl": "mirrorlist=https://ostree.fedoraproject.org/iot/mirrorlist",
"gpgkeypaths": [
"/etc/pki/rpm-gpg/"
]
} }
] ]
} }

View file

@ -2091,7 +2091,11 @@
"remotes": [ "remotes": [
{ {
"name": "fedora-iot", "name": "fedora-iot",
"url": "http://fedora.example.com/repo" "url": "https://ostree.fedoraproject.org/iot",
"contenturl": "mirrorlist=https://ostree.fedoraproject.org/iot/mirrorlist",
"gpgkeypaths": [
"/etc/pki/rpm-gpg/"
]
} }
] ]
} }

View file

@ -2115,7 +2115,11 @@
"remotes": [ "remotes": [
{ {
"name": "fedora-iot", "name": "fedora-iot",
"url": "http://fedora.example.com/repo" "url": "https://ostree.fedoraproject.org/iot",
"contenturl": "mirrorlist=https://ostree.fedoraproject.org/iot/mirrorlist",
"gpgkeypaths": [
"/etc/pki/rpm-gpg/"
]
} }
] ]
} }

View file

@ -2099,7 +2099,11 @@
"remotes": [ "remotes": [
{ {
"name": "fedora-iot", "name": "fedora-iot",
"url": "http://fedora.example.com/repo" "url": "https://ostree.fedoraproject.org/iot",
"contenturl": "mirrorlist=https://ostree.fedoraproject.org/iot/mirrorlist",
"gpgkeypaths": [
"/etc/pki/rpm-gpg/"
]
} }
] ]
} }

View file

@ -2123,7 +2123,11 @@
"remotes": [ "remotes": [
{ {
"name": "fedora-iot", "name": "fedora-iot",
"url": "http://fedora.example.com/repo" "url": "https://ostree.fedoraproject.org/iot",
"contenturl": "mirrorlist=https://ostree.fedoraproject.org/iot/mirrorlist",
"gpgkeypaths": [
"/etc/pki/rpm-gpg/"
]
} }
] ]
} }