diff --git a/.goreleaser.yml b/.goreleaser.yml index 19e0b999..0afc694f 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -49,17 +49,3 @@ builds: snapshot: version_template: "{{ .Version }}-SNAPSHOT-{{.ShortCommit}}" - -brews: - - ids: - - pygmy - repository: - owner: pygmystack - name: homebrew-pygmy - branch: main - token: "${{ .Env.GITHUB_TOKEN }}" - homepage: "https://github.com/pygmystack/pygmy" - description: "amazee.io's local development helper tool" - skip_upload: false - test: system "#{bin}/pygmy version" - install: bin.install "pygmy" \ No newline at end of file diff --git a/cmd/addkey.go b/cmd/addkey.go index e2d94138..5d790dd8 100644 --- a/cmd/addkey.go +++ b/cmd/addkey.go @@ -23,6 +23,7 @@ package cmd import ( "fmt" "github.com/pygmystack/pygmy/external/docker/setup" + "strings" . "github.com/logrusorgru/aurora" "github.com/spf13/cobra" @@ -73,7 +74,12 @@ var addkeyCmd = &cobra.Command{ if purpose == "sshagent" { name, _ := service.GetFieldString(ctx, cli, "name") d, _ := containers.Exec(ctx, cli, name, "ssh-add -l") - fmt.Println(string(d)) + if strings.Contains(string(d), "The agent has no identities.") { + fmt.Println(Red("Agent has no identities, the key could not be added.")) + fmt.Println(Red("Start the SSH Agent, add the SSH key and try again.")) + } else { + fmt.Println(string(d)) + } } } diff --git a/cmd/root.go b/cmd/root.go index 2332d6ab..92e0578b 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -117,10 +117,13 @@ func findConfig() string { } // Provide a default. - if runtime.GOOS == "linux" { - return strings.Join([]string{"etc", "pygmy", "config.yml"}, string(os.PathSeparator)) + defaultFilePath := strings.Join([]string{home, ".pygmy.yml"}, string(os.PathSeparator)) + file, err := os.Create(defaultFilePath) + if err != nil { + panic("could not create pygmy config file") } - return strings.Join([]string{home, ".pygmy.yml"}, string(os.PathSeparator)) + defer file.Close() + return defaultFilePath } // initConfig reads in config file and ENV variables if set. diff --git a/cmd/up.go b/cmd/up.go index f51abd25..94034051 100644 --- a/cmd/up.go +++ b/cmd/up.go @@ -22,9 +22,7 @@ package cmd import ( "fmt" - "os" - "github.com/mitchellh/go-homedir" "github.com/pygmystack/pygmy/external/docker/commands" "github.com/pygmystack/pygmy/external/docker/setup" "github.com/spf13/cobra" @@ -79,11 +77,8 @@ It includes dnsmasq, haproxy, mailhog, resolv and ssh-agent.`, func init() { - homedir, _ := homedir.Dir() - keypath := fmt.Sprintf("%v%v.ssh%vid_rsa", homedir, string(os.PathSeparator), string(os.PathSeparator)) - rootCmd.AddCommand(upCmd) - upCmd.Flags().StringP("key", "", keypath, "Path of SSH key to add") + upCmd.Flags().StringP("key", "", "", "Path of SSH key to add") upCmd.Flags().BoolP("no-addkey", "", false, "Skip adding the SSH key") upCmd.Flags().BoolP("no-resolver", "", false, "Skip adding or removing the Resolver") } diff --git a/external/docker/commands/addkey.go b/external/docker/commands/addkey.go index 7be1455b..3812b5db 100644 --- a/external/docker/commands/addkey.go +++ b/external/docker/commands/addkey.go @@ -7,6 +7,7 @@ import ( "strings" . "github.com/logrusorgru/aurora" + "github.com/spf13/viper" "github.com/pygmystack/pygmy/external/docker/setup" "github.com/pygmystack/pygmy/internal/runtime/docker/internals" @@ -94,7 +95,23 @@ func SshKeyAdd(c setup.Config, key string) error { } _ = Container.Remove(ctx, cli) + writeKeys := []setup.Key{ + { + Path: key, + }, + } + + for _, key := range c.Keys { + if key.Path != writeKeys[0].Path { + writeKeys = append(writeKeys, key) + } + } + viper.Set("keys", writeKeys) + err = viper.WriteConfig() + if err != nil { + return err + } } } diff --git a/external/docker/commands/status.go b/external/docker/commands/status.go index 5bbeeac9..f985f19a 100644 --- a/external/docker/commands/status.go +++ b/external/docker/commands/status.go @@ -4,6 +4,9 @@ import ( "context" "encoding/json" "fmt" + "net" + urltools "net/url" + "os" "strings" "sync" @@ -128,8 +131,17 @@ func Status(ctx context.Context, cli *client.Client, c setup.Config) { for _, Container := range c.Services { Status, _ := Container.Status(ctx, cli) url, _ := Container.GetFieldString(ctx, cli, "url") - if url != "" && Status { - urls = append(urls, url) + + cleanUrl, err := urltools.Parse(url) + if err != nil { + fmt.Println(err.Error()) + continue + } + if Status { + if strings.Contains(cleanUrl.String(), "docker.amazee.io") { + finalUrl := strings.Trim(cleanUrl.String(), "[]") + urls = append(urls, finalUrl) + } } } diff --git a/external/docker/commands/up.go b/external/docker/commands/up.go index b6c1a895..aa5d03ff 100644 --- a/external/docker/commands/up.go +++ b/external/docker/commands/up.go @@ -1,7 +1,10 @@ package commands import ( + "errors" "fmt" + "net" + urltools "net/url" "os" "strings" @@ -135,9 +138,20 @@ func Up(c setup.Config) error { // Add ssh-keys to the agent if agentPresent { - for _, v := range c.Keys { - if e := SshKeyAdd(c, v.Path); e != nil { - color.Print(Red(fmt.Sprintf("%v\n", e))) + if len(c.Keys) == 0 || c.Keys[0].Path == "" { + color.Print(Red("No SSH keys are configured, use `pygmy addkey --key=/path/to/key` to add one.\n")) + } else { + for _, v := range c.Keys { + if v.Path != "" { + _, err := os.Stat(v.Path) + if !errors.Is(err, os.ErrNotExist) { + if e := SshKeyAdd(c, v.Path); e != nil { + color.Print(Red(fmt.Sprintf("%v\n", e))) + } + } else { + color.Print(Red(fmt.Sprintf("Unable to add SSH key '%s': does not exist\n", v.Path))) + } + } } } } @@ -166,10 +180,18 @@ func Up(c setup.Config) error { // Look for the environment variable $LAGOON_ROUTE. if strings.Contains(v, "LAGOON_ROUTE=") { url := strings.TrimPrefix(v, "LAGOON_ROUTE=") - if !strings.HasPrefix(url, "http") && !strings.HasPrefix(url, "https") { - url = "http://" + url + cleanUrl, err := urltools.Parse(url) + if err != nil { + fmt.Println(err.Error()) + continue + } + if os.Getenv("PYGMY_WEB_PORT") != "" { + cleanUrl.Host = net.JoinHostPort(cleanUrl.Host, os.Getenv("PYGMY_WEB_PORT")) + } + if strings.Contains(cleanUrl.String(), "docker.amazee.io") { + finalUrl := strings.Trim(cleanUrl.String(), "[]") + urls = append(urls, finalUrl) } - urls = append(urls, url) } } }