New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CLI flag to launch Pulumi program under a debugger #1372
Comments
Moving this out. We'll probably do this around the same time that we try to support doing more Pulumi stuff from within the language host itself (e.g. when we support managing the lifecycle of a stack in the source program itself, so you can write tests using your favorite framework). |
With .NET support, this should get up in the queue IMO, and .NET folks love their F5-debugging. |
Adding my 2cts, not sure why that works but it seems to, by using the
typescript program, pulumi 3.10.3, node 12, vscode 1.59.1 |
For people using Python and VSCode, here is an alternative.
import debugpy
debugpy.listen(("localhost", 5678))
max_wait_s = 30
while max_wait_s >= 0:
if debugpy.is_client_connected():
break
time.sleep(1)
max_wait_s -= 1 To start debugging, simply run If no debugger is attached after 30 seconds, execution will continue. |
For people using GoLand and Go (This idea may apply to other languages):
After understanding the execution method, we only need to create a simple script, then execute the dlv debugging command in the script, and finally turn on the remote Debug function of GoLand, we can happily Coding. Below is the detailed tutorial:This is my project structure:~/o/p/xxxx ❯❯❯ tree
.
├── Pulumi.yaml
├── common.go
├── debug.sh
├── deployment.go
├── go.mod
├── go.sum
├── goapp
├── main.go
└── service.go
0 directories, 9 files Compile Code to bin fileFor GoLand's remote Debug, we need to compile our code using the following command: # this will generate an executable file with debug symbols (goapp)
go build -o goapp -gcflags "all=-N -l" . Create debug scriptWe create a bash script to execute the dlv command:
#!/bin/bash
dlv --listen=:2345 --headless=true --api-version=2 --accept-multiclient exec ./goapp Save the above code as Update
|
I would like to suggest a better approach which pauses the code and waits for a client to attach: import debugpy
debugpy.listen(("0.0.0.0", 5678))
print("debugpy is listening, attach by pressing F5 or ►")
debugpy.wait_for_client()
print("Attached to debugpy!") Since I am working with Unable to open '__main__.py': Unable to read file '/pulumi/__main__.py' (Error: Unable to resolve non-existing file '/pulumi/__main__.py'). You can solve this issue by changing the remote path in the "pathMappings": [
{
"localRoot": "${workspaceFolder}/",
"remoteRoot": "${workspaceFolder}/" # <-- default is empty which results in the root project directory
}
] |
I'm using Typescript and this works for me: ❯ code --version
1.63.0
7db1a2b88f7557e0a43fec75b6ba7e50b3e9f77e
x64
Notice the "debug" prompt above the scripts section. In between lines 5 and 6. You can click that and vscode will open up a debug console. Works perfectly. |
I can confirm simply starting it in a debugger as @harryttd described, works in Webstorm too. |
Is it possible to use any of the
Edit: I missed this comment regarding delve and remote debugging in goland (#1372 (comment)) |
Note that nodejs programs can be quite easily debugged using vscodes auto-attach system (https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_auto-attach) Turn on auto attach and then run |
Or you can create a new terminal with the type |
I have found a simpler way to debug pulumi go project in VSCode. There is no need to build the project upfront nor add
|
Anyone got this working with IPython? E.g. import pulumi
from pulumi_gcp import storage
# Create a GCP resource (Storage Bucket)
bucket = storage.Bucket('my-bucket', location="eu")
import IPython; IPython.embed(using=False) The debug point is then totally skipped when running Pulumi
|
Below is an enhanced single click solution which worked for me to debug my Python Pulumi project on a Mac:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "pulumi up",
"type": "shell",
"isBackground": true,
"command": "pulumi up",
"presentation": {
"reveal": "silent"
},
// This task is run before some debug tasks.
// Problem is, it's a watch script, and since it never exits, VSCode
// complains. All this is needed so VSCode just lets it run.
"problemMatcher": [
{
"pattern": [
{
"regexp": ".",
"file": 1,
"location": 2,
"message": 3
}
],
"background": {
"activeOnStart": true,
"beginsPattern": ".",
"endsPattern": ".",
}
}
]
},
{
"label": "Wait 30 seconds",
"type": "shell",
"command": "sleep 3",
"presentation": {
"reveal": "silent"
}
},
{
"label": "Run pulumi up and wait to start",
"dependsOn": ["pulumi up", "Wait 30 seconds"]
}
]
}
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Remote Attach",
"type": "python",
"request": "attach",
"connect": {
"host": "localhost",
"port": 5678
},
"preLaunchTask": "Run pulumi up and wait to start",
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "."
}
],
"justMyCode": true
}
]
}
import debugpy
debugpy.listen(("localhost", 5678))
debugpy.wait_for_client() Run the debugger with the "Python: Remote Attach" configuration Note: If the solution throws an exception and you receive errors that the port is already taken when you attempt to run the debugger you may want to check for a previously run and not shut down debugpy process and shut it down with the following commands: ps aux | grep debugpy Thank you to all people in this thread for providing their solutions which I based mine on. |
There is a way for
|
@swgillespie This issue/discussion would better be refined into issues/topics for specific languages. |
@weijiany thank you so much!!!! this is life changing! |
How did you use ? In the first step when I write this command on terminal and tap to enter the pulumi starts to work! since there is problem in my pulumi codes after starting I will get error. I want to debug it but this guild does not work for me. |
NODE_OPTIONS is a nodejs specific option. The simplest thing I've seen for dotnet is to add a call to |
Thanks for response , If I run it without pulumi I got this error :
How can I use with pulumi preview ? I mean If I run pulumi preview by terminal , How can I debug it ? |
Add a call to pulumi will run the program with the environment needed for the sdk to work, and the N.B. |
I am using mac, I was using both but not working :
|
Summarizing how to attach across the SDKs, such that the program waits for the client to attach.
|
Since we get to use ✨ real code ✨ in Pulumi programs, sometimes you just need to look at your code in a debugger. It would be cool if we could do this from the pulumi CLI.
Language hosts could optionally respond to an RPC request to launch a given program under a debugger where the debugger is listening to a given port.
The text was updated successfully, but these errors were encountered: