-
Notifications
You must be signed in to change notification settings - Fork 47
/
coreos_installer.go
203 lines (176 loc) · 5.26 KB
/
coreos_installer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
package manifest
import (
"fmt"
"github.com/osbuild/images/internal/fdo"
"github.com/osbuild/images/internal/ignition"
"github.com/osbuild/images/pkg/container"
"github.com/osbuild/images/pkg/osbuild"
"github.com/osbuild/images/pkg/ostree"
"github.com/osbuild/images/pkg/platform"
"github.com/osbuild/images/pkg/rpmmd"
)
type CoreOSInstaller struct {
Base
// Packages to install or exclude in addition to the ones required by the
// pipeline.
ExtraPackages []string
ExcludePackages []string
// Extra repositories to install packages from
ExtraRepos []rpmmd.RepoConfig
platform platform.Platform
repos []rpmmd.RepoConfig
packageSpecs []rpmmd.PackageSpec
kernelName string
kernelVer string
product string
version string
Variant string
// Biosdevname indicates whether or not biosdevname should be used to
// name network devices when booting the installer. This may affect
// the naming of network devices on the target system.
Biosdevname bool
FDO *fdo.Options
// For the coreos-installer we only have EmbeddedOptions for ignition
Ignition *ignition.EmbeddedOptions
AdditionalDracutModules []string
}
// NewCoreOSInstaller creates an CoreOS installer pipeline object.
func NewCoreOSInstaller(m *Manifest,
buildPipeline *Build,
platform platform.Platform,
repos []rpmmd.RepoConfig,
kernelName,
product,
version string) *CoreOSInstaller {
name := "coi-tree"
p := &CoreOSInstaller{
Base: NewBase(m, name, buildPipeline),
platform: platform,
repos: filterRepos(repos, name),
kernelName: kernelName,
product: product,
version: version,
}
buildPipeline.addDependent(p)
m.addPipeline(p)
return p
}
// TODO: refactor:
// - what is required to boot and what to build?
// - do they all belong in this pipeline?
// - should these be moved to the platform for the image type?
func (p *CoreOSInstaller) getBootPackages() []string {
packages := []string{
"grub2-tools",
"grub2-tools-extra",
"grub2-tools-minimal",
"efibootmgr",
}
packages = append(packages, p.platform.GetPackages()...)
// TODO: Move these to the platform?
// For Fedora, this will add a lot of duplicates, but we also add them here
// for RHEL and CentOS.
switch p.platform.GetArch() {
case platform.ARCH_X86_64:
packages = append(packages,
"grub2-efi-x64",
"grub2-efi-x64-cdboot",
"grub2-pc",
"grub2-pc-modules",
"shim-x64",
"syslinux",
"syslinux-nonlinux",
)
case platform.ARCH_AARCH64:
packages = append(packages,
"grub2-efi-aa64-cdboot",
"grub2-efi-aa64",
"shim-aa64",
)
default:
panic(fmt.Sprintf("unsupported arch: %s", p.platform.GetArch()))
}
if p.Biosdevname {
packages = append(packages, "biosdevname")
}
return packages
}
func (p *CoreOSInstaller) getBuildPackages(Distro) []string {
packages := p.getBootPackages()
packages = append(packages,
"rpm",
"lorax-templates-generic",
)
return packages
}
func (p *CoreOSInstaller) getPackageSetChain(Distro) []rpmmd.PackageSet {
packages := p.getBootPackages()
return []rpmmd.PackageSet{
{
Include: append(packages, p.ExtraPackages...),
Exclude: p.ExcludePackages,
Repositories: append(p.repos, p.ExtraRepos...),
InstallWeakDeps: true,
},
}
}
func (p *CoreOSInstaller) getPackageSpecs() []rpmmd.PackageSpec {
return p.packageSpecs
}
func (p *CoreOSInstaller) serializeStart(packages []rpmmd.PackageSpec, _ []container.Spec, _ []ostree.CommitSpec) {
if len(p.packageSpecs) > 0 {
panic("double call to serializeStart()")
}
p.packageSpecs = packages
if p.kernelName != "" {
p.kernelVer = rpmmd.GetVerStrFromPackageSpecListPanic(p.packageSpecs, p.kernelName)
}
}
func (p *CoreOSInstaller) getInline() []string {
inlineData := []string{}
// inline data for FDO cert
if p.FDO != nil && p.FDO.DiunPubKeyRootCerts != "" {
inlineData = append(inlineData, p.FDO.DiunPubKeyRootCerts)
}
// inline data for ignition embedded (url or data)
if p.Ignition != nil {
if p.Ignition.Config != "" {
inlineData = append(inlineData, p.Ignition.Config)
}
}
return inlineData
}
func (p *CoreOSInstaller) serializeEnd() {
if len(p.packageSpecs) == 0 {
panic("serializeEnd() call when serialization not in progress")
}
p.kernelVer = ""
p.packageSpecs = nil
}
func (p *CoreOSInstaller) serialize() osbuild.Pipeline {
pipeline := p.Base.serialize()
pipeline.AddStage(osbuild.NewRPMStage(osbuild.NewRPMStageOptions(p.repos), osbuild.NewRpmStageSourceFilesInputs(p.packageSpecs)))
pipeline.AddStage(osbuild.NewBuildstampStage(&osbuild.BuildstampStageOptions{
Arch: p.platform.GetArch().String(),
Product: p.product,
Variant: p.Variant,
Version: p.version,
Final: true,
}))
pipeline.AddStage(osbuild.NewLocaleStage(&osbuild.LocaleStageOptions{Language: "C.UTF-8"}))
dracutModules := append(
p.AdditionalDracutModules,
"coreos-installer",
"fdo",
)
dracutStageOptions := dracutStageOptions(p.kernelVer, p.Biosdevname, dracutModules)
if p.FDO != nil && p.FDO.DiunPubKeyRootCerts != "" {
pipeline.AddStage(osbuild.NewFDOStageForRootCerts(p.FDO.DiunPubKeyRootCerts))
dracutStageOptions.Install = []string{"/fdo_diun_pub_key_root_certs.pem"}
}
pipeline.AddStage(osbuild.NewDracutStage(dracutStageOptions))
return pipeline
}
func (p *CoreOSInstaller) Platform() platform.Platform {
return p.platform
}