Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5da3dc5

Browse files
authored
Merge pull request symfony-cli#149 from symfony-cli/docker-compose-fix
Fix docker-compose usage when doing a book checkout
2 parents be38fcc + b36860e commit 5da3dc5

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

book/checkout.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func (b *Book) Checkout(step string) error {
109109
}
110110
printBanner("<comment>[WEB]</> Stopping Docker Containers", b.Debug)
111111
if hasDocker {
112-
if err := executeCommand([]string{"docker-compose", "down", "--remove-orphans"}, b.Debug, false, nil); err != nil {
112+
if err := executeCommand(append(dockerComposeBin(), "down", "--remove-orphans"), b.Debug, false, nil); err != nil {
113113
return err
114114
}
115115
} else {
@@ -152,7 +152,7 @@ func (b *Book) Checkout(step string) error {
152152

153153
printBanner("<comment>[WEB]</> Starting Docker Compose", b.Debug)
154154
if hasDocker {
155-
if err := executeCommand([]string{"docker-compose", "up", "-d"}, b.Debug, false, nil); err != nil {
155+
if err := executeCommand(append(dockerComposeBin(), "up", "-d"), b.Debug, false, nil); err != nil {
156156
return err
157157
}
158158
printBanner("<comment>[WEB]</> Waiting for the Containers to be ready", b.Debug)
@@ -311,3 +311,10 @@ func executeCommand(args []string, debug, skipErrors bool, env []string) error {
311311
}
312312
return nil
313313
}
314+
315+
func dockerComposeBin() []string {
316+
if path, err := exec.LookPath("docker-compose"); err == nil {
317+
return []string{path}
318+
}
319+
return []string{"docker", "compose"}
320+
}

book/reqs.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ func CheckRequirements() (bool, error) {
137137
}
138138

139139
// Docker Compose
140-
_, composeBinary := exec.LookPath("docker-compose")
141-
composePlugin := exec.Command("docker", "compose").Run()
142-
if composeBinary != nil && composePlugin != nil {
140+
_, err1 := exec.LookPath("docker-compose")
141+
err2 := exec.Command("docker", "compose").Run()
142+
if err1 != nil && err2 != nil {
143143
ready = false
144144
terminal.Println("<error>[KO]</> Cannot find Docker Compose, please install it <href=https://docs.docker.com/compose/install/>https://docs.docker.com/compose/install/</>")
145145
} else {

0 commit comments

Comments
 (0)