From b3437f6eeb42ef2f0797bd0b04aa42ec97ce6060 Mon Sep 17 00:00:00 2001 From: Jon Edvald Date: Sun, 28 Oct 2018 20:57:14 +0100 Subject: [PATCH 1/2] chore(release): fix minor issues in pkg build script --- garden-service/scripts/build-pkg.sh | 37 ++++++++++++++--------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/garden-service/scripts/build-pkg.sh b/garden-service/scripts/build-pkg.sh index d8078f0cdf..52ed5f2748 100755 --- a/garden-service/scripts/build-pkg.sh +++ b/garden-service/scripts/build-pkg.sh @@ -1,8 +1,8 @@ #!/bin/bash -e -garden_cli_root=$(cd `dirname $0` && cd .. && pwd) +garden_service_root=$(cd `dirname $0` && cd .. && pwd) -cd ${garden_cli_root} +cd ${garden_service_root} commit_hash=$(git rev-parse --short HEAD) version=$(cat package.json | jq -r .version) @@ -11,12 +11,11 @@ echo "Packaging version ${version}-${commit_hash}" echo "-> Copying files to tmp build dir..." mkdir -p dist +rm -rf tmp/dist mkdir -p tmp/dist -cp -r package.json build static node_modules tmp/dist - -echo "-> Cleaning up .garden directories..." -find tmp/dist -depth -type d -name ".garden" -exec rm -r "{}" \; +cp -r package.json build node_modules tmp/dist +rsync -r --exclude=.garden --exclude=.git static tmp/dist echo "-> Building executables..." cd dist @@ -25,18 +24,18 @@ pkg --target node10-linux-x64,node10-win-x64 ../tmp/dist echo "-> Preparing packages..." -echo " -> linux-x64" -rm -rf linux-x64 -mkdir linux-x64 -mv garden-cli-linux linux-x64/garden -cp -r ../tmp/dist/static linux-x64 -tar -czf garden-${version}-${commit_hash}.tar.gz linux-x64 - -echo " -> win-x64" -rm -rf win-x64 -mkdir win-x64 -mv garden-cli-win.exe win-x64/garden.exe -cp -r ../tmp/dist/static win-x64 -zip -q -r garden-${version}-${commit_hash}.zip win-x64 +echo " -> linux-amd64" +rm -rf linux-amd64 +mkdir linux-amd64 +mv garden-cli-linux linux-amd64/garden +cp -r ../tmp/dist/static linux-amd64 +tar -czf garden-${version}-${commit_hash}-linux-amd64.tar.gz linux-amd64 + +echo " -> win-amd64" +rm -rf win-amd64 +mkdir win-amd64 +mv garden-cli-win.exe win-amd64/garden.exe +cp -r ../tmp/dist/static win-amd64 +zip -q -r garden-${version}-${commit_hash}-win-amd64.zip win-amd64 echo "Done!" From dd92cc69822fe64ab3d36fe9d7fca54763fcd5a3 Mon Sep 17 00:00:00 2001 From: Jon Edvald Date: Sun, 28 Oct 2018 20:57:22 +0100 Subject: [PATCH 2/2] chore(release): update docs and Windows installation script --- docs/introduction/getting-started.md | 39 ++-- garden-service/package.json | 4 +- garden-service/support/install.ps1 | 174 ----------------- lerna.json | 2 +- .../support => support}/homebrew-formula.rb | 0 support/install.ps1 | 175 ++++++++++++++++++ 6 files changed, 194 insertions(+), 200 deletions(-) delete mode 100644 garden-service/support/install.ps1 rename {garden-service/support => support}/homebrew-formula.rb (100%) create mode 100644 support/install.ps1 diff --git a/docs/introduction/getting-started.md b/docs/introduction/getting-started.md index ae011e293a..5e09463334 100644 --- a/docs/introduction/getting-started.md +++ b/docs/introduction/getting-started.md @@ -21,9 +21,9 @@ If you haven't already set up homebrew, please follow [their instructions](https #### Step 2: Docker and local Kubernetes -To install Docker, Kubernetes and kubectl, we strongly recommend Docker for Mac (edge version). +To install Docker, Kubernetes and kubectl, we strongly recommend Docker for Mac. -_Note: you need to install the **edge version** of Docker for Mac in +_Note: If you have an older version installed, you may need to update it in order to enable Kubernetes support._ Once installed, open the Docker for Mac preferences, go to the Kubernetes section, @@ -43,29 +43,15 @@ brew tap garden-io/garden brew install garden-cli ``` -To later upgrade to the newest version, simply run `brew update` and then `brew upgrade garden-cli` -(or `brew upgrade` to upgrade all your Homebrew packages). +To later upgrade to the newest version, simply run `brew update` and then `brew upgrade garden-cli`. ### Windows You can run Garden on Windows 10 Pro or Enterprise editions (The Home edition unfortunately does not work because it -does not include support for virtualization). To install the Garden CLI please use our _automated installation script_, -which will check for dependencies, install missing dependencies if needed, and finally install the `garden-cli` -npm package. +does not include support for virtualization). -The things the script will check for are the following: - -* The [Chocolatey](https://chocolatey.org) package manager. -* Whether you have Hyper-V enabled. This is required for _Docker for Windows_. If you do not already have it enabled, - the script will enable it but you will need to restart your computer before starting Docker for Windows. -* Docker - We strongly recommend using the _Edge version_ of - [Docker for Windows](https://docs.docker.com/docker-for-windows/edge-release-notes/), which has built-in support for Kubernetes. It is also - _possible_ to configure Docker and Kubernetes differently, using minikube for example, but in most cases - Docker for Windows is much easier to install and configure, and is well supported. The script will check if Docker is - installed, and whether Kubernetes has been enabled as the default orchestrator. -* Node.js - The script will install it via Chocolatey if it is missing, but note that _if you already have Node.js - installed, please make sure it is version 8.x or newer._ -* Git and rsync. The script will install those if they are missing. +To install the Garden CLI please use our automated installation script, +which will check for dependencies, install missing dependencies if needed, and finally install the Garden CLI. To run the script, open PowerShell as an Administrator and run: @@ -73,13 +59,20 @@ To run the script, open PowerShell as an Administrator and run: Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/garden-io/garden/master/garden-service/support/install.ps1')) ``` -To later upgrade to the newest version, run `npm install -g -U garden-cli`. +The things the script will check for are the following: + +* The [Chocolatey](https://chocolatey.org) package manager. The script installs it automatically if necessary. +* _git_, _rsync_ and _Docker for Windows_. The script will install or upgrade those via Chocolatey. +* Whether you have Hyper-V enabled. This is required for _Docker for Windows_. If you do not already have it enabled, + the script will enable it but you will need to restart your computer before starting Docker for Windows. +* Whether you have Kubernetes enabled in your _Docker for Windows_ installation. + +To later upgrade to the newest version, simply re-run the above script. ### Linux (manual installation) You need the following dependencies on your local machine to use Garden: -* Node.js >= 8.x * [Docker](https://docs.docker.com/) * Git * rsync @@ -96,7 +89,7 @@ For local Kubernetes, you can use [Minikube](https://github.com/kubernetes/minik #### Step 3: Install other dependencies -Use your preferred method or package manager to install `node` (version 8.x or higher), `git` and `rsync`. +Use your preferred method or package manager to install `git` and `rsync`. #### Step 4: Install `garden-cli` diff --git a/garden-service/package.json b/garden-service/package.json index f58dbe4e39..4fd154f618 100644 --- a/garden-service/package.json +++ b/garden-service/package.json @@ -1,6 +1,6 @@ { "name": "garden-cli", - "version": "0.7.0", + "version": "0.8.0", "description": "A full-featured development framework for containers and serverless", "repository": { "type": "git", @@ -161,4 +161,4 @@ }, "snyk": true, "gitHead": "b0647221a4d2ff06952bae58000b104215aed922" -} +} \ No newline at end of file diff --git a/garden-service/support/install.ps1 b/garden-service/support/install.ps1 deleted file mode 100644 index d50476801b..0000000000 --- a/garden-service/support/install.ps1 +++ /dev/null @@ -1,174 +0,0 @@ -#Requires -RunAsAdministrator -# This is the Garden installer for Windows. Here's a brief description of what -# it does: -# -# 1. Checks whether Hyper-V is enabled. -# 2. Checks whether Docker is installed. -# 3. Checks whether Kubernetes is the default orchestrator for Docker. -# 4. Check if Chocolatey is installed, installs it if missing. -# 5. Installs the listed dependencies using Chocolatey if they're not already -# present (currently git, nodejs, rsync). -# 6. Installs or updates the windows-build-tools NPM package. -# 7. Installs or updates the garden-cli NPM package. -# -# To execute it run the following command in PowerShell: -# Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/garden-io/garden/master/garden-cli/support/install.ps1')) -# -# For more information visit https://docs.garden.io/ - -Function CheckHyperV { - # if ((New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) -eq $false) { - # ContinueYN("To check whether Hyper-V is enabled (and enable it if necessary), please run as Administrator. If you choose to continue the Hyper-V check will be skipped.") - # return - # } - $hyperv = Get-WindowsOptionalFeature -FeatureName Microsoft-Hyper-V-All -Online - if($hyperv.State -ne "Enabled") { - Write-Host "- Hyper-V is being enabled. You will need to restart your computer for the changes to take effect (This is required for Docker for Windows to run)." - # For testing, disable with: Disable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-All - Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All - } else { - Write-Host "- Hyper-V is enabled." - } - return $true -} - -Function CheckDocker { - if ((CheckIfExists("docker")) -eq $false) { - Write-Host "- Docker is not installed. Please download and install the Edge release at: https://docs.docker.com/docker-for-windows/edge-release-notes/" - return $false - } else { - Write-Host "- Docker is installed." - } - return $true -} - -Function CheckKubernetes { - $dockerConfigPath = (Join-Path $HOME .docker\config.json) - $dockerConfigParsed = (Get-Content $dockerConfigPath | Out-String | ConvertFrom-Json) - if ($dockerConfigParsed.stackOrchestrator -ne "kubernetes") { - Write-Host "- Kubernetes is not enabled as the default orchestrator for Docker. Please enable it in the Kubernetes section of Docker for Windows's settings." - return $false - } else { - Write-Host "- Kubernetes is enabled." - } - return $true -} - -Function CheckChocolatey { - if ((CheckIfExists("chocolatey")) -eq $false) { - Write-Host "- Chocolatey not found. Installing it..." - iex ((new-object net.webclient).DownloadString('http://chocolatey.org/install.ps1')) - } else { - Write-Host "- Chocolatey is installed." - } - return $true -} - -Function CheckChocolateyDeps { - param($array) - $missing = @("-y") - $install = $false - for ($i=0; $i -lt $array.length; $i++) { - if ((CheckIfExists($array[$i][0])) -eq $false) { - Write-Host - Package $array[$i][1] not found. Installing... - $missing = $missing + $array[$i][1] - $install = $true - } else { - Write-Host - Package $array[$i][0] already present... - } - } - if ($install) { - & cinst $missing - } -} - -Function ContinueYN ($message) { - Write-Host "$message" -ForegroundColor Yellow - Write-Host -NoNewLine "Continue? (Y/N) " - $response = Read-Host - if ( $response -ne "Y" ) { Exit } -} - -Function Pause ($message) { - Write-Host "$message" -ForegroundColor Yellow - $x = $host.ui.RawUI.ReadKey("NoEcho,IncludeKeyDown") -} - -function CheckIfExists { - Param ($command) - $oldPreference = $ErrorActionPreference - $ErrorActionPreference = 'stop' - try { - if (Get-Command $command) { - return $true - } - } Catch { - return $false - } - Finally { - $ErrorActionPreference=$oldPreference - } -} - -# Elevate to Admin. -if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { - Write-Host("This script needs to be run as an Administrator. Please start a PowerShell windows as an Administrator and run the script again.") - return -} - -# Start here. -Write-Host(" -Hi! This script will install the Garden CLI, after checking and installing missing dependencies. -Please refer to our Getting Started guide at https://docs.garden.io/introduction/getting-started for details. - -Please note that you may need to answer prompts during the installation. - -*** Checking dependencies *** -") - -if ((CheckHyperV) -eq $false) { return } -if ((CheckDocker) -eq $false) { return } -if ((CheckKubernetes) -eq $false) { return } -if ((CheckChocolatey) -eq $false) { return } - -# chocDeps lists the chocolatey dependencies to be installed. It consists of -# pairs, where the first element is the package's CLI command (to check whether -# it's already installed), and the second is its respective Chocolatey package -# name. -$chocDeps = (("git","git"), - ("rsync","rsync"), - ("node","nodejs")) -CheckChocolateyDeps($chocDeps) -[Console]::ResetColor() - -# Node Configuration. -Write-Host("- Installing/updating Node.js build dependencies") -$nodePath = Join-Path $env:programfiles 'nodejs' -$is64bit = (Get-WmiObject Win32_Processor).AddressWidth -eq 64 -if ($is64bit) {$nodePath = Join-Path ${env:ProgramFiles(x86)} 'nodejs'} -$env:Path = "$($env:Path);$nodePath" - -# installing >=4.0 ensures we're using Node.js 8.x or newer -npm install --global --update --production windows-build-tools@">=4.0" -npm config set msvs_version 2015 --global - -# Install the garden-cli package -Write-Host(" -*** Installing the Garden CLI *** -") -npm install --global --update garden-cli - -Write-Host(" -Garden CLI successfully installed! -You can now run the garden command in your shell. -Please head over to https://docs.garden.io for more information on how to get started. -") - -# Notes for testing: -# -# npm uninstall -g garden-cli windows-build-tools -# choco uninstall git nodejs rsync -# rm -r -fo C:\ProgramData\chocolatey -# -# choco pack -# choco install garden-cli -dv -s . \ No newline at end of file diff --git a/lerna.json b/lerna.json index cb68a42e0f..a15f552ee3 100644 --- a/lerna.json +++ b/lerna.json @@ -7,5 +7,5 @@ "packages": [ "garden-service/" ], - "version": "0.7.0" + "version": "0.8.0" } \ No newline at end of file diff --git a/garden-service/support/homebrew-formula.rb b/support/homebrew-formula.rb similarity index 100% rename from garden-service/support/homebrew-formula.rb rename to support/homebrew-formula.rb diff --git a/support/install.ps1 b/support/install.ps1 new file mode 100644 index 0000000000..d0fa80f6a5 --- /dev/null +++ b/support/install.ps1 @@ -0,0 +1,175 @@ +#Requires -RunAsAdministrator +# This is the Garden installer for Windows. Here's a brief description of what +# it does: +# +# 1. Check if Chocolatey is installed, installs it if missing. +# 2. Installs and/or upgrades dependencies using Chocolatey. +# 3. Checks whether Hyper-V is enabled. +# 4. Checks whether Kubernetes is the default orchestrator for Docker. +# 5. Installs or updates the garden binary. +# +# To execute it run the following command in PowerShell: +# Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/garden-io/garden/master/garden-cli/support/install.ps1')) +# +# For more information visit https://docs.garden.io/ + +Function CheckHyperV { + # if ((New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) -eq $false) { + # ContinueYN("To check whether Hyper-V is enabled (and enable it if necessary), please run as Administrator. If you choose to continue the Hyper-V check will be skipped.") + # return + # } + $hyperv = Get-WindowsOptionalFeature -FeatureName Microsoft-Hyper-V-All -Online + if($hyperv.State -ne "Enabled") { + Write-Host "- WARNING: Hyper-V is being enabled. You will need to restart your computer for the changes to take effect (This is required for Docker for Windows to run)." + # For testing, disable with: Disable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-All + Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All + } else { + Write-Host "- Hyper-V is enabled." + } +} + +Function CheckKubernetes { + $dockerConfigPath = (Join-Path $HOME .docker\config.json) + $dockerConfigParsed = (Get-Content $dockerConfigPath | Out-String | ConvertFrom-Json) + if ($dockerConfigParsed.stackOrchestrator -ne "kubernetes") { + Write-Host "- WARNING: Kubernetes is not enabled as the default orchestrator for Docker. Please enable it in the Kubernetes section of Docker for Windows's settings." + } else { + Write-Host "- Kubernetes is enabled." + } +} + +Function CheckChocolatey { + if ((CheckIfExists("chocolatey")) -eq $false) { + Write-Host "- Chocolatey not found. Installing it..." + iex ((new-object net.webclient).DownloadString('http://chocolatey.org/install.ps1')) + } else { + Write-Host "- Chocolatey is installed." + } +} + +Function ContinueYN ($message) { + Write-Host "$message" -ForegroundColor Yellow + Write-Host -NoNewLine "Continue? (Y/N) " + $response = Read-Host + if ( $response -ne "Y" ) { Exit } +} + +Function Pause ($message) { + Write-Host "$message" -ForegroundColor Yellow + $x = $host.ui.RawUI.ReadKey("NoEcho,IncludeKeyDown") +} + +Function CheckIfExists { + Param ($command) + $oldPreference = $ErrorActionPreference + $ErrorActionPreference = 'stop' + try { + if (Get-Command $command) { + return $true + } + } Catch { + return $false + } + Finally { + $ErrorActionPreference=$oldPreference + } +} + +# Elevate to Admin. +if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { + Write-Host("This script needs to be run as an Administrator. Please start a PowerShell windows as an Administrator and run the script again.") + return +} + +$ErrorActionPreference = "Stop" + +# Start here. +Write-Host(" +Hi! This script will install the Garden CLI, after checking and installing missing dependencies. +Please refer to our Getting Started guide at https://docs.garden.io/introduction/getting-started for details. + +Please note that you may need to answer prompts during the installation. + +*** Checking dependencies *** +") + +# Install Chocolatey if needed +CheckChocolatey + +# Install choco dependencies +Write-Host "- Installing Chocolatey dependencies..." +choco upgrade -y git rsync docker-for-windows + +[Console]::ResetColor() + +# Check system configuration +CheckHyperV +CheckKubernetes + +# Install the garden binary +$homedir = Resolve-Path "~" +$gardenHomePath = "$homedir\.garden" +$gardenBinPath = "$gardenHomePath\bin" +$gardenTmpPath = "$gardenHomePath\tmp" + +Write-Host(" +*** Installing the Garden CLI to $gardenBinPath and adding to PATH *** +") + +# Make sure paths exists +md -Force $gardenHomePath | Out-Null +md -Force $gardenBinPath | Out-Null +md -Force $gardenTmpPath | Out-Null + +# Download and extract the archive to $gardenBinPath +# TODO: change this to point to the latest stable instead of the hard-coded version +$url = "https://github.com/garden-io/garden/releases/download/v0.8.0-rc0/garden-0.8.0-b86c463-win-amd64.zip" +$zipPath = "$gardenTmpPath\garden-0.8.0-b86c463-win-amd64.zip" + +Write-Host "-> Downloading $url..." +if (-not ([Net.ServicePointManager]::SecurityProtocol).ToString().Contains([Net.SecurityProtocolType]::Tls12)) { + [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol.toString() + ', ' + [Net.SecurityProtocolType]::Tls12 +} +(New-Object System.Net.WebClient).DownloadFile($url, $zipPath) + +Write-Host "-> Extracting archive..." +Expand-Archive $zipPath -DestinationPath $gardenTmpPath -Force +Copy-Item -Force -Recurse -Path "$gardenTmpPath/win-amd64/*" -Destination $gardenBinPath + +# Make sure $gardenBinPath is in the user's PATH +if (!($env:path.ToLower() -like "*$gardenBinPath*".ToLower())) { + Write-Host "-> Adding $gardenBinPath to your PATH (you may need to restart your console sessions for it to take effect)" + $oldPath = (Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH).path + $newPath = "$oldPath;$gardenBinPath" + Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH -Value $newPath + $env:path = "$env:path;$gardenBinPath" + + # notify all windows of environment block change + $HWND_BROADCAST = [IntPtr] 0xffff; + $WM_SETTINGCHANGE = 0x1a; + $result = [UIntPtr]::Zero + + if (-not ("Win32.NativeMethods" -as [Type])) + { + # import sendmessagetimeout from win32 + Add-Type -Namespace Win32 -Name NativeMethods -MemberDefinition @" + [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] + public static extern IntPtr SendMessageTimeout( + IntPtr hWnd, uint Msg, UIntPtr wParam, string lParam, + uint fuFlags, uint uTimeout, out UIntPtr lpdwResult); +"@ + } + [Win32.Nativemethods]::SendMessageTimeout($HWND_BROADCAST, $WM_SETTINGCHANGE, [UIntPtr]::Zero, "Environment", 2, 5000, [ref] $result); + +} else { + Write-Host "-> $gardenBinPath is already in your PATH" +} + +Write-Host(" +Garden CLI successfully installed! +You can now run the garden command in your shell (you may need to restart your sessions for changes to PATH to take effect). +Please head over to https://docs.garden.io for more information on how to get started. + +Note: Please see the logs above for any warnings. If Docker for Windows was just installed and/or + Hyper-V was just enabled, you may need to restart your computer before using Docker and Garden. +")