Skip to content

Commit 9100836

Browse files
henrybarretogustavosbarreto
authored andcommitted
feat(api,ssh,gateway): remove refresh and use air
As refresh package, used to rebuild the service when the code changes, seem don't be maintained anymore, we have decided to change to air, a more modern alternative. Beyond that, we also added 'dlv' to the air, allowing use to attach a debug to the service through the container's IP on the port `:2345`. With the container's IP in your hands, you just need to connect to it using the 'dlv' connect command. It is worth to notice that, as `agent`'s container runs on host network, you don't need to specify the IP when debugging it. ```sh dlv connect <IP>:2345 ``` As the code built in the container lives in another GOPATH, you can need to remap this path to your local environment. To perform that, you can open or create the file `~/.config/dlv/config.yml`, and insert this snippet. ```yml substitute-path: [ { from: "/go", to: "<GOPATH in your local machine>" } ] ```
1 parent 5f24c14 commit 9100836

11 files changed

+119
-34
lines changed

.gitignore

+12-14
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
1+
.env.override
2+
docker-compose.override.yml
3+
14
*~
5+
*/tmp
6+
*/node_modules
7+
*.orig
8+
29
api_private_key
310
api_public_key
411
ssh_private_key
5-
/go.sum
6-
/ui/node_modules/
7-
*.orig
8-
.env.override
9-
docker-compose.override.yml
10-
gateway/gateway
11-
api/api
12-
ssh/ssh
13-
agent/agent
14-
agent/shellhub.key
15-
cli/cli
12+
1613
go.work
1714
go.work.sum
18-
connector/.keys
19-
connector/connector
20-
*/tmp
15+
go.sum
16+
17+
cli/cli
18+
agent/shellhub.key
2119

2220
# Directory used by devscripts/run-agent to store binaries
2321
bin/agent

api/.air.toml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
root = "."
2+
tmp_dir = "tmp"
3+
4+
[build]
5+
pre_cmd = []
6+
cmd = "go build -gcflags=\"all=-N -l\" -o ./tmp/main ."
7+
post_cmd = []
8+
bin = ""
9+
full_bin = "dlv exec ./tmp/main"
10+
args_bin = [
11+
"--listen=0.0.0.0:2345",
12+
"--headless",
13+
"--continue",
14+
"--accept-multiclient",
15+
"--",
16+
"server",
17+
]
18+
delay = 500
19+
exclude_dir = ["assets", "tmp", "vendor", "testdata"]
20+
exclude_file = []
21+
exclude_regex = ["_test.go"]
22+
exclude_unchanged = false
23+
follow_symlink = false
24+
include_dir = []
25+
include_ext = ["go", "tpl", "tmpl", "html"]
26+
include_file = []
27+
kill_delay = "0s"
28+
log = "build-errors.log"
29+
poll = false
30+
poll_interval = 0
31+
rerun = false
32+
rerun_delay = 500
33+
send_interrupt = false
34+
stop_on_error = false

api/Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ ARG GOPROXY
4040
ENV GOPROXY ${GOPROXY}
4141

4242
RUN apk add --update openssl build-base docker-cli
43-
RUN go install github.com/markbates/[email protected] && \
43+
RUN go install github.com/air-verse/[email protected] && \
44+
go install github.com/go-delve/delve/cmd/[email protected] && \
4445
go install github.com/golangci/golangci-lint/cmd/[email protected] && \
4546
go install github.com/vektra/mockery/v2/[email protected]
4647

api/entrypoint-dev.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ fi
1212

1313
ln -sf $PWD/api /api
1414

15-
refresh run
15+
air

gateway/.air.toml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
root = "."
2+
tmp_dir = "tmp"
3+
4+
[build]
5+
pre_cmd = []
6+
cmd = "go build -gcflags=\"all=-N -l\" -o ./tmp/main ."
7+
post_cmd = []
8+
bin = ""
9+
full_bin = "dlv exec ./tmp/main"
10+
args_bin = [
11+
"--listen=0.0.0.0:2345",
12+
"--headless",
13+
"--continue",
14+
"--accept-multiclient",
15+
]
16+
delay = 500
17+
exclude_dir = ["assets", "tmp", "vendor", "testdata"]
18+
exclude_file = []
19+
exclude_regex = ["_test.go"]
20+
exclude_unchanged = false
21+
follow_symlink = false
22+
include_dir = []
23+
include_ext = ["go", "tpl", "tmpl", "html"]
24+
include_file = []
25+
kill_delay = "0s"
26+
log = "build-errors.log"
27+
poll = false
28+
poll_interval = 0
29+
rerun = false
30+
rerun_delay = 500
31+
send_interrupt = false
32+
stop_on_error = false

gateway/Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ RUN mkdir -p /var/run/openresty /etc/letsencrypt && \
4040
curl -sSL https://ssl-config.mozilla.org/ffdhe2048.txt -o /etc/shellhub-gateway/dhparam.pem
4141

4242
RUN apk add --update openssl build-base
43-
RUN go install github.com/markbates/[email protected] && \
43+
RUN go install github.com/air-verse/[email protected] && \
44+
go install github.com/go-delve/delve/cmd/[email protected] && \
4445
go install github.com/golangci/golangci-lint/cmd/[email protected] && \
4546
go install github.com/vektra/mockery/v2/[email protected]
4647

gateway/entrypoint-dev.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
ln -sf $PWD/gateway /gateway
44

5-
refresh run
5+
air

gateway/refresh.yml

-14
This file was deleted.

ssh/.air.toml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
root = "."
2+
tmp_dir = "tmp"
3+
4+
[build]
5+
pre_cmd = []
6+
cmd = "go build -gcflags=\"all=-N -l\" -o ./tmp/main ."
7+
post_cmd = []
8+
bin = ""
9+
full_bin = "dlv exec ./tmp/main"
10+
args_bin = [
11+
"--listen=0.0.0.0:2345",
12+
"--headless",
13+
"--continue",
14+
"--accept-multiclient",
15+
]
16+
delay = 500
17+
exclude_dir = ["assets", "tmp", "vendor", "testdata"]
18+
exclude_file = []
19+
exclude_regex = ["_test.go"]
20+
exclude_unchanged = false
21+
follow_symlink = false
22+
include_dir = []
23+
include_ext = ["go", "tpl", "tmpl", "html"]
24+
include_file = []
25+
kill_delay = "0s"
26+
log = "build-errors.log"
27+
poll = false
28+
poll_interval = 0
29+
rerun = false
30+
rerun_delay = 500
31+
send_interrupt = false
32+
stop_on_error = false

ssh/Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ ARG GOPROXY
4040
ENV GOPROXY ${GOPROXY}
4141

4242
RUN apk add --update openssl
43-
RUN go install github.com/markbates/[email protected] && \
43+
RUN go install github.com/air-verse/[email protected] && \
44+
go install github.com/go-delve/delve/cmd/[email protected] && \
4445
go install github.com/golangci/golangci-lint/cmd/[email protected] && \
4546
go install github.com/vektra/mockery/v2/[email protected]
4647

ssh/entrypoint-dev.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ if [ ! -f /var/run/secrets/ssh_private_key ]; then
99
openssl genrsa -out /var/run/secrets/ssh_private_key 2048
1010
fi
1111

12-
refresh run
12+
air

0 commit comments

Comments
 (0)