Skip to content

Commit

Permalink
feat(agent): use air to reloader and dlv as debugger
Browse files Browse the repository at this point in the history
The Air utility is a more modern, widely used binary loader and well
currently maintained, which makes it a better option than the previous
one, the Refresh. Another addition is the use of Delve, a Golang
debugger, to facilitate the bugging process for the ShellHub Agent in
the host environment.

NOTE: This change only affects the development environment.

A good extra could append the `substitute-path` configuration to the
"~/.config/dlv/config.yml" to substitute the reference to the source
code inside the container for the host's one.
  • Loading branch information
henrybarreto committed Aug 30, 2024
1 parent d025397 commit c0b5c30
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ go.work
go.work.sum
connector/.keys
connector/connector
*/tmp

# Directory used by devscripts/run-agent to store binaries
bin/agent
32 changes: 32 additions & 0 deletions agent/.air.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
root = "."
tmp_dir = "tmp"

[build]
pre_cmd = ["rm ./tmp/dlv.sock"]
cmd = "go build -tags docker -ldflags \"-X main.AgentVersion=latest\" -gcflags=\"all=-N -l\" -o ./tmp/main ."
post_cmd = []
bin = ""
full_bin = "dlv exec ./tmp/main"
args_bin = [
"--listen unix:./tmp/dlv.sock",
"--headless",
"--continue",
"--accept-multiclient",
]
delay = 1000
exclude_dir = ["assets", "tmp", "vendor", "testdata"]
exclude_file = []
exclude_regex = ["_test.go"]
exclude_unchanged = false
follow_symlink = false
include_dir = []
include_ext = ["go", "tpl", "tmpl", "html"]
include_file = []
kill_delay = "0s"
log = "build-errors.log"
poll = false
poll_interval = 0
rerun = false
rerun_delay = 500
send_interrupt = false
stop_on_error = false
3 changes: 2 additions & 1 deletion agent/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ ARG GOPROXY
ENV GOPROXY ${GOPROXY}

RUN apk add --update openssl openssh-client
RUN go install github.com/markbates/[email protected] && \
RUN go install github.com/air-verse/[email protected] && \
go install github.com/go-delve/delve/cmd/[email protected] && \
go install github.com/golangci/golangci-lint/cmd/[email protected]

WORKDIR $GOPATH/src/github.com/shellhub-io/shellhub
Expand Down
2 changes: 1 addition & 1 deletion agent/entrypoint-dev.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh

refresh run
air
14 changes: 0 additions & 14 deletions agent/refresh.yml

This file was deleted.

0 comments on commit c0b5c30

Please sign in to comment.