Skip to content

Commit e957ab1

Browse files
authored
Merge pull request #1038 from jonjohnsonjr/extra-packages
Add --package-append flag to build
2 parents 2826e29 + 6ae94eb commit e957ab1

5 files changed

Lines changed: 15 additions & 3 deletions

File tree

docs/md/melange_build.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ melange build [flags]
5252
--namespace string namespace to use in package URLs in SBOM (eg wolfi, alpine) (default "unknown")
5353
--out-dir string directory where packages will be output (default "./packages/")
5454
--overlay-binsh string use specified file as /bin/sh overlay in build environment
55+
--package-append strings extra packages to install for each of the build environments
5556
--pipeline-dir string directory used to extend defined built-in pipelines
5657
-r, --repository-append strings path to extra repositories to include in the build environment
5758
--rm clean up intermediate artifacts (e.g. container images)

pkg/build/build.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ type Build struct {
7171
Arch apko_types.Architecture
7272
ExtraKeys []string
7373
ExtraRepos []string
74+
ExtraPackages []string
7475
DependencyLog string
7576
BinShOverlay string
7677
CreateBuildLog bool
@@ -239,6 +240,7 @@ func (b *Build) BuildGuest(ctx context.Context, imgConfig apko_types.ImageConfig
239240
apko_build.WithArch(b.Arch),
240241
apko_build.WithExtraKeys(b.ExtraKeys),
241242
apko_build.WithExtraRepos(b.ExtraRepos),
243+
apko_build.WithExtraPackages(b.ExtraPackages),
242244
apko_build.WithCacheDir(b.ApkCacheDir, false), // TODO: Replace with real offline plumbing
243245
apko_build.WithTempDir(tmp),
244246
)

pkg/build/options.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,3 +342,11 @@ func WithTimeout(dur time.Duration) Option {
342342
return nil
343343
}
344344
}
345+
346+
// WithExtraPackages specifies packages that are added to each build by default.
347+
func WithExtraPackages(extraPackages []string) Option {
348+
return func(b *Build) error {
349+
b.ExtraPackages = extraPackages
350+
return nil
351+
}
352+
}

pkg/build/test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,12 @@ func (t *Test) BuildGuest(ctx context.Context, imgConfig apko_types.ImageConfigu
136136
}
137137
defer os.RemoveAll(tmp)
138138

139-
// Then add any extra packages specified by the command line.
140-
imgConfig.Contents.Packages = append(imgConfig.Contents.Packages, t.ExtraTestPackages...)
141-
142139
bc, err := apko_build.New(ctx, guestFS,
143140
apko_build.WithImageConfiguration(imgConfig),
144141
apko_build.WithArch(t.Arch),
145142
apko_build.WithExtraKeys(t.ExtraKeys),
146143
apko_build.WithExtraRepos(t.ExtraRepos),
144+
apko_build.WithExtraPackages(t.ExtraTestPackages),
147145
apko_build.WithCacheDir(t.ApkCacheDir, false), // TODO: Replace with real offline plumbing
148146
apko_build.WithTempDir(tmp),
149147
)

pkg/cli/build.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ func Build() *cobra.Command {
7373
var failOnLintWarning bool
7474
var cpu, memory string
7575
var timeout time.Duration
76+
var extraPackages []string
7677

7778
var traceFile string
7879

@@ -132,6 +133,7 @@ func Build() *cobra.Command {
132133
build.WithOutDir(outDir),
133134
build.WithExtraKeys(extraKeys),
134135
build.WithExtraRepos(extraRepos),
136+
build.WithExtraPackages(extraPackages),
135137
build.WithDependencyLog(dependencyLog),
136138
build.WithBinShOverlay(overlayBinSh),
137139
build.WithStripOriginName(stripOriginName),
@@ -192,6 +194,7 @@ func Build() *cobra.Command {
192194
cmd.Flags().StringVar(&runner, "runner", "", fmt.Sprintf("which runner to use to enable running commands, default is based on your platform. Options are %q", build.GetAllRunners()))
193195
cmd.Flags().StringSliceVarP(&extraKeys, "keyring-append", "k", []string{}, "path to extra keys to include in the build environment keyring")
194196
cmd.Flags().StringSliceVarP(&extraRepos, "repository-append", "r", []string{}, "path to extra repositories to include in the build environment")
197+
cmd.Flags().StringSliceVar(&extraPackages, "package-append", []string{}, "extra packages to install for each of the build environments")
195198
cmd.Flags().BoolVar(&createBuildLog, "create-build-log", false, "creates a package.log file containing a list of packages that were built by the command")
196199
cmd.Flags().BoolVar(&debug, "debug", false, "enables debug logging of build pipelines")
197200
cmd.Flags().BoolVar(&debugRunner, "debug-runner", false, "when enabled, the builder pod will persist after the build succeeds or fails")

0 commit comments

Comments
 (0)