You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/website/docs/user-guides/advanced/debugging-with-openshift-toolkit.md
+220-5Lines changed: 220 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
---
2
-
title: Running an Application with OpenShift Toolkit
2
+
title: Debugging an Application with OpenShift Toolkit
3
3
sidebar_position: 7
4
4
---
5
5
@@ -13,20 +13,24 @@ However, this task is made absurdly simple with the help of OpenShift Toolkit.
13
13
14
14
## Prerequisites
15
15
1.[You have logged in to your cluster](../quickstart/nodejs.md#step-1-connect-to-your-cluster-and-create-a-new-namespace-or-project).
16
-
2.[You have initialized a Node.js application with odo](../quickstart/nodejs.md#step-2-initializing-your-application--odo-init-).
17
-
3. Open the application in the IDE.
18
-
4. Install OpenShift Toolkit Plugin in your preferred VS Code or a Jet Brains IDE.
16
+
2.[You have initialized a Node.js application with odo](../quickstart/nodejs.md#step-2-initializing-your-application-odo-init).
17
+
:::note
18
+
This tutorial uses a nodejs application, but you can use any application that has Devfile with debug command defined in it. If your Devfile does not contain a debug command, refer [Configure Devfile to support debugging](#configure-devfile-to-support-debugging).
19
+
:::
20
+
3. You have installed OpenShift Toolkit Plugin in your preferred VS Code or a Jet Brains IDE.
21
+
4. You have opened the application in the IDE.
19
22
20
23
In the plugin window, you should be able to see the cluster you are logged into in "APPLICATION EXPLORER" section, and your component "my-nodejs-app" in "COMPONENTS" section.
1. Add an exec command with `group`:`kind` set to `debug`. The debugger tool you use must be able to start a debug server that we can later on connect to. The binary for your debugger tool should be made available by the container component image.
128
+
```yaml
129
+
commands:
130
+
- exec:
131
+
env:
132
+
- name: GOPATH
133
+
value: ${PROJECT_SOURCE}/.go
134
+
- name: GOCACHE
135
+
value: ${PROJECT_SOURCE}/.cache
136
+
commandLine: |
137
+
dlv \
138
+
--listen=127.0.0.1:${DEBUG_PORT} \
139
+
--only-same-user=false \
140
+
--headless=true \
141
+
--api-version=2 \
142
+
--accept-multiclient \
143
+
debug --continue main.go
144
+
component: runtime
145
+
group:
146
+
isDefault: true
147
+
kind: debug
148
+
workingDir: ${PROJECT_SOURCE}
149
+
id: debug
150
+
```
151
+
For the example above, we use [`dlv`](https://github.com/go-delve/delve) debugger for debugging a Go application and it listens to port exposed by env variable *DEBUG_PORT* inside the container. The debug command references a container component called "runtime".
152
+
153
+
2. Add Debug endpoint to the container component's [`endpoints`](https://devfile.io/docs/2.2.0/defining-endpoints) with `exposure` set to `none` so that it cannot be accessed from outside, and export the debug port number via `DEBUG_PORT` `env` variable.
154
+
155
+
The debug endpoint name must be named **debug** or be prefixed by **debug** so that `odo` can recognize it as a debug port.
For the example above, we assume that the "runtime" container's `image` provides the binary for delve debugger. We also add an endpoint called "debug" with `targetPort` set to *5858* and `exposure` set to `none`. We also export debug port number via `env` variable called `DEBUG_PORT`.
181
+
182
+
The final Devfile should look like the following:
183
+
<details>
184
+
<summary>Go Devfile configured for debugging</summary>
0 commit comments