@@ -96,6 +96,16 @@ const (
9696// The value of this string is inserted during compilation via a linker flag.
9797var ToolVersion = ""
9898
99+ type ImageCustomizerOptions struct {
100+ BuildDir string
101+ InputImageFile string
102+ RpmsSources []string
103+ OutputImageFile string
104+ OutputImageFormat string
105+ UseBaseImageRpmRepos bool
106+ PackageSnapshotTime string
107+ }
108+
99109type ImageCustomizerParameters struct {
100110 // build dirs
101111 buildDirAbs string
@@ -147,27 +157,24 @@ type verityDeviceMetadata struct {
147157 hashSignaturePath string
148158}
149159
150- func createImageCustomizerParameters (ctx context.Context , buildDir string ,
151- inputImageFile string ,
152- configPath string , config * imagecustomizerapi.Config ,
153- useBaseImageRpmRepos bool , rpmsSources []string ,
154- outputImageFormat string , outputImageFile string , packageSnapshotTime string ,
160+ func createImageCustomizerParameters (ctx context.Context , configPath string , config * imagecustomizerapi.Config ,
161+ options ImageCustomizerOptions ,
155162) (* ImageCustomizerParameters , error ) {
156163 _ , span := otel .GetTracerProvider ().Tracer (OtelTracerName ).Start (ctx , "create_image_customizer_parameters" )
157164 defer span .End ()
158165
159166 ic := & ImageCustomizerParameters {}
160167
161168 // working directories
162- buildDirAbs , err := filepath .Abs (buildDir )
169+ buildDirAbs , err := filepath .Abs (options . BuildDir )
163170 if err != nil {
164171 return nil , err
165172 }
166173
167174 ic .buildDirAbs = buildDirAbs
168175
169176 // input image
170- ic .inputImageFile = inputImageFile
177+ ic .inputImageFile = options . InputImageFile
171178 if ic .inputImageFile == "" && config .Input .Image .Path != "" {
172179 ic .inputImageFile = file .GetAbsPathWithBase (configPath , config .Input .Image .Path )
173180 }
@@ -190,10 +197,10 @@ func createImageCustomizerParameters(ctx context.Context, buildDir string,
190197 len (config .Scripts .PostCustomization ) > 0 ||
191198 len (config .Scripts .FinalizeCustomization ) > 0
192199
193- ic .useBaseImageRpmRepos = useBaseImageRpmRepos
194- ic .rpmsSources = rpmsSources
200+ ic .useBaseImageRpmRepos = options . UseBaseImageRpmRepos
201+ ic .rpmsSources = options . RpmsSources
195202
196- err = ValidateRpmSources (rpmsSources )
203+ err = ValidateRpmSources (options . RpmsSources )
197204 if err != nil {
198205 return nil , err
199206 }
@@ -202,16 +209,16 @@ func createImageCustomizerParameters(ctx context.Context, buildDir string,
202209 ic .rawImageFile = filepath .Join (buildDirAbs , BaseImageName )
203210
204211 // output image
205- ic .outputImageFormat = imagecustomizerapi .ImageFormatType (outputImageFormat )
212+ ic .outputImageFormat = imagecustomizerapi .ImageFormatType (options . OutputImageFormat )
206213 if err := ic .outputImageFormat .IsValid (); err != nil {
207- return nil , fmt .Errorf ("%w (format='%s'):\n %w" , ErrInvalidOutputFormat , outputImageFormat , err )
214+ return nil , fmt .Errorf ("%w (format='%s'):\n %w" , ErrInvalidOutputFormat , options . OutputImageFormat , err )
208215 }
209216
210217 if ic .outputImageFormat == "" {
211218 ic .outputImageFormat = config .Output .Image .Format
212219 }
213220
214- ic .outputImageFile = outputImageFile
221+ ic .outputImageFile = options . OutputImageFile
215222 if ic .outputImageFile == "" && config .Output .Image .Path != "" {
216223 ic .outputImageFile = file .GetAbsPathWithBase (configPath , config .Output .Image .Path )
217224 }
@@ -237,7 +244,7 @@ func createImageCustomizerParameters(ctx context.Context, buildDir string,
237244 }
238245 }
239246
240- ic .packageSnapshotTime = packageSnapshotTime
247+ ic .packageSnapshotTime = options . PackageSnapshotTime
241248
242249 return ic , nil
243250}
@@ -246,6 +253,18 @@ func CustomizeImageWithConfigFile(ctx context.Context, buildDir string, configFi
246253 rpmsSources []string , outputImageFile string , outputImageFormat string ,
247254 useBaseImageRpmRepos bool , packageSnapshotTime string ,
248255) error {
256+ return CustomizeImageWithConfigFileOptions (ctx , configFile , ImageCustomizerOptions {
257+ BuildDir : buildDir ,
258+ InputImageFile : inputImageFile ,
259+ RpmsSources : rpmsSources ,
260+ OutputImageFile : outputImageFile ,
261+ OutputImageFormat : outputImageFormat ,
262+ UseBaseImageRpmRepos : useBaseImageRpmRepos ,
263+ PackageSnapshotTime : packageSnapshotTime ,
264+ })
265+ }
266+
267+ func CustomizeImageWithConfigFileOptions (ctx context.Context , configFile string , options ImageCustomizerOptions ) error {
249268 var err error
250269
251270 var config imagecustomizerapi.Config
@@ -262,8 +281,7 @@ func CustomizeImageWithConfigFile(ctx context.Context, buildDir string, configFi
262281 return fmt .Errorf ("%w:\n %w" , ErrGetAbsoluteConfigPath , err )
263282 }
264283
265- err = CustomizeImage (ctx , buildDir , absBaseConfigPath , & config , inputImageFile , rpmsSources , outputImageFile , outputImageFormat ,
266- useBaseImageRpmRepos , packageSnapshotTime )
284+ err = CustomizeImageOptions (ctx , absBaseConfigPath , & config , options )
267285 if err != nil {
268286 return err
269287 }
@@ -280,13 +298,27 @@ func cleanUp(ic *ImageCustomizerParameters) error {
280298 return nil
281299}
282300
283- func CustomizeImage (ctx context.Context , buildDir string , baseConfigPath string , config * imagecustomizerapi.Config , inputImageFile string ,
284- rpmsSources []string , outputImageFile string , outputImageFormat string ,
301+ func CustomizeImage (ctx context.Context , buildDir string , baseConfigPath string , config * imagecustomizerapi.Config ,
302+ inputImageFile string , rpmsSources []string , outputImageFile string , outputImageFormat string ,
285303 useBaseImageRpmRepos bool , packageSnapshotTime string ,
304+ ) (err error ) {
305+ return CustomizeImageOptions (ctx , baseConfigPath , config , ImageCustomizerOptions {
306+ BuildDir : buildDir ,
307+ InputImageFile : inputImageFile ,
308+ RpmsSources : rpmsSources ,
309+ OutputImageFile : outputImageFile ,
310+ OutputImageFormat : outputImageFormat ,
311+ UseBaseImageRpmRepos : useBaseImageRpmRepos ,
312+ PackageSnapshotTime : packageSnapshotTime ,
313+ })
314+ }
315+
316+ func CustomizeImageOptions (ctx context.Context , baseConfigPath string , config * imagecustomizerapi.Config ,
317+ options ImageCustomizerOptions ,
286318) (err error ) {
287319 ctx , span := otel .GetTracerProvider ().Tracer (OtelTracerName ).Start (ctx , "customize_image" )
288320 span .SetAttributes (
289- attribute .String ("output_image_format" , string (outputImageFormat )),
321+ attribute .String ("output_image_format" , string (options . OutputImageFormat )),
290322 )
291323 defer func () {
292324 if err != nil {
@@ -305,14 +337,12 @@ func CustomizeImage(ctx context.Context, buildDir string, baseConfigPath string,
305337 span .End ()
306338 }()
307339
308- err = ValidateConfig (ctx , baseConfigPath , config , inputImageFile , rpmsSources , outputImageFile , outputImageFormat , useBaseImageRpmRepos , packageSnapshotTime , false )
340+ err = ValidateConfig (ctx , baseConfigPath , config , false , options )
309341 if err != nil {
310342 return fmt .Errorf ("%w:\n %w" , ErrInvalidImageConfig , err )
311343 }
312344
313- imageCustomizerParameters , err := createImageCustomizerParameters (ctx , buildDir , inputImageFile ,
314- baseConfigPath , config , useBaseImageRpmRepos , rpmsSources ,
315- outputImageFormat , outputImageFile , packageSnapshotTime )
345+ imageCustomizerParameters , err := createImageCustomizerParameters (ctx , baseConfigPath , config , options )
316346 if err != nil {
317347 return fmt .Errorf ("%w:\n %w" , ErrInvalidParameters , err )
318348 }
0 commit comments