Giter Site home page Giter Site logo

moshebe / gebug Goto Github PK

View Code? Open in Web Editor NEW
633.0 633.0 19.0 93.79 MB

Debug Dockerized Go applications better

License: Apache License 2.0

Go 81.57% Makefile 2.19% Shell 0.14% Dockerfile 0.77% JavaScript 0.09% HTML 0.76% Vue 9.07% TypeScript 5.42%

gebug's People

Contributors

chenrui333 avatar dependabot-preview[bot] avatar dependabot[bot] avatar inbarperry avatar moshebe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

gebug's Issues

Setup VS Code environment automatically

I had some issues while trying to use the debugger option in visual studio code. I managed to solve it eventually by creating launch.json by myself and assign the remote port that was set by Gebug, but it would be nice if the init process would setup the environment for me.

Maybe gebug init should ask if its want to set up the required files for this to work. It will be different between IDEs so it should try to figure it out (checking for .vscode, etc...)

Support remote hot-reload

Support hot-reload while the Docker container is running on a remote machine. Support rsync, scp, S3, git.

Document the code

Is your feature request related to a problem? Please describe.
The code is missing documentation.

Describe the solution you'd like
We should write some.

Describe alternatives you've considered
I think we should consider godoc for generating a user-friendly documentation.

Additional context

SIGTERM handle

Now, when receiving signal 15 (SIGTERM) (cmd+c in console) from the user, the program crashes with an error

2020-07-21T19:45:07.909+0300 FATAL cmd/init.go:32 Failed to initialize project {"error": "^C"} github.com/moshebe/gebug/cmd.glob..func3 /Users/miksmolin/gebug/cmd/init.go:32 github.com/spf13/cobra.(*Command).execute /Users/miksmolin/go/pkg/mod/github.com/spf13/[email protected]/command.go:846 github.com/spf13/cobra.(*Command).ExecuteC /Users/miksmolin/go/pkg/mod/github.com/spf13/[email protected]/command.go:950 github.com/spf13/cobra.(*Command).Execute /Users/miksmolin/go/pkg/mod/github.com/spf13/[email protected]/command.go:887 github.com/moshebe/gebug/cmd.Execute /Users/miksmolin/gebug/cmd/root.go:38 main.main /Users/miksmolin/gebug/main.go:6 runtime.main /Users/miksmolin/homebrew/Cellar/[email protected]/1.13.10_1/libexec/src/runtime/proc.go:203

Would be great to add SIGTERM handling for graceful shutdown.

Remove prefix is not showing

It seems from the code that it is intended to show a โœ–๏ธ prefix before each port in the list to indicate that removal is possible.

it didn't work for me:
image

Running in debugger mode without networks and exposed port results with an invalid configurations

Describe the bug
Running in debugger mode without exposed ports results with an invalid docker-compose.yml

To Reproduce
Steps to reproduce the behavior:

  1. Run gebug init and enable Debugger mode
  2. Skip on the exposed-ports and network parts
  3. Run gebug start
  4. See the .gebug/docker-compose.yml error

Expected behavior
The debugger port should be on the ports section and not appear under volumes

Screenshots/Snippets
Example of an invalid generated configuration:

version: '3'
services:
  gebug-app:
    build:
      context: ..
      dockerfile: .gebug/Dockerfile
    cap_add:
      - SYS_PTRACE
    volumes:
      - ../:/src:ro
      - 40000:40000

Support environment varialbes

Currently It seems like the only option to add env vars would be to edit the .gebug/Dockerfile.. Would be great if there's an option to pass env vars without much manual work.

Empty port cause invalid docker-compose.yml generation

When going to through gebug init process, you are prompt with a choice to expose ports in the container.
Leaving the field empty generates an invalid docker-compose.yml file when executing gebug start:

docker-compose.yml
version: '3'
services:
  gebug-goproj:
    build:
      context: ..
      dockerfile: .gebug/Dockerfile
    volumes:
      - ../:/src:ro
    ports:

and the invalid yaml cause the following error:

ERROR: The Compose file './.gebug/docker-compose.yml' is invalid because:
services.gebug-goproj.ports contains an invalid type, it should be an array
2020-07-21T17:11:28.155+0300	FATAL	cmd/start.go:57	Failed to start	{"error": "exit status 1"}
github.com/moshebe/gebug/cmd.glob..func6
	/Users/inbar/go/src/github.com/moshebe/gebug/cmd/start.go:57
github.com/spf13/cobra.(*Command).execute
	/Users/inbar/go/src/github.com/spf13/cobra/command.go:846
github.com/spf13/cobra.(*Command).ExecuteC
	/Users/inbar/go/src/github.com/spf13/cobra/command.go:950
github.com/spf13/cobra.(*Command).Execute
	/Users/inbar/go/src/github.com/spf13/cobra/command.go:887
github.com/moshebe/gebug/cmd.Execute
	/Users/inbar/go/src/github.com/moshebe/gebug/cmd/root.go:38
main.main
	/Users/inbar/go/src/github.com/moshebe/gebug/main.go:6
runtime.main
	/usr/local/Cellar/go/1.14.2_1/libexec/src/runtime/proc.go:203

Workaround

Manually delete the ports section from .gebug/docker-compose.yml and run gebug start --skip-generate instead.

Installation not working

getting the following error while running go get

go get -v github.com/moshebe/gebug

go: github.com/moshebe/gebug upgrade => v0.0.0-20200721074100-a66de0d5eca3
go get: github.com/moshebe/[email protected]: parsing go.mod:
	module declares its path as: gebug
	        but was required as: github.com/moshebe/gebug

Refactor: Prompt validator should not assign the field itself

Is your feature request related to a problem? Please describe.
As of now, the validator of the prompt is both checking and assigning the field of the configuration.
I think the validator should be responsible only for the validation.

Describe the solution you'd like
According to promptui documentation, promptui.Prompt.Run() returns the value that was entered.
So we can implement the prompts like this:

func (p *PromptName) Run() error {
	prompt := &promptui.Prompt{
		Label:    "Application Name",
		Validate: regexValidator{`^[A-Za-z0-9]([A-Za-z0-9_-]*[A-Za-z0-9])?$`}.validate,
		Default:  p.Name,
	}

	var err error
	p.Name, err = prompt.Run()
	if err != nil {
		return err
	}

	return nil
}

Instead of this:

func (p *PromptName) Run() error {
	prompt := &promptui.Prompt{
		Label:    "Application Name",
		Validate: regexValidator{`^[A-Za-z0-9]([A-Za-z0-9_-]*[A-Za-z0-9])?$`, &p.Name}.validate,
		Default:  p.Name,
	}
	_, err := prompt.Run()
	if err != nil {
		return err
	}
	return nil
}

Change gebug init application name title

Problem
in gebug init, the first title say: Application Name, but here wants a docker image name instead.
I enter this in the init process:
Application Name: goRest
[...] // ...and the others fields
And i give an unexpected error:
$ gebug start
ERROR: Service 'gebug-goRest' contains uppercase characters which are not valid as part of an image name. Either use a lowercase service name or use the image field to set a custom name for the service image.

Solution
To change Application Name to Docker image name (or similar)

Select an existing network to join

as requested by johnnMackk on r/golang:
"One question, is there a way to select the network that gebug can connects to? I am just thinking of a use case where I have a server that wants to speak to another service sql db for example".

I think the network can be set via the interactive init command or via dedicated set network command or something alike.

Debugger with aws-lambda-rie

When running the config below with the debugger enabled I get the following error:

could not launch process: could not open debug info - debuggee must not be built with 'go run' or -ldflags='-s -w', which strip debug info

If I run it with debug disabled, it builds and works correctly. I was using a simple hello world main. Is there a way to have debugging with rie?

Thanks

name: relay
output_binary: /usr/local/bin/aws-lambda-rie /var/task/main
build_command: go build -o /var/task/main
build_dir: /src
run_command: '{{.output_binary}}'
runtime_image: golang:1.20.4
debugger_enabled: true
debugger_port: 40000
expose_ports:
  - "8080:8080"
networks: []
environment: []
pre_run_commands:
  - mkdir -p /var/task
  - curl -sLo /tmp/aws-lambda-rie https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie && mv /tmp/aws-lambda-rie /usr/local/bin/aws-lambda-rie && chmod +x /usr/local/bin/aws-lambda-rie

Make pkg/input more testable

Is your feature request related to a problem? Please describe.
In order to increase the coverage testing of the project, we need to add more unit tests.
We should inject promptui.Prompt to the different prompts in order to mock it's response.

Describe the solution you'd like
We can create an interface that matches promptui structs and constructors to the prompts:

type PromptIface interface {
	Run() (string, error)
}

// PromptName handles the prompt that asks for application name
type PromptName struct {
	*config.Config
	prompt PromptIface
}

// NewPromptName constructs PromptName
func NewPromptName(configuration *config.Config) *PromptName {
	p := PromptName{
		Config: configuration,
		prompt: &promptui.Prompt{
			Label:    "Application Name",
			Validate: regexValidator{`^[A-Za-z0-9]([A-Za-z0-9_-]*[A-Za-z0-9])?$`}.validate,
			Default:  configuration.Name,
		},
	}

	return &p
}

// Run asks the user for application name
func (p *PromptName) Run() error {
	var err error
	p.Name, err = p.prompt.Run()
	if err != nil {
		return err
	}

	return nil
}

And then when testing, we can inject a mock:

type MockPrompt struct{}

func (p *MockPrompt) Run() (string, error) {
	return "", errors.New("error")
}

func Test_PromptName(t *testing.T) {
	p := PromptName{
		Config: &config.Config{},
		prompt: &MockPrompt{},
	}

	assert.Error(t, p.Run())
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.