Skip to content

Commit

Permalink
correct implementations
Browse files Browse the repository at this point in the history
Signed-off-by: Philip-21 <[email protected]>
  • Loading branch information
Philip-21 committed Jan 18, 2024
1 parent fe29231 commit 15aa781
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +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.Flags().StringVar(&initOptions.CustomPath, "override", "", "copy data from custom path to docker-compose.override.yml")
initCmd.PersistentFlags().StringVarP(&initOptions.CustomPath, "override", "o", "", "copy data from custom path to docker-compose.override.yml")
rootCmd.AddCommand(initCmd)
}
20 changes: 11 additions & 9 deletions internal/stacks/stack_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ 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(compose, options.CustomPath); err != nil {
if err := s.copyToDockerComposeOverride(options.CustomPath); err != nil {
return fmt.Errorf("failed to copy file data to docker-compose.override.yml: %s", err)
}
return s.writeConfig(options)
Expand Down Expand Up @@ -418,18 +418,20 @@ 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(compose *docker.DockerComposeConfig, overrideFilePath string) error {
comments := "#Copy custom file to docker-compose.override.yml file"
func (s *StackManager) copyToDockerComposeOverride(dockerComposePath string) error {
comments := "# Copy custom file to docker-compose.override.yml file\n"
bytes := []byte(comments)

overideContent, err := os.ReadFile(overrideFilePath)
if err != nil && !os.IsNotExist(err) {
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, overideContent...)

return os.WriteFile(filepath.Join(s.Stack.StackDir, "docker-compose.override.yml"), bytes, 0755)

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 {
Expand Down

0 comments on commit 15aa781

Please sign in to comment.