Skip to content

Commit

Permalink
added support for --detect-output-dir
Browse files Browse the repository at this point in the history
Signed-off-by: Rashad Sirajudeen <[email protected]>
  • Loading branch information
rashadism committed Jun 14, 2024
1 parent 63b140d commit ae266dd
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 10 deletions.
4 changes: 4 additions & 0 deletions internal/build/lifecycle_execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,10 @@ func (l *LifecycleExecution) Detect(ctx context.Context, phaseFactory PhaseFacto
CopyOutToMaybe(filepath.Join(l.mountPaths.layersDir(), "analyzed.toml"), l.tmpDir))),
If(l.hasExtensions(), WithPostContainerRunOperations(
CopyOutToMaybe(filepath.Join(l.mountPaths.layersDir(), "generated"), l.tmpDir))),
If(l.opts.GroupDestinationDir != "", WithPostContainerRunOperations(
EnsureVolumeAccess(l.opts.Builder.UID(), l.opts.Builder.GID(), l.os, l.layersVolume, l.appVolume),
CopyOutTo(l.mountPaths.groupPath(), l.opts.GroupDestinationDir))),

envOp,
)

Expand Down
1 change: 1 addition & 0 deletions internal/build/lifecycle_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ type LifecycleOptions struct {
PreviousImage string
ReportDestinationDir string
SBOMDestinationDir string
GroupDestinationDir string
CreationTime *time.Time
Keychain authn.Keychain
FetchOptions image.FetchOptions
Expand Down
4 changes: 4 additions & 0 deletions internal/build/mount_paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,7 @@ func (m mountPaths) launchCacheDir() string {
func (m mountPaths) sbomDir() string {
return m.join(m.volume, "layers", "sbom")
}

func (m mountPaths) groupPath() string {
return m.join(m.layersDir(), "group.toml")
}
2 changes: 2 additions & 0 deletions internal/commands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type BuildFlags struct {
GID int
UID int
PreviousImage string
GroupDestinationDir string
SBOMDestinationDir string
ReportDestinationDir string
DateTime string
Expand Down Expand Up @@ -259,6 +260,7 @@ This option may set DOCKER_HOST environment variable for the build container if
cmd.Flags().StringVar(&buildFlags.Workspace, "workspace", "", "Location at which to mount the app dir in the build image")
cmd.Flags().IntVar(&buildFlags.GID, "gid", 0, `Override GID of user's group in the stack's build and run images. The provided value must be a positive number`)
cmd.Flags().IntVar(&buildFlags.UID, "uid", 0, `Override UID of user in the stack's build and run images. The provided value must be a positive number`)
cmd.Flags().StringVar(&buildFlags.GroupDestinationDir, "detect-output-dir", "", "Path to export group.toml.")

if !buildFlags.DetectOnly {
cmd.Flags().Var(&buildFlags.Cache, "cache",
Expand Down
21 changes: 12 additions & 9 deletions internal/commands/execute_detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ func ExecuteDetect(logger logging.Logger, cfg config.Config, packClient PackClie
buildpacks := flags.Buildpacks
extensions := flags.Extensions

groupDestinationDir := flags.GroupDestinationDir

env, err := parseEnv(flags.EnvFiles, flags.Env)
if err != nil {
return err
Expand Down Expand Up @@ -103,15 +105,16 @@ func ExecuteDetect(logger logging.Logger, cfg config.Config, packClient PackClie
Network: flags.Network,
Volumes: flags.Volumes,
},
LifecycleImage: lifecycleImage,
PreBuildpacks: flags.PreBuildpacks,
PostBuildpacks: flags.PostBuildpacks,
Buildpacks: buildpacks,
Extensions: extensions,
Workspace: flags.Workspace,
GroupID: gid,
UserID: uid,
DetectOnly: true,
LifecycleImage: lifecycleImage,
PreBuildpacks: flags.PreBuildpacks,
PostBuildpacks: flags.PostBuildpacks,
Buildpacks: buildpacks,
Extensions: extensions,
Workspace: flags.Workspace,
GroupID: gid,
UserID: uid,
DetectOnly: true,
GroupDestinationDir: groupDestinationDir,
}); err != nil {
return errors.Wrap(err, "failed to detect")
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/client/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ type BuildOptions struct {
// Only trust builders from reputable sources.
TrustBuilder IsTrustedBuilder

// Directory to output any SBOM artifacts
GroupDestinationDir string

// Directory to output any SBOM artifacts
SBOMDestinationDir string

Expand Down
2 changes: 1 addition & 1 deletion pkg/client/detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func (c *Client) Detect(ctx context.Context, opts BuildOptions) error {
return err
}

// TODO: Cleanup
lifecycleOpts.GroupDestinationDir = opts.GroupDestinationDir

if err = c.lifecycleExecutor.Detect(ctx, *lifecycleOpts); err != nil {
return fmt.Errorf("executing detect: %w", err)
Expand Down

0 comments on commit ae266dd

Please sign in to comment.