Skip to content

Commit

Permalink
Update the debugging documentation
Browse files Browse the repository at this point in the history
**What type of PR is this?**
> Uncomment only one ` /kind` line, and delete the rest.
> For example, `> /kind bug` would simply become: `/kind bug`

/kind documentation
[skip ci]

**What does does this PR do / why we need it**:

Updates the debugging documentation with more information with example
output as well as a link to VSCode debugging tools

**Which issue(s) this PR fixes**:

N/A

**PR acceptance criteria**:

- [ ] Unit test

- [ ] Integration test

- [X] Documentation

- [ ] I have read the [test guidelines](https://github.com/openshift/odo/blob/master/docs/dev/test-architecture.adoc)

**How to test changes / Special notes to the reviewer**:

Signed-off-by: Charlie Drage <[email protected]>
  • Loading branch information
cdrage committed Sep 24, 2020
1 parent 99d6e03 commit ea9d9df
Showing 1 changed file with 76 additions and 36 deletions.
112 changes: 76 additions & 36 deletions docs/public/debugging-using-devfile.adoc
Original file line number Diff line number Diff line change
@@ -1,29 +1,11 @@
# Debugging components using devfiles

`odo` uses devfiles to build and deploy components. More information on devifles : https://redhat-developer.github.io/devfile/[Introduction to devfile]

In order to use `odo debug` your devfile is required to have a `debugrun` step. Example of a nodejs devfile with a debugrun step:

```yaml
schemaVersion: 2.0.0
metadata:
name: nodejs
version: 1.0.0
starterProjects:
- name: nodejs-starter
git:
remotes:
origin: "https://github.com/odo-devfiles/nodejs-ex.git"
components:
- name: runtime
container:
image: registry.access.redhat.com/ubi8/nodejs-12:1-45
memoryLimit: 1024Mi
mountSources: true
sourceMapping: /project
endpoints:
- name: http-3000
targetPort: 3000
= Debugging a component

Debugging your component involves port forwarding with the Kubernetes pod. Before you start, it is required that you have a `kind: debug` step located within your `devfile.yaml`.

. See below for an example `devfile.yaml` that containers a `debugrun` step under the `commands` key:
[source,yaml]
----
...
commands:
- id: install
exec:
Expand All @@ -49,18 +31,76 @@ commands:
group:
kind: debug
isDefault: true
```
----

== Debugging your devfile component via CLI

We will use the official link:https://github.com/odo-devfiles/registry/tree/master/devfiles/nodejs[nodejs] example in our debugging session which includes the necessary `debugrun` step within `devfile.yaml`.

. Download the example application:
+
[source,sh]
----
$ odo create nodejs --starter
Validation
✓ Checking devfile existence [11498ns]
✓ Checking devfile compatibility [15714ns]
✓ Creating a devfile component from registry: DefaultDevfileRegistry [17565ns]
✓ Validating devfile component [113876ns]
Starter Project
✓ Downloading starter project nodejs-starter from https://github.com/odo-devfiles/nodejs-ex.git [428ms]
Please use `odo push` command to create the component with source deployed
----

- Now we need to create the component using `odo create nodejs`
- Next we enable remote debugging for the component using `odo push --debug`. We can also use a custom step as the debugrun step using `odo push --debug --debug-command="custom-step"`
- Next we port forward a local port for debugging using `odo debug port-forward`. The default local port used for debugging is 5858. If 5858 is occupied, odo will automatically pick up a local port. We can also specify the local port using, `odo debug port-forward --local-port 5858`
- Next we need to attach the debugger to the local port. Here's a guide to do it for VS Code : https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_remote-debugging[Remote Debugging]
. Push with the `--debug` flag which is required for all debugging deployments:
+
[source,sh]
----
$ odo push --debug
### Check if a debugging session is running
Validation
✓ Validating the devfile [29916ns]
We can check if a debugging session is running for a component by using `odo debug info`
Creating Kubernetes resources for component nodejs
✓ Waiting for component to start [38ms]
```
odo debug info
Applying URL changes
✓ URLs are synced with the cluster, no changes are required.
Syncing to component nodejs
✓ Checking file changes for pushing [1ms]
✓ Syncing files to the component [778ms]
Executing devfile commands for component nodejs
✓ Executing install command "npm install" [2s]
✓ Executing debug command "npm run debug" [1s]
Pushing devfile component nodejs
✓ Changes successfully pushed to component
----
+
NOTE: A custom debug command may be chosen via the `--debug-command="custom-step"` flag.

. Port forward to the local port in order to access the debugging interface:
+
[source,sh]
----
$ odo debug port-forward
Started port forwarding at ports - 5858:5858
----
+
NOTE: A specific port may be specified using the `--local-port` flag

. Checking that the debug session is running in a separate terminal window:
+
[source,sh]
----
$ odo debug info
Debug is running for the component on the local port : 5858
```
----

. Accessing the debugger:
+
Accessing the debugger is accessible through an assortment of tools. An example of setting up a debug interface would be through link:https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_remote-debugging[VSCode's debugging interface].

0 comments on commit ea9d9df

Please sign in to comment.