forked from toolshed/abra
refactor!: consolidate SSH handling
Closes coop-cloud/organising#389. Closes coop-cloud/organising#341. Closes coop-cloud/organising#326. Closes coop-cloud/organising#380. Closes coop-cloud/organising#360.
This commit is contained in:
@ -378,73 +378,6 @@ var RemoteUserFlag = &cli.StringFlag{
|
||||
Destination: &RemoteUser,
|
||||
}
|
||||
|
||||
// SSHFailMsg is a hopefully helpful SSH failure message
|
||||
var SSHFailMsg = `
|
||||
Woops, Abra is unable to connect to connect to %s.
|
||||
|
||||
Here are a few tips for debugging your local SSH config. Abra uses plain 'ol
|
||||
SSH to make connections to servers, so if your SSH config is working, Abra is
|
||||
working.
|
||||
|
||||
In the first place, Abra will always try to read your Docker context connection
|
||||
string for SSH connection details. You can view your server context configs
|
||||
with the following command. Are they correct?
|
||||
|
||||
abra server ls
|
||||
|
||||
Is your ssh-agent running? You can start it by running the following command:
|
||||
|
||||
eval "$(ssh-agent)"
|
||||
|
||||
If your SSH private key loaded? You can check by running the following command:
|
||||
|
||||
ssh-add -L
|
||||
|
||||
If, you can add it with:
|
||||
|
||||
ssh-add ~/.ssh/<private-key-part>
|
||||
|
||||
If you are using a non-default public/private key, you can configure this in
|
||||
your ~/.ssh/config file which Abra will read in order to figure out connection
|
||||
details:
|
||||
|
||||
Host foo.coopcloud.tech
|
||||
Hostname foo.coopcloud.tech
|
||||
User bar
|
||||
Port 12345
|
||||
IdentityFile ~/.ssh/bar@foo.coopcloud.tech
|
||||
|
||||
If you're only using password authentication, you can use the following config:
|
||||
|
||||
Host foo.coopcloud.tech
|
||||
Hostname foo.coopcloud.tech
|
||||
User bar
|
||||
Port 12345
|
||||
PreferredAuthentications=password
|
||||
PubkeyAuthentication=no
|
||||
|
||||
Good luck!
|
||||
|
||||
`
|
||||
|
||||
var ServerAddFailMsg = `
|
||||
Failed to add server %s.
|
||||
|
||||
This could be caused by two things.
|
||||
|
||||
Abra isn't picking up your SSH configuration or you need to specify it on the
|
||||
command-line (e.g you use a non-standard port or username to connect). Run
|
||||
"server add" with "-d/--debug" to learn more about what Abra is doing under the
|
||||
hood.
|
||||
|
||||
Docker is not installed on your server. You can pass "-p/--provision" to
|
||||
install Docker and initialise Docker Swarm mode. See help output for "server
|
||||
add"
|
||||
|
||||
See "abra server add -h" for more.
|
||||
|
||||
`
|
||||
|
||||
// SubCommandBefore wires up pre-action machinery (e.g. --debug handling).
|
||||
func SubCommandBefore(c *cli.Context) error {
|
||||
if Debug {
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"coopcloud.tech/abra/pkg/client"
|
||||
"coopcloud.tech/abra/pkg/config"
|
||||
"coopcloud.tech/abra/pkg/dns"
|
||||
"coopcloud.tech/abra/pkg/formatter"
|
||||
@ -17,12 +16,13 @@ import (
|
||||
"coopcloud.tech/abra/pkg/recipe"
|
||||
"coopcloud.tech/abra/pkg/upstream/stack"
|
||||
"github.com/AlecAivazis/survey/v2"
|
||||
dockerClient "github.com/docker/docker/client"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
// DeployAction is the main command-line action for this package
|
||||
func DeployAction(c *cli.Context) error {
|
||||
func DeployAction(c *cli.Context, cl *dockerClient.Client) error {
|
||||
app := ValidateApp(c)
|
||||
|
||||
if !Chaos {
|
||||
@ -40,11 +40,6 @@ func DeployAction(c *cli.Context) error {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
cl, err := client.New(app.Server)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
logrus.Debugf("checking whether %s is already deployed", app.StackName())
|
||||
|
||||
isDeployed, deployedVersion, err := stack.IsDeployed(context.Background(), cl, app.StackName())
|
||||
|
@ -5,15 +5,15 @@ import (
|
||||
"path"
|
||||
|
||||
"coopcloud.tech/abra/pkg/app"
|
||||
"coopcloud.tech/abra/pkg/client"
|
||||
"coopcloud.tech/abra/pkg/config"
|
||||
"coopcloud.tech/abra/pkg/context"
|
||||
"coopcloud.tech/abra/pkg/formatter"
|
||||
"coopcloud.tech/abra/pkg/jsontable"
|
||||
"coopcloud.tech/abra/pkg/recipe"
|
||||
recipePkg "coopcloud.tech/abra/pkg/recipe"
|
||||
"coopcloud.tech/abra/pkg/secret"
|
||||
"coopcloud.tech/abra/pkg/ssh"
|
||||
"github.com/AlecAivazis/survey/v2"
|
||||
dockerClient "github.com/docker/docker/client"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
@ -25,7 +25,7 @@ type AppSecrets map[string]string
|
||||
var RecipeName string
|
||||
|
||||
// createSecrets creates all secrets for a new app.
|
||||
func createSecrets(sanitisedAppName string) (AppSecrets, error) {
|
||||
func createSecrets(cl *dockerClient.Client, sanitisedAppName string) (AppSecrets, error) {
|
||||
appEnvPath := path.Join(config.ABRA_DIR, "servers", NewAppServer, fmt.Sprintf("%s.env", Domain))
|
||||
appEnv, err := config.ReadEnv(appEnvPath)
|
||||
if err != nil {
|
||||
@ -33,7 +33,7 @@ func createSecrets(sanitisedAppName string) (AppSecrets, error) {
|
||||
}
|
||||
|
||||
secretEnvVars := secret.ReadSecretEnvVars(appEnv)
|
||||
secrets, err := secret.GenerateSecrets(secretEnvVars, sanitisedAppName, NewAppServer)
|
||||
secrets, err := secret.GenerateSecrets(cl, secretEnvVars, sanitisedAppName, NewAppServer)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -144,19 +144,15 @@ func NewAction(c *cli.Context) error {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
cl, err := client.New(NewAppServer)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
var secrets AppSecrets
|
||||
var secretTable *jsontable.JSONTable
|
||||
if Secrets {
|
||||
if err := context.HasDockerContext(sanitisedAppName, NewAppServer); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
if err := ssh.EnsureHostKey(NewAppServer); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
var err error
|
||||
secrets, err = createSecrets(sanitisedAppName)
|
||||
secrets, err := createSecrets(cl, sanitisedAppName)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
@ -8,9 +8,7 @@ import (
|
||||
|
||||
"coopcloud.tech/abra/pkg/app"
|
||||
"coopcloud.tech/abra/pkg/config"
|
||||
"coopcloud.tech/abra/pkg/context"
|
||||
"coopcloud.tech/abra/pkg/recipe"
|
||||
"coopcloud.tech/abra/pkg/ssh"
|
||||
"github.com/AlecAivazis/survey/v2"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
@ -142,14 +140,6 @@ func ValidateApp(c *cli.Context) config.App {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
if err := context.HasDockerContext(app.Name, app.Server); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
if err := ssh.EnsureHostKey(app.Server); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
logrus.Debugf("validated %s as app argument", appName)
|
||||
|
||||
return app
|
||||
|
Reference in New Issue
Block a user