-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from local-deploy/DL-T-30
legacy compatibility
- Loading branch information
Showing
3 changed files
with
107 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package helper | ||
|
||
import ( | ||
"bufio" | ||
"context" | ||
"errors" | ||
"os" | ||
"os/exec" | ||
"strings" | ||
|
||
"github.com/docker/docker/api/types" | ||
"github.com/docker/docker/api/types/filters" | ||
"github.com/docker/docker/client" | ||
"github.com/pterm/pterm" | ||
) | ||
|
||
// WpdeployCheck Legacy app check | ||
func WpdeployCheck() bool { | ||
ctx := context.Background() | ||
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation()) | ||
if err != nil { | ||
pterm.FgRed.Println("Failed to connect to socket") | ||
return false | ||
} | ||
|
||
containerFilter := filters.NewArgs(filters.Arg("label", "com.docker.compose.project=local-services")) | ||
isExists, err := cli.ContainerList(ctx, types.ContainerListOptions{All: true, Filters: containerFilter}) | ||
if err != nil { | ||
pterm.FgRed.Println(err) | ||
return false | ||
} | ||
if len(isExists) > 0 { | ||
err := wpdeployDown() | ||
if err != nil { | ||
pterm.FgRed.Println(err) | ||
return false | ||
} | ||
return false | ||
} | ||
return true | ||
} | ||
|
||
func wpdeployDown() error { | ||
dir, _ := os.Getwd() | ||
wpdeploy, _ := exec.LookPath("wpdeploy") | ||
reader := bufio.NewReader(os.Stdin) | ||
|
||
pterm.FgYellow.Print("An old version of wpdeploy is running. Do you want to stop it (Y/n)? ") | ||
|
||
a, err := reader.ReadString('\n') | ||
if err != nil { | ||
return err | ||
} | ||
|
||
//goland:noinspection GoErrorStringFormat | ||
errorMsg := errors.New("Stop wpdeploy local services first: wpdeploy local-services down") | ||
|
||
a = strings.TrimSpace(a) | ||
if strings.ToLower(a) == "y" || a == "" { | ||
cmdDown := &exec.Cmd{ | ||
Path: wpdeploy, | ||
Dir: dir, | ||
Args: []string{wpdeploy, "local-services", "down"}, | ||
Stdout: os.Stdout, | ||
Stderr: os.Stderr, | ||
} | ||
err = cmdDown.Run() | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
return errorMsg | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters