aslafy-z / helm-git

Helm Plugin - Install Helm Charts strait from Git repositories
Apache License 2.0
293 stars 46 forks source link

Feature: Support Windows #121

Open ziaenezhad opened 4 years ago

ziaenezhad commented 4 years ago

helm-git doesn't work on my Windows 10

helm-git version: 0.8.1

Steps To Reproduce

  1. Running :
    helm repo add cert-manager git+https://github.com/jetstack/cert-manager@deploy/charts?ref=v0.6.2

Shows this error:

Error: looks like "git+https://github.com/jetstack/cert-manager@deploy/charts?ref=v0.6.2" is not a valid chart repository or cannot be reached: exec: "C:\\Users\\Sajjad\\AppData\\Roaming\\helm\\plugins\\helm-git\\helm-git": file does not exist
aslafy-z commented 4 years ago

I have no windows system to try this on. Can you enable debugging with export HELM_GIT_DEBUG=1 and post the output? Thanks

ziaenezhad commented 3 years ago

I did, but no more information, just like before:

Error: looks like "git+https://github.com/jetstack/cert-manager@deploy/charts?ref=v0.6.2" is not a valid chart repository or cannot be reached: exec: "C:\\Users\\Sajjad\\AppData\\Roaming\\helm\\plugins\\helm-git\\helm-git": file does not exist
ziaenezhad commented 3 years ago

I worked a bit more on it. The error was because we can't directly execute shell scripts on windows. so I made a new file helm-git.bat and set the command attribute within plugin.yaml to trigger this one, instead of the default to wrap the shell script:

sh ./helm-git %0 "%2" "%3" %4

now I'm getting this:

$ helm repo add cert-manager git+https://github.com/jetstack/cert-manager@deploy/charts?ref=v0.6.2
write /dev/stdout: The pipe is being closed.
Error: looks like "git+https://github.com/jetstack/cert-manager@deploy/charts?ref=v0.6.2" is not a valid chart repository
or cannot be reached: error converting YAML to JSON: yaml: line 5: mapping values are not allowed in this context

any idea?

aslafy-z commented 3 years ago

Thanks for taking time to work on this. Is debugging enabled?

ziaenezhad commented 3 years ago

nope, it's with the debugging:

helm repo add cert-manager git+https://github.com/jetstack/cert-manager@deploy/charts?ref=v0.6.2
write /dev/stdout: The pipe is being closed.
Warning in plugin 'helm-git': git_ref is empty, defaulted to 'master'. Prefer to pin GIT ref in URI.
Debug in plugin 'helm-git': repo: https://github.com/jetstack/cert-manager ref: master path: deploy/charts file: index.yaml sparse: 1 depupdate: 1
Debug in plugin 'helm-git': helm_repo_uri: git+https://github.com/jetstack/cert-manager@deploy/charts?ref=master&sparse=1&depupdate=1
Error: looks like "git+https://github.com/jetstack/cert-manager@deploy/charts?ref=v0.6.2" is not a valid chart repository or cannot be reached: error converting YAML to JSON: yaml: line 5: mapping values are not allowed in this context
aslafy-z commented 3 years ago

Can you try with the following build (with debug enabled): #133 I added some logs to try to nail the issue

ziaenezhad commented 3 years ago

yes:

$ helm repo add cert-manager git+https://github.com/jetstack/cert-manager@deploy/charts?ref=v0.6.2
write /dev/stdout: The pipe is being closed.
Warning in plugin 'helm-git': git_ref is empty, defaulted to 'master'. Prefer to pin GIT ref in URI.
Debug in plugin 'helm-git': repo: https://github.com/jetstack/cert-manager ref: master path: deploy/charts file: index.yaml sparse: 1 depupdate: 1
Debug in plugin 'helm-git': helm_repo_uri: git+https://github.com/jetstack/cert-manager@deploy/charts?ref=master&sparse=1&depupdate=1
Debug in plugin 'helm-git': helm index produced at /tmp/helm-git.Lp6Iqi/index.yaml: apiVersion: v1
entries:
  cert-manager:
  - apiVersion: v1
    appVersion: v0.1.0
    created: "2020-11-18T08:13:45.3239102+03:30"
    description: A Helm chart for cert-manager
    digest: cfbf6057fbc395ea243f747221c749515cc78324da3bc624bcd6aee074d7855b
    home: https://github.com/jetstack/cert-manager
    icon: https://raw.githubusercontent.com/jetstack/cert-manager/master/logo/logo.png
    keywords:
    - cert-manager
    - kube-lego
    - letsencrypt
    - tls
    maintainers:
    - email: james@jetstack.io
      name: munnerz
    name: cert-manager
    sources:
    - https://github.com/jetstack/cert-manager
    urls:
    - git+https://github.com/jetstack/cert-manager@deploy/charts/cert-manager-v0.1.0.tgz?ref=master&sparse=1&depupdate=1
    version: v0.1.0
generated: "2020-11-18T08:13:45.3209792+03:30"
Error: looks like "git+https://github.com/jetstack/cert-manager@deploy/charts?ref=v0.6.2" is not a valid chart repository or cannot be reached: error converting YAML to JSON: yaml: line 5: mapping values are not allowed in this context

Also, I'm getting these params in my bat file, if helps:

echo "%0 %1 %2 %3 %4 %5"
"C:\Users\Sajjad\AppData\Roaming\helm\plugins\helm-git\helm-git.bat "" "" "" git+https://github.com/jetstack/cert-manager@deploy/charts/index.yaml?ref v0.6.2 "
aslafy-z commented 2 years ago

I think you may need to quote the %4 in your bat file.

aslafy-z commented 2 years ago

@sajjad-shirazy Any updates?

frizzr commented 2 years ago

@aslafy-z While I would absolutely love to have this plugin working on Windows, I definitely sympathize with the difficulty of getting shell scripts running on Windows.

If you don't mind some unsolicited advice on a different direction you could look at for a short-term workaround...

Keep in mind this is just an idea, I would need to test it a bit with a local copy of your plugin:

Make a Windows-compatible version by

  1. Requiring Windows users to have busybox.exe for Windows in their path, giving Windows users the ability to effectively run your sh scripts unmodified
  2. Changing your helm-git root script to be compatible with both Windows (bat) and Linux (sh) by using these principles, which effectively gives you separate sections of this single file to put both Windows BAT code and sh code into while allowing the same file to be run on both platforms.
  3. Finally, you embed this code into the Windows BAT code section (and of course give credit to skanga for a good idea!) which would then use busybox for Windows to run your child script (helm-git-plugin.sh.) You would need to slightly modify the BAT code linked here to directly run the helm-git-plugin.sh script instead of using the default logic that uses the name of the script where the BAT code runs.

The nice thing about busybox is that it is smart enough to back out to Windows when it cannot find an executable, so git, for example, would call the Windows git executable.

It's not a long-term solution. For that, I would recommend making a powershell version of your helm-git-plugin.sh. Powershell comes with Windows anyway and it is easier to convert from sh to Powershell than it is from sh to BAT. Then you could rework the root helm-git script with the same framework as above, but the BAT section would then call Powershell instead of busybox.