Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,5 +263,6 @@ func init() {
initCmd.PersistentFlags().StringVar(&initOptions.IPFSMode, "ipfs-mode", "private", fmt.Sprintf("Set the mode in which IFPS operates. Options are: %v", fftypes.FFEnumValues(types.IPFSMode)))
initCmd.PersistentFlags().StringArrayVar(&initOptions.OrgNames, "org-name", []string{}, "Organization name")
initCmd.PersistentFlags().StringArrayVar(&initOptions.NodeNames, "node-name", []string{}, "Node name")
initCmd.PersistentFlags().StringVarP(&initOptions.CustomPath, "override", "o", "", "copy data from custom path to docker-compose.override.yml")
rootCmd.AddCommand(initCmd)
}
19 changes: 19 additions & 0 deletions internal/stacks/stack_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ func (s *StackManager) InitStack(options *types.InitOptions) (err error) {
if err := s.writeDockerComposeOverride(compose); err != nil {
return fmt.Errorf("failed to write docker-compose.override.yml: %s", err)
}
if err := s.copyToDockerComposeOverride(options.CustomPath); err != nil {
return fmt.Errorf("failed to copy file data to docker-compose.override.yml: %s", err)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need a check around this to see if options.CustomPath has been set or not. Right now the tests seem to indicate that the CLI fails to initialize a stack if this flag is not set.

return s.writeConfig(options)
}

Expand Down Expand Up @@ -415,6 +418,22 @@ func (s *StackManager) writeDockerComposeOverride(compose *docker.DockerComposeC
return os.WriteFile(filepath.Join(s.Stack.StackDir, "docker-compose.override.yml"), bytes, 0755)
}

func (s *StackManager) copyToDockerComposeOverride(dockerComposePath string) error {
comments := "# Copy custom file to docker-compose.override.yml file\n"
bytes := []byte(comments)

if dockerComposePath == "docker-compose.yml" {
dockerComposePath = filepath.Join(s.Stack.StackDir, "docker-compose.yml")
}
overrideComposeContent, err := os.ReadFile(dockerComposePath)
if err != nil && os.IsNotExist(err) {
return err
}
bytes = append(bytes, overrideComposeContent...)
override := filepath.Join(s.Stack.StackDir, "docker-compose.override.yml")
return os.WriteFile(override, bytes, 0775)
}

func (s *StackManager) writeStackConfig() error {
stackConfigBytes, err := json.MarshalIndent(s.Stack, "", " ")
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/types/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type InitOptions struct {
ChannelName string
ChaincodeName string
CustomPinSupport bool
CustomPath string
}

const IPFSMode = "ipfs_mode"
Expand Down