Skip to content

Commit

Permalink
chore: reorganize, fix goreleaser and update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
runz0rd committed Oct 25, 2023
1 parent e4b0f42 commit a3d29b4
Show file tree
Hide file tree
Showing 40 changed files with 260 additions and 281 deletions.
4 changes: 2 additions & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
# Build customization
builds:
- binary: gograpple
main: ./cmd/main.go
main: ./main.go
env:
- CGO_ENABLED=0
ldflags:
- -s -w -X github.com/foomo/gograpple/cmd/actions.version={{.Version}}
- -s -w -X github.com/foomo/gograpple/cmd.version={{.Version}}
goos:
- darwin
- linux
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
build:
go build -o bin/gograpple cmd/gograpple/main.go
go build -o bin/gograpple main.go

install:
go build -o /usr/local/bin/gograpple cmd/gograpple/main.go
go build -o /usr/local/bin/gograpple main.go

test:
go test ./...
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@
gograpple that go program and delve into the high seas ...
or in other words: delve debugger injection for your golang code running in k8 pods

## requirements
- helm
- kubectl
- docker

## quick start
```
go install github.com/foomo/gograpple/cmd/gograpple@latest
brew install foomo/gograpple/gograpple
OR
go install github.com/foomo/gograpple@latest
```
start patch debugging in interactive mode
```
Expand All @@ -15,6 +22,12 @@ when you configure your patch correctly a file will be saved in your cwd and the

## common issues

### stuck with patched deployment
in case your deployment is styck in patched state, use
```
gograpple rollback [namespace] [deployment]
```

### vscode
> The debug session doesnt start until the entrypoint is triggered more than once.
Expand Down
8 changes: 4 additions & 4 deletions cmd/gograpple/actions/flags.go → cmd/flags.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package actions
package cmd

import (
"fmt"
"strconv"
"strings"

"github.com/foomo/gograpple"
"github.com/foomo/gograpple/internal/grapple"
)

type HostPort struct {
Expand All @@ -14,7 +14,7 @@ type HostPort struct {
}

func NewHostPort(host string, port int) *HostPort {
addr, err := gograpple.CheckTCPConnection(host, port)
addr, err := grapple.CheckTCPConnection(host, port)
if err == nil {
host = addr.IP.String()
port = addr.Port
Expand Down Expand Up @@ -45,7 +45,7 @@ func (lf *HostPort) Set(value string) error {
default:
return fmt.Errorf("invalid address %q provided", value)
}
addr, err := gograpple.CheckTCPConnection(lf.Host, lf.Port)
addr, err := grapple.CheckTCPConnection(lf.Host, lf.Port)
if err != nil {
return err
}
Expand Down
124 changes: 0 additions & 124 deletions cmd/gograpple/actions/root.go

This file was deleted.

22 changes: 0 additions & 22 deletions cmd/gograpple/actions/version.go

This file was deleted.

7 changes: 0 additions & 7 deletions cmd/gograpple/main.go

This file was deleted.

20 changes: 12 additions & 8 deletions cmd/gograpple/actions/interactive.go → cmd/interactive.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package actions
package cmd

import (
"path"

"github.com/foomo/gograpple"
"github.com/foomo/gograpple/config"
"github.com/foomo/gograpple/kubectl"
"github.com/foomo/gograpple/internal/config"
"github.com/foomo/gograpple/internal/grapple"
"github.com/foomo/gograpple/internal/kubectl"
"github.com/spf13/cobra"
)

const commandNameInteractive = "interactive"
func init() {
interactiveCmd.Flags().BoolVar(&flagAttach, "attach", false, "debug with attach (default will patch)")
interactiveCmd.Flags().StringVar(&flagSaveDir, "save", ".", "directory to save interactive configuration")
rootCmd.AddCommand(interactiveCmd)
}

var (
flagAttach bool
Expand Down Expand Up @@ -37,7 +41,7 @@ func attachDebug(baseDir string) error {
if err != nil {
return err
}
g, err := gograpple.NewGrapple(newLogger(flagVerbose, flagJSONLog), c.Namespace, c.Deployment, flagDebug)
g, err := grapple.NewGrapple(newLogEntry(flagDebug), c.Namespace, c.Deployment)
if err != nil {
return err
}
Expand All @@ -48,7 +52,7 @@ func attachDebug(baseDir string) error {
if err := kubectl.SetContext(c.Cluster); err != nil {
return err
}
return g.Attach(c.Namespace, c.Deployment, c.Container, c.AttachTo, c.Arch, host, port)
return g.Attach(c.Namespace, c.Deployment, c.Container, c.AttachTo, c.Arch, host, port, flagDebug)
}

func patchDebug(baseDir string) error {
Expand All @@ -64,7 +68,7 @@ func patchDebug(baseDir string) error {
if &c == nil {
return nil
}
g, err := gograpple.NewGrapple(newLogger(flagVerbose, flagJSONLog), c.Namespace, c.Deployment, flagDebug)
g, err := grapple.NewGrapple(newLogEntry(flagDebug), c.Namespace, c.Deployment)
if err != nil {
return err
}
Expand Down
25 changes: 25 additions & 0 deletions cmd/rollback.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package cmd

import (
"github.com/foomo/gograpple/internal/grapple"
"github.com/spf13/cobra"
)

func init() {
rootCmd.AddCommand(rollbackCmd)
}

var (
rollbackCmd = &cobra.Command{
Use: "rollback [namespace] [deployment]",
Short: "rollback the patched deployment",
Args: cobra.MinimumNArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
g, err := grapple.NewGrapple(newLogEntry(flagDebug), args[0], args[1])
if err != nil {
return err
}
return g.Rollback()
},
}
)
50 changes: 50 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package cmd

import (
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

func init() {
rootCmd.PersistentFlags().BoolVarP(&flagDebug, "debug", "", false, "debug mode")
}

var (
// flagImage string
// flagDir string
flagDebug bool
// flagNamespace string
// flagPod string
// flagContainer string
// flagRepo string
// flagMounts []string
// flagSourcePath string
// flagArgs = NewStringList(" ")
// flagRollback bool
// flagListen = NewHostPort("127.0.0.1", 0)
// flagVscode bool
// flagContinue bool
// flagJSONLog bool
// flagDebug bool
)

var (
rootCmd = &cobra.Command{
Use: "gograpple",
}
)

func Execute() {
if err := rootCmd.Execute(); err != nil {
le := newLogEntry(flagDebug)
le.Fatal(err)
}
}

func newLogEntry(debug bool) *logrus.Entry {
logger := logrus.New()
if debug {
logger.SetLevel(logrus.TraceLevel)
}
return logrus.NewEntry(logger)
}
Loading

0 comments on commit a3d29b4

Please sign in to comment.