Skip to content
14 changes: 0 additions & 14 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
8 changes: 7 additions & 1 deletion cmd/addkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package cmd
import (
"fmt"
"github.com/pygmystack/pygmy/external/docker/setup"
"strings"

. "github.com/logrusorgru/aurora"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -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))
}
}
}

Expand Down
9 changes: 6 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 1 addition & 6 deletions cmd/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
}
17 changes: 17 additions & 0 deletions external/docker/commands/addkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
}

}
Expand Down
16 changes: 14 additions & 2 deletions external/docker/commands/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"context"
"encoding/json"
"fmt"
"net"

Check failure on line 7 in external/docker/commands/status.go

View workflow job for this annotation

GitHub Actions / full

"net" imported and not used

Check failure on line 7 in external/docker/commands/status.go

View workflow job for this annotation

GitHub Actions / goreleaser

"net" imported and not used
urltools "net/url"
"os"

Check failure on line 9 in external/docker/commands/status.go

View workflow job for this annotation

GitHub Actions / full

"os" imported and not used

Check failure on line 9 in external/docker/commands/status.go

View workflow job for this annotation

GitHub Actions / goreleaser

"os" imported and not used
"strings"
"sync"

Expand Down Expand Up @@ -128,8 +131,17 @@
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)
}
}
}

Expand Down
34 changes: 28 additions & 6 deletions external/docker/commands/up.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package commands

import (
"errors"
"fmt"
"net"
urltools "net/url"
"os"
"strings"

Expand Down Expand Up @@ -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)))
}
}
}
}
}
Expand Down Expand Up @@ -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)
}
}
}
Expand Down
Loading