Skip to content

Commit e6f959d

Browse files
authored
[server] allow debugging (#17911)
1 parent 4fd4f66 commit e6f959d

File tree

4 files changed

+49
-9
lines changed

4 files changed

+49
-9
lines changed

.vscode/launch.json

+17-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
{
22
"configurations": [
3+
{
4+
"name": "Attach to Kubernetes Node",
5+
"type": "node",
6+
"request": "attach",
7+
"smartStep": true,
8+
"port": 9229,
9+
"address": "127.0.0.1",
10+
"localRoot": "${workspaceFolder}/components",
11+
"remoteRoot": "/app/node_modules/@gitpod",
12+
"skipFiles": [
13+
"<node_internals>/**"
14+
]
15+
},
316
{
417
"name": "Attach to Node",
518
"type": "node",
@@ -21,19 +34,18 @@
2134
"mode": "remote"
2235
},
2336
{
24-
// This will run the db-test yarn target in the gitpod-db component.
25-
// This allows you to set breakpoints in your tests and step through
26-
// them with the VSCode debugger.
2737
"type": "node",
2838
"request": "launch",
2939
"name": "gitpod-db-tests",
3040
"cwd": "${workspaceFolder}/components/gitpod-db",
3141
"runtimeExecutable": "yarn",
32-
"runtimeArgs": ["db-test"],
42+
"runtimeArgs": [
43+
"db-test"
44+
],
3345
"internalConsoleOptions": "openOnSessionStart",
3446
"skipFiles": [
3547
"<node_internals>/**"
3648
]
3749
}
3850
]
39-
}
51+
}

components/server/debug.sh

+25-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,27 @@
11
#!/bin/bash
22

3-
set -Eeuo pipefail
4-
source /workspace/gitpod/scripts/ws-deploy.sh deployment server
3+
deploymentName="server"
4+
debugPort="9229"
5+
6+
echo "Storing the original deployment configuration in a file"
7+
kubectl get deployment $deploymentName -o json > original_deployment_$deploymentName.json
8+
9+
function restore {
10+
echo "Restoring the original deployment configuration and stop port forwarding"
11+
kubectl replace --force -f original_deployment_$deploymentName.json
12+
rm original_deployment_$deploymentName.json
13+
}
14+
trap restore EXIT
15+
16+
echo "Add the inspect flag and debug port to the configuration"
17+
jq '.spec.template.spec.containers[0].command = ["yarn", "start-inspect"]' original_deployment_$deploymentName.json > new_deployment_$deploymentName.json
18+
19+
echo "Apply the new configuration"
20+
kubectl apply -f new_deployment_$deploymentName.json
21+
rm new_deployment_$deploymentName.json
22+
23+
echo "Scale down to one pod"
24+
kubectl scale deployment $deploymentName --replicas=1
25+
26+
echo "Forward the port $debugPort to localhost. Waiting for a debugger to attach ..."
27+
kubectl port-forward deployment/$deploymentName $debugPort

components/server/deploy.sh

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
set -Eeuo pipefail
4+
source /workspace/gitpod/scripts/ws-deploy.sh deployment server

components/server/package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"license": "AGPL-3.0",
66
"scripts": {
77
"start": "node ./dist/main.js",
8-
"start-inspect": "node --inspect=9229 ./dist/main.js",
8+
"start-inspect": "node --inspect=0.0.0.0:9229 ./dist/main.js",
99
"prepare": "yarn clean && yarn build",
1010
"build": "yarn lint && npx tsc",
1111
"build:clean": "yarn clean && yarn build",
@@ -22,7 +22,8 @@
2222
"telepresence": "telepresence --swap-deployment server --method inject-tcp --run yarn start-inspect"
2323
},
2424
"files": [
25-
"/dist"
25+
"/dist",
26+
"/src"
2627
],
2728
"dependencies": {
2829
"@authzed/authzed-node": "^0.10.0",

0 commit comments

Comments
 (0)