moshebe / gebug Goto Github PK
View Code? Open in Web Editor NEWDebug Dockerized Go applications better
License: Apache License 2.0
Debug Dockerized Go applications better
License: Apache License 2.0
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 hot-reload while the Docker container is running on a remote machine. Support rsync, scp, S3, git.
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
Describe the solution you'd like
gebug completion zsh
will output the zsh configuration for auto-complete gebug commands.
Describe alternatives you've considered
It seems that it can be easily achieved for even more kind of shells using cobra:
https://chromium.googlesource.com/external/github.com/spf13/cobra/+/refs/heads/master/shell_completions.md
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.
I think >= 80%
will be a good milestone
Describe the bug
Running in debugger mode without exposed ports results with an invalid docker-compose.yml
To Reproduce
Steps to reproduce the behavior:
gebug init
and enable Debugger modegebug start
.gebug/docker-compose.yml
errorExpected 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
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.
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
Manually delete the ports section from .gebug/docker-compose.yml
and run gebug start --skip-generate
instead.
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
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
}
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)
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.
Just FYI, it looks like 1.0.6 tag did not get marked as latest release
relates to Homebrew/homebrew-core#132675
Currently, there are no releases. and the version is hard-coded v0.0.1. There should be an automatic way to get the release name.
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
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())
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.