fix: working provisioning post chaos testing
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2021-10-25 10:06:16 +02:00
parent a7970132c2
commit 8772217f41
3 changed files with 124 additions and 84 deletions

View File

@ -19,7 +19,6 @@ import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm"
dockerClient "github.com/docker/docker/client"
"github.com/sfreiberg/simplessh"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
)
@ -155,9 +154,23 @@ func newClient(c *cli.Context, domainName string) (*dockerClient.Client, error)
}
func installDocker(c *cli.Context, cl *dockerClient.Client, domainName string) error {
if _, err := cl.Info(c.Context); err != nil {
if strings.Contains(err.Error(), "command not found") {
fmt.Println(fmt.Sprintf(`
logrus.Debugf("attempting to construct SSH client for %s", domainName)
client, err := ssh.New(domainName, sshAuth)
if err != nil {
return err
}
defer client.Close()
logrus.Debugf("successfully created SSH client for %s", domainName)
result, err := client.Exec("which docker")
if err != nil && string(result) != "" {
return err
}
if string(result) == "" {
fmt.Println(fmt.Sprintf(`
A docker installation cannot be found on %s. This is a required system dependency
for running Co-op Cloud on your server. If you would like, Abra can attempt to install
Docker for you using the upstream non-interactive installation script.
@ -174,81 +187,43 @@ source for this script can be seen here:
`, domainName))
response := false
prompt := &survey.Confirm{
Message: fmt.Sprintf("attempt install docker on %s?", domainName),
response := false
prompt := &survey.Confirm{
Message: fmt.Sprintf("attempt install docker on %s?", domainName),
}
if err := survey.AskOne(prompt, &response); err != nil {
return err
}
if !response {
logrus.Fatal("exiting as requested")
}
cmd := "curl -s https://get.docker.com | bash"
var sudoPass string
if askSudoPass {
prompt := &survey.Password{
Message: "sudo password?",
}
if err := survey.AskOne(prompt, &response); err != nil {
if err := survey.AskOne(prompt, &sudoPass); err != nil {
return err
}
if !response {
logrus.Fatal("exiting as requested")
}
hasIdentityFile := true
if sshAuth == "password" {
hasIdentityFile = false
}
hostConfig, err := ssh.GetHostConfig(domainName, hasIdentityFile)
logrus.Debugf("running '%s' on %s now with sudo password", cmd, domainName)
_, err := client.ExecSudo(cmd, sudoPass)
if err != nil {
return err
}
var client *simplessh.Client
if sshAuth == "identity-file" {
var err error
client, err = simplessh.ConnectWithAgent(hostConfig.Host, hostConfig.User)
if err != nil {
return err
}
} else {
password := ""
prompt := &survey.Password{
Message: "SSH password?",
}
if err := survey.AskOne(prompt, &password); err != nil {
return err
}
var err error
client, err = simplessh.ConnectWithPassword(hostConfig.Host, hostConfig.User, password)
if err != nil {
return err
}
} else {
logrus.Debugf("running '%s' on %s now without sudo password", cmd, domainName)
_, err := client.Exec(cmd)
if err != nil {
return err
}
defer client.Close()
logrus.Debugf("successfully created SSH client for %s", domainName)
cmd := "curl -s https://get.docker.com | bash"
var sudoPass string
if askSudoPass {
prompt := &survey.Password{
Message: "sudo password?",
}
if err := survey.AskOne(prompt, &sudoPass); err != nil {
return err
}
logrus.Debugf("running '%s' on %s now with sudo password", cmd, domainName)
_, err := client.ExecSudo(cmd, sudoPass)
if err != nil {
return err
}
} else {
logrus.Debugf("running '%s' on %s now without sudo password", cmd, domainName)
_, err := client.Exec(cmd)
if err != nil {
return err
}
}
logrus.Infof("docker has successfully been installed on %s", domainName)
return nil
}
}
logrus.Infof("docker is installed on %s", domainName)
return nil
}
@ -381,12 +356,7 @@ You may omit flags to avoid performing this provisioning logic.
},
ArgsUsage: "<domain> [<user>] [<port>]",
Action: func(c *cli.Context) error {
if c.Args().Len() == 2 && !local {
err := errors.New("missing arguments <domain> or '--local'")
internal.ShowSubcommandHelpAndError(c, err)
}
if c.Args().Get(2) != "" && local {
if c.Args().Len() > 0 && local {
err := errors.New("cannot use '<domain>' and '--local' together")
internal.ShowSubcommandHelpAndError(c, err)
}