Azure / draft-classic

A tool for developers to create cloud-native applications on Kubernetes.
https://draft.sh
MIT License
3.93k stars 397 forks source link

draft init fails on Windows #707

Closed radu-matei closed 6 years ago

radu-matei commented 6 years ago

Deleted the .draft directory, draft version below:

draft version
&version.Version{SemVer:"v0.14.0", GitCommit:"e7a92f6b2f05a23f4cd9cc15fc24eb98d628e5d7", GitTreeState:"clean"}

When doing draft init:

draft init
Installing default plugins...

After this step the terminal (Powershell or CMD) quits entirely - it cloned draft-pack-repo in the plugin directory. If I try to execute the scripts\get.ps1 manually, it's denied because of the execution policy.

If I'm not missing anything, we probably should add a note on the execution policy in the docs for draft init, then switch it back! Link to the docs for execution policy

If I set the execution policy to Unrestricted and execute the get script manually:

.\get.ps1
Downloading https://github.com/draftcreate/draft-pack-repo/releases/download/canary/pack-repo-vcanary-windows-amd64.zip
Exception calling "DownloadFile" with "2" argument(s): "The request was aborted: Could not create SSL/TLS secure
channel."
At C:\Users\radum\.draft\plugins\draft-pack-repo\scripts\get.ps1:13 char:1
+ (new-object System.Net.WebClient).DownloadFile($url, $file)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : WebException

Preparing to install into \plugins\draft-pack-repo\bin
Expand-Archive : The path 'C:\Users\radum\AppData\Local\Temp\pack-repo-vcanary-windows-amd64.zip' either does not
exist or is not a valid file system path.
At C:\Users\radum\.draft\plugins\draft-pack-repo\scripts\get.ps1:20 char:1
+ Expand-Archive -Path "$file" -DestinationPath "$tempDir" -Force
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (C:\Users\radum\...ndows-amd64.zip:String) [Expand-Archive], InvalidOpe
   rationException
    + FullyQualifiedErrorId : ArchiveCmdletPathNotFound,Expand-Archive

Move-Item : Cannot find path 'C:\Users\radum\AppData\Local\Temp\pack-repo\windows-amd64\pack-repo.exe' because it does
not exist.
At C:\Users\radum\.draft\plugins\draft-pack-repo\scripts\get.ps1:22 char:1
+ Move-Item -Path "$tempDir\windows-amd64\$name.exe" -Destination "$bin ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Users\radum\...4\pack-repo.exe:String) [Move-Item], ItemNotFoundExce
   ption
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.MoveItemCommand

This seems to be because of the deprecation of TLSv1/TLSv1.1 by GitHub

To check the (what I think is the default) security protocol:

[Net.ServicePointManager]::SecurityProtocol
Ssl3, Tls

appears to be Tls, which I think is TLSv1.

If you go further and set the protocol for this session to be TLSv1.2:

[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12;

and try to execute the script again - not draft init, as the command above is only valid for the current session:

Downloading https://github.com/draftcreate/draft-pack-repo/releases/download/canary/pack-repo-vcanary-windows-amd64.zip
Exception calling "DownloadFile" with "2" argument(s): "The request was aborted: The connection was closed unexpectedly."
At C:\Users\radum\.draft\plugins\draft-pack-repo\scripts\get.ps1:13 char:1
+ (new-object System.Net.WebClient).DownloadFile($url, $file)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : WebException

The same error - The request was aborted: The connection was closed unexpectedly. also appears if I switch to Invoke-WebRequest

At this point I've started looking at what version of the .NET Framework I have installed - .NET Framework 4.7.1, which comes by default with Windows 10 Fall Creators Update.

I added all supported protocols:

$AllProtocols = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12'
[System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols

[Net.ServicePointManager]::SecurityProtocol
Ssl3, Tls, Tls11, Tls12

Still the same error on a different network, and on another Windows PC.

This is annoying.

squillace commented 6 years ago

@radu-matei you might get some help from the windows folks. Would you like me to wire you up? Likely it's an easy error for them....

radu-matei commented 6 years ago

Ok, here's what happens:

PS C:\Users\radum\.draft\plugins\draft-pack-repo> git status
HEAD detached at v0.4.1
nothing to commit, working tree clean

Now if we look at get.ps1 in our directory and at get.ps1 in the v0.4.1 commit, we see that the version set for it is canary, so the plugin will try to install the canary release from GitHub, which is missing (plus a mismatch with v$version).

If you modify the install script / clone the correct branch and execute the script again, it downloads correctly, but $Env:DRAFT_HOME is not set, so it cannot copy in the correct folder:

Preparing to install into \plugins\draft-pack-repo\bin
pack-repo installed into \plugins\draft-pack-repo\bin\pack-repo.exe

And for a brief summary of this issue:

rhollins commented 6 years ago

I'm having the same issue on Windows

radu-matei commented 6 years ago

For the record, you can still use Draft, just the pack repo functionality is missing, and you can manually add the executable:

bacongobbler commented 6 years ago

This workaround works for me on Windows:

C:\Users\mafishe> draft init
C:\Users\mafishe> draft plugin remove pack-repo
C:\Users\mafishe> draft plugin install https://github.com/draftcreate/draft-pack-repo --version master
C:\Users\mafishe> draft init
Installing default plugins...Installation of default plugins complete
Installing default pack repositories...
Installing pack repo from https://github.com/Azure/draft
Installed pack repository github.com/Azure/draft
Installation of default pack repositories complete
$DRAFT_HOME has been configured at C:\Users\mafishe\.draft.
Happy Sailing!

The problem is indeed what you mentioned, @radu-matei: draft init installs draft-pack-repo v0.4.1, but get.ps1 points to the canary release. This was fixed in master for draft-pack-repo by hardcoding get.ps1 to install v0.4.1 (see https://github.com/draftcreate/draft-pack-repo/pull/21), which is why the above workaround works. :)

Honestly, the best move forward is to implement #688. The current install process for plugins is proving to be very fragile, and we were planning on doing that work anyways in 0.15. The powershell script support for plugins was purely a crutch just to get this all to work, which is why I've been focusing so hard on GoFish outside of work hours recently.

Rather than coming up with yet another crutch, we should just bite the bullet and get the work done. This software is early and users are still able to get Draft working on windows using the above workarounds for the time being. If we were 1.0+ then I'd say let's do another patch release, but honestly I'd rather do the work once, and do it right.