A very useful setup for debugging porter development #2231
richbai90
started this conversation in
Show and tell
Replies: 1 comment
-
Made a few minor changes to the Dockerfile and debug script to correct some permissions and build errors. Errors were minor and could probably be fixed by anyone using the script, but it should all be correct now. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I've recently undertaken several development projects relating to Porter, from working with the team to implement new core features, to developing custom Mixins around those features. Unit tests are of course extremely valuable, but sometimes it is nice to step through the execution of your bundle to debug exactly what is happening. With a simple docker file, a bash script, and some vscode configuration, a debug setup can be made to step through the code just as though it were executed via the Porter CLI. I hope this information helps you as much as it has me.
Setup steps
devcontainer.json
file below.vscode
folder. (Create it if it doesn't exist)tasks.json
andlaunch.json
config files from the files section below.12.Files
Note: Any text in the files that follow, surrounded in {}, where the curly braces do not constitute appropriate syntax -- as in the case of the ${} notation in the Dockerfile -- should be replaced with the actual string referenced. If it appears in a comment, replacement is not necessary, but should be understood to mean the same.
Dockerfile
porter-debug.sh
devcontainer.json
/mixin/.vscode/tasks.json
/mixin/.vscode/launch.json
/porter/.vscode/tasks.json
/porter/.vscode/launch.json
Final notes
Some mixin actions expect to read snippets of the yaml file from stdin. For these actions you can create a reader to use instead of stdin inside your mixin code. When you do this, you will want to protect this code from running during a production build. The porter debug flag can be run by any user in any environment so it is not a good idea to rely on this flag to supply testing data to the mixin. Instead, I opt to set an env variable in my launch config and check for it. This is a pattern similar to how these actions are tested in the built-in template tests. Here is an example from a mixin I'm developing:
Beta Was this translation helpful? Give feedback.
All reactions