Skip to content

Commit 5d27c1d

Browse files
authored
feat: support kiwi image profiles (#433)
1 parent 357f8e3 commit 5d27c1d

6 files changed

Lines changed: 52 additions & 4 deletions

File tree

internal/app/azldev/cmds/image/build.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func BuildImage(env *azldev.Env, options *ImageBuildOptions) (*ImageBuildResult,
143143
}
144144

145145
// Run kiwi to build the image into the work directory.
146-
kiwiRunner, err := createKiwiRunner(env, kiwiDefPath, kiwiWorkDir, options)
146+
kiwiRunner, err := createKiwiRunner(env, imageConfig, kiwiWorkDir, options)
147147
if err != nil {
148148
return nil, err
149149
}
@@ -181,13 +181,18 @@ func checkBuildPrerequisites(env *azldev.Env) error {
181181
// createKiwiRunner sets up a kiwi runner with the configured repositories.
182182
func createKiwiRunner(
183183
env *azldev.Env,
184-
kiwiDefPath, targetDir string,
184+
imageConfig *projectconfig.ImageConfig,
185+
targetDir string,
185186
options *ImageBuildOptions,
186187
) (*kiwi.Runner, error) {
187-
runner := kiwi.NewRunner(env, filepath.Dir(kiwiDefPath)).
188+
runner := kiwi.NewRunner(env, filepath.Dir(imageConfig.Definition.Path)).
188189
WithTargetDir(targetDir).
189190
WithRemoteRepoGPGCheck(!options.NoRemoteRepoGpgCheck)
190191

192+
if imageConfig.Definition.Profile != "" {
193+
runner.WithProfile(imageConfig.Definition.Profile)
194+
}
195+
191196
for _, repoURI := range options.RemoteRepoPaths {
192197
if err := runner.AddRemoteRepo(repoURI); err != nil {
193198
return nil, fmt.Errorf("invalid remote repository:\n%w", err)

internal/projectconfig/image.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ type ImageDefinition struct {
3333

3434
// Path points to the image definition file.
3535
Path string `toml:"path,omitempty" json:"path,omitempty" jsonschema:"title=Path,description=Path to the image definition file"`
36+
37+
// Profile is an optional field that specifies the profile to use when building the image.
38+
Profile string `toml:"profile,omitempty" json:"profile,omitempty" jsonschema:"title=Profile,description=Optional field that specifies the profile to use when building the image"`
3639
}
3740

3841
// Type of image definition.

internal/utils/kiwi/kiwi.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ type Runner struct {
6666
// remoteRepoGPGCheck controls whether GPG checking is enabled for remote repositories.
6767
// Defaults to true.
6868
remoteRepoGPGCheck bool
69+
70+
// profile is the optional kiwi profile to use when building the image.
71+
profile string
6972
}
7073

7174
// NewRunner constructs a new [Runner] that can be used to invoke kiwi-ng.
@@ -77,6 +80,7 @@ func NewRunner(ctx opctx.Ctx, descriptionDir string) *Runner {
7780
verbose: ctx.Verbose(),
7881
descriptionDir: descriptionDir,
7982
remoteRepoGPGCheck: true, // GPG checking enabled by default
83+
profile: "",
8084
}
8185
}
8286

@@ -91,6 +95,7 @@ func (r *Runner) Clone() *Runner {
9195
localRepoPaths: deep.MustCopy(r.localRepoPaths),
9296
remoteRepoPaths: deep.MustCopy(r.remoteRepoPaths),
9397
remoteRepoGPGCheck: r.remoteRepoGPGCheck,
98+
profile: r.profile,
9499
}
95100
}
96101

@@ -109,6 +114,13 @@ func (r *Runner) WithRemoteRepoGPGCheck(enabled bool) *Runner {
109114
return r
110115
}
111116

117+
// WithProfile sets the profile that kiwi will use to build the image.
118+
func (r *Runner) WithProfile(profile string) *Runner {
119+
r.profile = profile
120+
121+
return r
122+
}
123+
112124
// RemoteRepoGPGCheck returns whether GPG checking is enabled for remote repositories.
113125
func (r *Runner) RemoteRepoGPGCheck() bool {
114126
return r.remoteRepoGPGCheck
@@ -167,6 +179,11 @@ func (r *Runner) DescriptionDir() string {
167179
return r.descriptionDir
168180
}
169181

182+
// Profile retrieves the kiwi profile configured for this [Runner].
183+
func (r *Runner) Profile() string {
184+
return r.profile
185+
}
186+
170187
// Build invokes kiwi-ng via sudo to build an image.
171188
func (r *Runner) Build(ctx context.Context) error {
172189
if r.descriptionDir == "" {
@@ -189,10 +206,17 @@ func (r *Runner) Build(ctx context.Context) error {
189206
kiwiArgs := []string{
190207
KiwiBinary,
191208
"--loglevel", logLevel,
209+
}
210+
211+
if r.profile != "" {
212+
kiwiArgs = append(kiwiArgs, "--profile", r.profile)
213+
}
214+
215+
kiwiArgs = append(kiwiArgs,
192216
"system", "build",
193217
"--description", r.descriptionDir,
194218
"--target-dir", r.targetDir,
195-
}
219+
)
196220

197221
// Add remote repositories using kiwi's --add-repo flag.
198222
// These have lower priority (50) than local repos so local repos can override.
@@ -235,6 +259,7 @@ func (r *Runner) Build(ctx context.Context) error {
235259

236260
slog.Info("Building image with kiwi-ng",
237261
"description", r.descriptionDir,
262+
"profile", r.profile,
238263
"output", r.targetDir,
239264
)
240265

scenario/__snapshots__/TestSnapshotsContainer_config_generate-schema_stdout_1.snap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,11 @@
376376
"type": "string",
377377
"title": "Path",
378378
"description": "Path to the image definition file"
379+
},
380+
"profile": {
381+
"type": "string",
382+
"title": "Profile",
383+
"description": "Optional field that specifies the profile to use when building the image"
379384
}
380385
},
381386
"additionalProperties": false,

scenario/__snapshots__/TestSnapshots_config_generate-schema_stdout_1.snap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,11 @@
376376
"type": "string",
377377
"title": "Path",
378378
"description": "Path to the image definition file"
379+
},
380+
"profile": {
381+
"type": "string",
382+
"title": "Profile",
383+
"description": "Optional field that specifies the profile to use when building the image"
379384
}
380385
},
381386
"additionalProperties": false,

schemas/azldev.schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,11 @@
376376
"type": "string",
377377
"title": "Path",
378378
"description": "Path to the image definition file"
379+
},
380+
"profile": {
381+
"type": "string",
382+
"title": "Profile",
383+
"description": "Optional field that specifies the profile to use when building the image"
379384
}
380385
},
381386
"additionalProperties": false,

0 commit comments

Comments
 (0)