Skip to content

Commit

Permalink
Add convenience flag for outputting dependencies only.
Browse files Browse the repository at this point in the history
  • Loading branch information
doru1004 authored and nicolaferraro committed Feb 19, 2021
1 parent 53d7f84 commit f54abe7
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions pkg/cmd/local_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func newCmdLocalBuild(rootCmdOptions *RootCmdOptions) (*cobra.Command, *localBui
}

cmd.Flags().Bool("base-image", false, "Build base image used as a starting point for any integration.")
cmd.Flags().Bool("dependencies-only", false, "Only output the integration dependencies. The integration-directory flag must be set.")
cmd.Flags().String("container-registry", "", "Registry that holds intermediate images. This flag should only be used in conjunction with the base-image flag.")
cmd.Flags().String("image", "", "Full path to integration image including registry.")
cmd.Flags().String("integration-directory", "", "Directory to hold local integration files.")
Expand All @@ -71,6 +72,7 @@ func newCmdLocalBuild(rootCmdOptions *RootCmdOptions) (*cobra.Command, *localBui
type localBuildCmdOptions struct {
*RootCmdOptions
BaseImage bool `mapstructure:"base-image"`
DependenciesOnly bool `mapstructure:"dependencies-only"`
ContainerRegistry string `mapstructure:"container-registry"`
Image string `mapstructure:"image"`
IntegrationDirectory string `mapstructure:"integration-directory"`
Expand Down Expand Up @@ -121,6 +123,11 @@ func (command *localBuildCmdOptions) validate(args []string) error {
return errors.New("base image construction does not use integration files")
}

// The integration directory must be set when only outputting dependencies.
if command.DependenciesOnly && command.IntegrationDirectory == "" {
return errors.New("to output dependencies the integration directory flag must be set")
}

return nil
}

Expand Down Expand Up @@ -166,16 +173,18 @@ func (command *localBuildCmdOptions) run(cmd *cobra.Command, args []string) erro
return err
}

hasIntegrationDir := command.IntegrationDirectory != ""

// Manage integration properties which may come from files or CLI.
propertyFiles, err := updateIntegrationProperties(command.Properties, command.PropertyFiles, false)
if err != nil {
return err
propertyFiles := []string{}
if !command.DependenciesOnly {
// Manage integration properties which may come from files or CLI.
propertyFiles, err = updateIntegrationProperties(command.Properties, command.PropertyFiles, false)
if err != nil {
return err
}
}

dependenciesList = dependencies
propertyFilesList = propertyFiles
hasIntegrationDir := command.IntegrationDirectory != ""
if hasIntegrationDir {
// Create dependencies subdirectory.
localDependenciesDirectory := getCustomDependenciesDir(command.IntegrationDirectory)
Expand All @@ -186,6 +195,11 @@ func (command *localBuildCmdOptions) run(cmd *cobra.Command, args []string) erro
return err
}

// Once dependencies have been copied to local folder, we can exit.
if command.DependenciesOnly {
return nil
}

// Create dependencies subdirectory.
localPropertiesDirectory := getCustomPropertiesDir(command.IntegrationDirectory)

Expand Down

0 comments on commit f54abe7

Please sign in to comment.