Skip to content
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

Add Pulumi support #335

Merged
merged 10 commits into from
Sep 20, 2022
Merged

Add Pulumi support #335

merged 10 commits into from
Sep 20, 2022

Conversation

devansh08
Copy link
Contributor

@devansh08 devansh08 commented Aug 25, 2022

Description

Add a right prompt section for displaying current Pulumi stack of the project. It reads the stack name from a local json file named using hash of the project path. This section will only show up if the directory has a Pulumi.yaml file (similar to a package.json file for node), which is something that's always created by pulumi for a new project.

Motivation and Context

Pulumi is an IaaC tool that I use quite often from the command line and knowing the current stack that I am on before running commands is quite helpful.

Screenshots (if appropriate)

Yellow prompt section in below screenshots. dev is the name of the current stack.

Lean
lean

Classic
classic

Rainbow
rainbow

How Has This Been Tested

  • I have tested using Linux.
  • I have tested using MacOS.

Checklist

  • I have updated the documentation accordingly. - Would like to know where and what do I need to update :)
  • I have updated the tests accordingly.

@IlanCosman
Copy link
Owner

Hi! Sorry for the delayed response, and thanks for contributing 🙂

Unfortunately this isn't in a state I'd be comfortable merging. External commands like grep and cat should be replaced with fish builtins such as string match and redirection (some_command <file.txt). Those should be pretty simple to fix, but the biggest problem is with running python code, which is just not something I want to do.

Is there really no pulumi print-stack or pulumi context or something like that? That would be the optimal solution.

@devansh08
Copy link
Contributor Author

Hi, thanks for checking this out!

External commands like grep and cat should be replaced with fish builtins such as string match and redirection (some_command <file.txt).

Will update those.

Those should be pretty simple to fix, but the biggest problem is with running python code, which is just not something I want to do.
Is there really no pulumi print-stack or pulumi context or something like that? That would be the optimal solution.

I actually did find out couple of days ago there is a command pulumi stack --show-name which gives the stack name (I blame the poor --help description for not spotting this sooner 😄). But it is a bit slow whenever I've used it, especially when a cloud service like AWS is used for storing the config/data. Honestly, I'm not sure why it takes so much time to just read a local file (current stack info is always stored in a local file, which is what my Python code reads).

For comparison, this is the time difference in using the command and using the Python script:
Screenshot_20220917_005617

It consistently takes ~1+ seconds. I think the speed of the pulumi command also depends on the number of stacks for the project, as I have seen this command take upto 3+ seconds on some actual projects, even while I was on a more powerful machine.

As a point, the method of reading the stack info is inspired from the Starship prompt, from this function in particular. As noted in their comment as well, pulumi does not really have a command that's fast enough for prompt usage.

If there is a better fish/shell/anything based approach you (or anyone else here) can suggest for creating the SHA1 hash of the project path string, the Python dependency can be removed. Python was the fastest solution for calculating the hash I could come up with.

Thanks!

@IlanCosman
Copy link
Owner

If there is a better fish/shell/anything based approach you (or anyone else here) can suggest for creating the SHA1 hash

Indeed there is: shasum on MacOS (and bsd?) and sha1sum on Linux.

I'm on a mac right now, so the replacement for your python would be echo -n $yaml_path | shasum | string sub -e40. From benchmarking it is a 1.5x speedup. Afaict it should be the exact same code on Linux, just with sha1sum.

If you could remove the python code and instead check for shasum vs sha1sum (using command -q) and then use the appropriate one, that would be great :)

@IlanCosman
Copy link
Owner

Aww snap don't tell anyone but just adding the -S flag to your python makes it faster than my shasum code. Still though I think it's better to use coreutils and 1. avoid necessitating python for this item, and 2. avoid python vs python3 etc.

@devansh08
Copy link
Contributor Author

I actually forgot to mention in my previous message that I had tried sha1sum before going with Python and it did not work. But realized now I did not remove the newline from it 😞. It does seem to be working correctly now with sha1sum. Will verify and update my code.

Thanks!

@devansh08
Copy link
Contributor Author

Hi, I've updated it with your suggestions. Lemme know your thoughts.

Thanks!

@IlanCosman
Copy link
Owner

I made some improvements/changes to the code, feel free to take a look at them and comment/ask questions :)

@devansh08
Copy link
Contributor Author

Hey, the improvements look good to me! So many fish builtins I did not know about till this PR 😄

Thanks!

@IlanCosman IlanCosman merged commit 0a83ef6 into IlanCosman:main Sep 20, 2022
@devansh08 devansh08 deleted the add-pulumi branch August 21, 2023 02:45
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants