-
Notifications
You must be signed in to change notification settings - Fork 52
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
base: main
Are you sure you want to change the base?
Changes from 6 commits
fe29231
15aa781
4f0cc56
7be4ff3
209e501
587258e
36259c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" { | ||
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) | ||
} | ||
|
||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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 |
||
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 { | ||
|
There was a problem hiding this comment.
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).