Skip to content

Commit

Permalink
Merge pull request #1038 from jonjohnsonjr/extra-packages
Browse files Browse the repository at this point in the history
Add --package-append flag to build
  • Loading branch information
imjasonh authored Feb 20, 2024
2 parents 2826e29 + 6ae94eb commit e957ab1
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/md/melange_build.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ melange build [flags]
--namespace string namespace to use in package URLs in SBOM (eg wolfi, alpine) (default "unknown")
--out-dir string directory where packages will be output (default "./packages/")
--overlay-binsh string use specified file as /bin/sh overlay in build environment
--package-append strings extra packages to install for each of the build environments
--pipeline-dir string directory used to extend defined built-in pipelines
-r, --repository-append strings path to extra repositories to include in the build environment
--rm clean up intermediate artifacts (e.g. container images)
Expand Down
2 changes: 2 additions & 0 deletions pkg/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type Build struct {
Arch apko_types.Architecture
ExtraKeys []string
ExtraRepos []string
ExtraPackages []string
DependencyLog string
BinShOverlay string
CreateBuildLog bool
Expand Down Expand Up @@ -239,6 +240,7 @@ func (b *Build) BuildGuest(ctx context.Context, imgConfig apko_types.ImageConfig
apko_build.WithArch(b.Arch),
apko_build.WithExtraKeys(b.ExtraKeys),
apko_build.WithExtraRepos(b.ExtraRepos),
apko_build.WithExtraPackages(b.ExtraPackages),
apko_build.WithCacheDir(b.ApkCacheDir, false), // TODO: Replace with real offline plumbing
apko_build.WithTempDir(tmp),
)
Expand Down
8 changes: 8 additions & 0 deletions pkg/build/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,3 +342,11 @@ func WithTimeout(dur time.Duration) Option {
return nil
}
}

// WithExtraPackages specifies packages that are added to each build by default.
func WithExtraPackages(extraPackages []string) Option {
return func(b *Build) error {
b.ExtraPackages = extraPackages
return nil
}
}
4 changes: 1 addition & 3 deletions pkg/build/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,12 @@ func (t *Test) BuildGuest(ctx context.Context, imgConfig apko_types.ImageConfigu
}
defer os.RemoveAll(tmp)

// Then add any extra packages specified by the command line.
imgConfig.Contents.Packages = append(imgConfig.Contents.Packages, t.ExtraTestPackages...)

bc, err := apko_build.New(ctx, guestFS,
apko_build.WithImageConfiguration(imgConfig),
apko_build.WithArch(t.Arch),
apko_build.WithExtraKeys(t.ExtraKeys),
apko_build.WithExtraRepos(t.ExtraRepos),
apko_build.WithExtraPackages(t.ExtraTestPackages),
apko_build.WithCacheDir(t.ApkCacheDir, false), // TODO: Replace with real offline plumbing
apko_build.WithTempDir(tmp),
)
Expand Down
3 changes: 3 additions & 0 deletions pkg/cli/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func Build() *cobra.Command {
var failOnLintWarning bool
var cpu, memory string
var timeout time.Duration
var extraPackages []string

var traceFile string

Expand Down Expand Up @@ -132,6 +133,7 @@ func Build() *cobra.Command {
build.WithOutDir(outDir),
build.WithExtraKeys(extraKeys),
build.WithExtraRepos(extraRepos),
build.WithExtraPackages(extraPackages),
build.WithDependencyLog(dependencyLog),
build.WithBinShOverlay(overlayBinSh),
build.WithStripOriginName(stripOriginName),
Expand Down Expand Up @@ -192,6 +194,7 @@ func Build() *cobra.Command {
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()))
cmd.Flags().StringSliceVarP(&extraKeys, "keyring-append", "k", []string{}, "path to extra keys to include in the build environment keyring")
cmd.Flags().StringSliceVarP(&extraRepos, "repository-append", "r", []string{}, "path to extra repositories to include in the build environment")
cmd.Flags().StringSliceVar(&extraPackages, "package-append", []string{}, "extra packages to install for each of the build environments")
cmd.Flags().BoolVar(&createBuildLog, "create-build-log", false, "creates a package.log file containing a list of packages that were built by the command")
cmd.Flags().BoolVar(&debug, "debug", false, "enables debug logging of build pipelines")
cmd.Flags().BoolVar(&debugRunner, "debug-runner", false, "when enabled, the builder pod will persist after the build succeeds or fails")
Expand Down

0 comments on commit e957ab1

Please sign in to comment.