Skip to content

Commit 61db293

Browse files
authored
feat(scripts/develop.sh): add --debug flag to develop.sh (#12423)
Adds a `--debug` flag to `scripts/develop.sh` that will start coder under `dlv debug` instead. You can then use e.g. the following launch snippet to connect dlv: ``` { "name": "Delve Remote", "type": "go", "request": "attach", "mode": "remote", "port": 12345, } ``` You can also run invididual CLI commands under dlv e.g. ``` debug=1 scripts/coder-dev.sh list ``` Also sets CGO_ENABLED=0 in develop.sh by default.
1 parent 8585863 commit 61db293

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

scripts/coder-dev.sh

+8-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ source "${SCRIPT_DIR}/lib.sh"
1010

1111
GOOS="$(go env GOOS)"
1212
GOARCH="$(go env GOARCH)"
13+
DEBUG_DELVE="${DEBUG_DELVE:-0}"
1314
BINARY_TYPE=coder-slim
1415
if [[ ${1:-} == server ]]; then
1516
BINARY_TYPE=coder
@@ -55,4 +56,10 @@ coder)
5556
;;
5657
esac
5758

58-
exec "${CODER_DEV_BIN}" --global-config "${CODER_DEV_DIR}" "$@"
59+
runcmd=("${CODER_DEV_BIN}")
60+
if [[ "${DEBUG_DELVE}" == 1 ]]; then
61+
set -x
62+
runcmd=(dlv debug --headless --continue --listen 127.0.0.1:12345 --accept-multiclient ./cmd/coder --)
63+
fi
64+
65+
CGO_ENABLED=0 exec "${runcmd[@]}" --global-config "${CODER_DEV_DIR}" "$@"

scripts/develop.sh

+7-2
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ source "${SCRIPT_DIR}/lib.sh"
1414
set -euo pipefail
1515

1616
CODER_DEV_ACCESS_URL="${CODER_DEV_ACCESS_URL:-http://127.0.0.1:3000}"
17+
debug=0
1718
DEFAULT_PASSWORD="SomeSecurePassword!"
1819
password="${CODER_DEV_ADMIN_PASSWORD:-${DEFAULT_PASSWORD}}"
1920
use_proxy=0
2021

21-
args="$(getopt -o "" -l access-url:,use-proxy,agpl,password: -- "$@")"
22+
args="$(getopt -o "" -l access-url:,use-proxy,agpl,debug,password: -- "$@")"
2223
eval set -- "$args"
2324
while true; do
2425
case "$1" in
@@ -38,6 +39,10 @@ while true; do
3839
use_proxy=1
3940
shift
4041
;;
42+
--debug)
43+
debug=1
44+
shift
45+
;;
4146
--)
4247
shift
4348
break
@@ -136,7 +141,7 @@ fatal() {
136141
trap 'fatal "Script encountered an error"' ERR
137142

138143
cdroot
139-
start_cmd API "" "${CODER_DEV_SHIM}" server --http-address 0.0.0.0:3000 --swagger-enable --access-url "${CODER_DEV_ACCESS_URL}" --dangerous-allow-cors-requests=true "$@"
144+
DEBUG_DELVE="${debug}" start_cmd API "" "${CODER_DEV_SHIM}" server --http-address 0.0.0.0:3000 --swagger-enable --access-url "${CODER_DEV_ACCESS_URL}" --dangerous-allow-cors-requests=true "$@"
140145

141146
echo '== Waiting for Coder to become ready'
142147
# Start the timeout in the background so interrupting this script

0 commit comments

Comments
 (0)