From 40042204c52704bc4e596b42c9b3ae0e8a6ff8a2 Mon Sep 17 00:00:00 2001 From: alefesta Date: Wed, 30 Jun 2021 16:31:06 +0200 Subject: [PATCH 1/2] [Installation] - Improve Installation for Windows Users - **What this feature does**: Windows user should be able to use the dagger binary getting a similar experience to the one proposed for Linux in the docs. - **What has been changed**: the feature implement a powershell script similar to `install.sh` logic. More specifically I've updated `install.md` and added `install.ps1` I'm not sure if the URL `releases.dagger.io` is currently pointing at the content of GH repo or something else so the documented steps may need a review. Signed-off-by: alefesta --- docs/install.md | 17 ++++++++++ install.ps1 | 82 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 install.ps1 diff --git a/docs/install.md b/docs/install.md index 22d56aaa..7758b401 100644 --- a/docs/install.md +++ b/docs/install.md @@ -35,6 +35,23 @@ You can then install it globally on your system: sudo mv ./bin/dagger /usr/local/bin ``` +## Option 2 (Windows): Run a shell script + +Since Dagger repository is currently private, we have to use a workaround +to be able to run the script and match the latest release. +This workaround will be removed once the repo will become public. +To generate a personal access token on GitHub follow the guidelines at [Create a personal access token](https://docs.github.com/en/github/authenticating-to-github/keeping-your-account-and-data-secure/creating-a-personal-access-token) + +From a terminal, run the following command: + +```shell +$personalToken= +curl https://releases.dagger.io/dagger/install.ps1 -OutFile install.ps1 ; ./install.ps1 -PersonalToken $personalToken; rm install.ps1 +``` + +We try to move the dagger binary under `C:\Windows\System32` but +in case use missing the necessary permission we'll save everything under `/dagger` + ## Option 3: Download a binary release Open your web browser to [the latest release](https://github.com/dagger/dagger/releases/latest). diff --git a/install.ps1 b/install.ps1 new file mode 100644 index 00000000..d9a1fa84 --- /dev/null +++ b/install.ps1 @@ -0,0 +1,82 @@ +param ( + [Parameter(Mandatory)] $PersonalToken +) +Clear-Host +@" + +--------------------------------------------------------------------------------- +Author: Alessandro Festa +Usage: To run using your GH personal developer token simply use the flag as below +./install.ps1 -PersonalToken 1234567891213 +Dagger executable will be save under the folder "dagger" in your home folder. +--------------------------------------------------------------------------------- + +"@ + +# Since we are already authenticated we may directly download latest version. +$name="dagger" +$base="https://dagger-io.s3.amazonaws.com" +function http_download { + Clear-Host + $version=Get_Version + $version= $version -replace '[""]' + $url = $base + "/" + $name + "/releases/" + $version.substring(1) + "/dagger_" + $version + "_windows_amd64.zip" + $fileName="dagger_" + $version + "_windows_amd64" + + + Invoke-WebRequest -Uri $url -OutFile $env:temp/$fileName.zip -ErrorAction Stop + Expand-Archive -Path $env:temp/$fileName.zip -DestinationPath $env:HOMEPATH/dagger -Force -ErrorVariable ProcessError; + If ($ProcessError) + { + Clear-Host +@" +Whoops apparently we had an issue in unzipping the file, please check +you have the right permission to do so and try to unzip manually the file. +Currently we saved Dagger at your temp folder. +"@ +exit + } else { + Clear-Host + +@" + +Thank You for downloading Dagger! + +----------------------------------------------------- +Dagger has been saved at /dagger/ +Please add dagger.exe to your PATH in order to use it +---------------------------------------------------- + +"@ + } + +} + +function Get_Version { + + $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]" + $headers.Add("Authorization", "token $PersonalToken") + $headers.Add("Accept", "application/vnd.github.VERSION.raw") + + $response = Invoke-RestMethod 'https://api.github.com/repos/dagger/dagger/releases/latest' -Method 'GET' -Headers $headers -Body $body -ErrorAction SilentlyContinue -ErrorVariable DownloadError + If ($DownloadError) + { + Clear-Host +@" + +--------------------------------------------------------------------------- +Houston we have a problem! + +Apparently we had an issue in downloading the file, please try again +run the script and if it still fail please open an issue on the Dagger repo. +---------------------------------------------------------------------------- + +"@ +exit + } + + return $response.tag_name| ConvertTo-Json + +} + +http_download \ No newline at end of file From 189fb715ebda66999e32a667de3f5718da81969b Mon Sep 17 00:00:00 2001 From: alefesta Date: Wed, 30 Jun 2021 17:54:12 +0200 Subject: [PATCH 2/2] Updated the Installer and Docs Updated Installer script and Docs accordingly to comments. Now it does not request anymore the personal token to be produced. Signed-off-by: alefesta --- docs/install.md | 8 +------- install.ps1 | 33 ++++++++++++++------------------- 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/docs/install.md b/docs/install.md index 7758b401..c489039a 100644 --- a/docs/install.md +++ b/docs/install.md @@ -37,16 +37,10 @@ sudo mv ./bin/dagger /usr/local/bin ## Option 2 (Windows): Run a shell script -Since Dagger repository is currently private, we have to use a workaround -to be able to run the script and match the latest release. -This workaround will be removed once the repo will become public. -To generate a personal access token on GitHub follow the guidelines at [Create a personal access token](https://docs.github.com/en/github/authenticating-to-github/keeping-your-account-and-data-secure/creating-a-personal-access-token) - From a terminal, run the following command: ```shell -$personalToken= -curl https://releases.dagger.io/dagger/install.ps1 -OutFile install.ps1 ; ./install.ps1 -PersonalToken $personalToken; rm install.ps1 +curl https://releases.dagger.io/dagger/install.ps1 -OutFile install.ps1 ; ./install.ps1; rm install.ps1 ``` We try to move the dagger binary under `C:\Windows\System32` but diff --git a/install.ps1 b/install.ps1 index d9a1fa84..8702ec3e 100644 --- a/install.ps1 +++ b/install.ps1 @@ -1,14 +1,12 @@ -param ( - [Parameter(Mandatory)] $PersonalToken -) +# param ( +# [Parameter(Mandatory)] $PersonalToken +# ) Clear-Host @" --------------------------------------------------------------------------------- Author: Alessandro Festa -Usage: To run using your GH personal developer token simply use the flag as below -./install.ps1 -PersonalToken 1234567891213 -Dagger executable will be save under the folder "dagger" in your home folder. +Dagger Installation Utility for Windows users --------------------------------------------------------------------------------- "@ @@ -17,11 +15,14 @@ Dagger executable will be save under the folder "dagger" in your home folder. $name="dagger" $base="https://dagger-io.s3.amazonaws.com" function http_download { - Clear-Host $version=Get_Version - $version= $version -replace '[""]' - $url = $base + "/" + $name + "/releases/" + $version.substring(1) + "/dagger_" + $version + "_windows_amd64.zip" - $fileName="dagger_" + $version + "_windows_amd64" + $version=$version -replace '[""]' + $version=$version -replace '\n' + $fileName="dagger_v" + $version + "_windows_amd64" + Clear-Host + $url = $base + "/" + $name + "/releases/" + $version + "/" + $fileName + ".zip" + write-host $url + Pause Invoke-WebRequest -Uri $url -OutFile $env:temp/$fileName.zip -ErrorAction Stop @@ -52,13 +53,8 @@ Please add dagger.exe to your PATH in order to use it } -function Get_Version { - - $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]" - $headers.Add("Authorization", "token $PersonalToken") - $headers.Add("Accept", "application/vnd.github.VERSION.raw") - - $response = Invoke-RestMethod 'https://api.github.com/repos/dagger/dagger/releases/latest' -Method 'GET' -Headers $headers -Body $body -ErrorAction SilentlyContinue -ErrorVariable DownloadError +function Get_Version { + $response = Invoke-RestMethod 'http://releases.dagger.io/dagger/latest_version' -Method 'GET' -Body $body -ErrorAction SilentlyContinue -ErrorVariable DownloadError If ($DownloadError) { Clear-Host @@ -74,8 +70,7 @@ run the script and if it still fail please open an issue on the Dagger repo. "@ exit } - - return $response.tag_name| ConvertTo-Json + return $response }