Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"init" option to copy in a custom docker-compose.override.yml file #285

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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 @@ -264,5 +264,6 @@ func init() {
initCmd.PersistentFlags().StringArrayVar(&initOptions.OrgNames, "org-name", []string{}, "Organization name")
initCmd.PersistentFlags().StringArrayVar(&initOptions.NodeNames, "node-name", []string{}, "Node name")
initCmd.PersistentFlags().BoolVar(&initOptions.RemoteNodeDeploy, "remote-node-deploy", false, "Enable or disable deployment of FireFly contracts on remote nodes")
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 @@ -188,6 +188,11 @@ 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 options.CustomPath == "docker-compose.yml" {
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 this check now enforces that you can only ever pass in a file named docker-compose.yml in the current directory. I would think we would just want to check to see if this is an empty string here (and then maybe validate the file exists).

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 @@ -416,6 +421,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(dockerComposePath string) error {
comments := "# Copy custom file to docker-compose.override.yml file\n"
bytes := []byte(comments)

dockerPath := filepath.Join(s.Stack.StackDir, dockerComposePath)
overrideComposeContent, err := os.ReadFile(dockerPath)
Comment on lines +428 to +429
Copy link
Contributor

Choose a reason for hiding this comment

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

If I'm reading this right, this means we will read the automatically generated docker-compose.override.yml, append it to a comment, and write it back out again to the same file.

From my understanding the goal here is to allow the user to pass in a yaml file from anywhere on their system, and we will use that as or merge it with the existing docker-compose.override.yml file. I'm not sure this function actually creates any new functionality as-is.

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 @@ -64,6 +64,7 @@ type InitOptions struct {
ChaincodeName string
CustomPinSupport bool
RemoteNodeDeploy bool
CustomPath string
}

const IPFSMode = "ipfs_mode"
Expand Down
Loading