Compare commits

...

3 Commits

Author SHA1 Message Date
4db15d8530 fix: clean up before panic in server add command
All checks were successful
continuous-integration/drone/pr Build is passing
2024-01-06 12:49:48 +01:00
fd15aeab9a fix: make dns resolve errors more accurate
All checks were successful
continuous-integration/drone/pr Build is passing
2024-01-06 02:28:18 +01:00
5d503319e3 feat: untie server name from a domain in the add command 2024-01-06 02:28:18 +01:00
4 changed files with 27 additions and 17 deletions

View File

@ -169,7 +169,7 @@ var NewAppServerFlag = &cli.StringFlag{
var NoDomainChecks bool var NoDomainChecks bool
var NoDomainChecksFlag = &cli.BoolFlag{ var NoDomainChecksFlag = &cli.BoolFlag{
Name: "no-domain-checks, D", Name: "no-domain-checks, D",
Usage: "Disable app domain sanity checks", Usage: "Disable domain sanity checks",
Destination: &NoDomainChecks, Destination: &NoDomainChecks,
} }

View File

@ -53,7 +53,7 @@ func cleanUp(domainName string) {
// Docker manages SSH connection details. These are stored to disk in // Docker manages SSH connection details. These are stored to disk in
// ~/.docker. Abra can manage this completely for the user, so it's an // ~/.docker. Abra can manage this completely for the user, so it's an
// implementation detail. // implementation detail.
func newContext(c *cli.Context, domainName, username, port string) error { func newContext(c *cli.Context, name, host, username, port string) error {
store := contextPkg.NewDefaultDockerContextStore() store := contextPkg.NewDefaultDockerContextStore()
contexts, err := store.Store.List() contexts, err := store.Store.List()
if err != nil { if err != nil {
@ -61,15 +61,15 @@ func newContext(c *cli.Context, domainName, username, port string) error {
} }
for _, context := range contexts { for _, context := range contexts {
if context.Name == domainName { if context.Name == name {
logrus.Debugf("context for %s already exists", domainName) logrus.Debugf("context for %s already exists", name)
return nil return nil
} }
} }
logrus.Debugf("creating context with domain %s, username %s and port %s", domainName, username, port) logrus.Debugf("creating context with name %s, host %s, username %s and port %s", name, host, username, port)
if err := client.CreateContext(domainName, username, port); err != nil { if err := client.CreateContext(name, host, username, port); err != nil {
return err return err
} }
@ -112,11 +112,16 @@ Abra can then load SSH connection details from this configuratiion with:
If "--local" is passed, then Abra assumes that the current local server is If "--local" is passed, then Abra assumes that the current local server is
intended as the target server. This is useful when you want to have your entire intended as the target server. This is useful when you want to have your entire
Co-op Cloud config located on the server itself, and not on your local Co-op Cloud config located on the server itself, and not on your local
developer machine. developer machine. The domain is then set to "default".
You can also pass "--no-domain-checks" flag to use any arbitrary name instead
of a real domain. Host will be resolved with the "hostname" entry of your SSH
configuration. Checks for a valid online domain will be skipped.
`, `,
Flags: []cli.Flag{ Flags: []cli.Flag{
internal.DebugFlag, internal.DebugFlag,
internal.NoInputFlag, internal.NoInputFlag,
internal.NoDomainChecksFlag,
localFlag, localFlag,
}, },
Before: internal.SubCommandBefore, Before: internal.SubCommandBefore,
@ -150,20 +155,26 @@ developer machine.
return nil return nil
} }
if _, err := dns.EnsureIPv4(domainName); err != nil { if !internal.NoDomainChecks {
logrus.Fatal(err) if _, err := dns.EnsureIPv4(domainName); err != nil {
} logrus.Fatal(err)
}
if err := createServerDir(domainName); err != nil {
logrus.Fatal(err)
} }
hostConfig, err := sshPkg.GetHostConfig(domainName) hostConfig, err := sshPkg.GetHostConfig(domainName)
if err != nil { if err != nil {
logrus.Fatal(err) logrus.Fatal(err)
} }
if hostConfig.Host == "" {
hostConfig.Host = domainName
}
if err := newContext(c, domainName, hostConfig.User, hostConfig.Port); err != nil { if err := createServerDir(domainName); err != nil {
logrus.Fatal(err)
}
if err := newContext(c, domainName, hostConfig.Host, hostConfig.User, hostConfig.Port); err != nil {
cleanUp(domainName)
logrus.Fatal(err) logrus.Fatal(err)
} }

View File

@ -14,8 +14,7 @@ import (
type Context = contextStore.Metadata type Context = contextStore.Metadata
func CreateContext(contextName string, user string, port string) error { func CreateContext(contextName string, host string, user string, port string) error {
host := contextName
if user != "" { if user != "" {
host = fmt.Sprintf("%s@%s", user, host) host = fmt.Sprintf("%s@%s", user, host)
} }

View File

@ -9,7 +9,7 @@ import (
func EnsureIPv4(domainName string) (string, error) { func EnsureIPv4(domainName string) (string, error) {
ipv4, err := net.ResolveIPAddr("ip4", domainName) ipv4, err := net.ResolveIPAddr("ip4", domainName)
if err != nil { if err != nil {
return "", err return "", fmt.Errorf("unable to resolve ipv4 address for %s, %s", domainName, err)
} }
// NOTE(d1): e.g. when there is only an ipv6 record available // NOTE(d1): e.g. when there is only an ipv6 record available