Skip to content

Commit

Permalink
feat: add Windows support (experimental)
Browse files Browse the repository at this point in the history
I tried testing this best I could, but it is possible there are
more issues lurking. If anyone can give this a proper spin
(on an actual Windows machine and not in a VM) that would be
most appreciated!
  • Loading branch information
edvald committed Jul 24, 2018
1 parent 5949c6d commit 9e9c218
Show file tree
Hide file tree
Showing 15 changed files with 213 additions and 96 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ but still), overall stability will improve and platform support is still limited
All that said, Garden can already be highly useful if the following applies to you:

* **You're deploying to (or transitioning to) Kubernetes.**
* **You develop on Mac or Linux.**
* **You work mostly with containers** _**today**_ _\(but perhaps plan on adopting serverless platforms in the future\)._
* **You keep all your services in a single repository** _(multi-repo support coming soon!)._
* **You really don't want to spend your precious hours building your own developer tooling!**
Expand Down
35 changes: 17 additions & 18 deletions docs/guides/minikube.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
## Using Garden with Minikube
# Using Garden with Minikube

Garden can be used with [Minikube](https://github.com/kubernetes/minikube) on supported platforms.

### Installation
_NOTE: We highly recommend using Docker for Mac and Docker for Windows, for macOS and Windows respectively._

For Minikube installation instructions, please see the
## Installation

For Minikube installation instructions, please see the
[official guide](https://github.com/kubernetes/minikube#installation).

You'll likely also need to install a driver to run the Minikube VM, please follow the
You'll likely also need to install a driver to run the Minikube VM, please follow the
[instructions here](https://github.com/kubernetes/minikube/blob/master/docs/drivers.md)
and note the name of the driver you use. The driver you choose will likely vary depending on your
OS/platform. We recommend [hyperkit](https://github.com/kubernetes/minikube/blob/master/docs/drivers.md#hyperkit-driver)
OS/platform. We recommend [hyperkit](https://github.com/kubernetes/minikube/blob/master/docs/drivers.md#hyperkit-driver)
for macOS and [kvm2](https://github.com/kubernetes/minikube/blob/master/docs/drivers.md#kvm2-driver) on most Linux
platforms.

Once Minikube and the appropriate driver for your OS is installed, you can start it by running:

minikube start --vm-driver=<your vm driver> # e.g. hyperkit on macOS

You'll also need to have Docker (for macOS, we recommend [Docker for Mac](https://docs.docker.com/engine/installation/))
and [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/) installed.

_NOTE: Garden is not yet officially supported on Windows, but we have every intention to support it.
Please file any issues and we will try and respond promptly._

### Usage
## Usage

The `local-kubernetes` plugin attempts to automatically detect if it is installed and set the appropriate context
The `local-kubernetes` plugin attempts to automatically detect if it is installed and set the appropriate context
for connecting to the local Kubernetes instance. In most cases you should not have to update your `garden.yml`
since it uses the `local-kubernetes` plugin by default, but you can configure it explicitly in your project
`garden.yml` like so:
Expand All @@ -37,20 +36,20 @@ project:
- name: local
providers:
- name: local-kubernetes
context: minikube
```
context: minikube
```
_Note: If you happen to have installed both Minikube and the Docker for Mac version with Kubernetes enabled,
`garden` will choose whichever one is configured as the current context in your `kubectl` configuration, and if neither
is set as the current context, Docker for Mac is preferred by default._

### Hostname
## Hostname

Garden needs the Kubernetes instance to have a hostname. By default Garden will use `<minikube-ip>.nip.io`. If you'd
Garden needs the Kubernetes instance to have a hostname. By default Garden will use `<minikube-ip>.nip.io`. If you'd
like to use a custom hostname, you can specify it via the `ingressHostname` in the `local-kubernetes` provider config
(see above).

### Anything else?
## Anything else?

Once the above is set up, the `local-kubernetes` plugin will automatically configure everything else Garden needs to
Once the above is set up, the `local-kubernetes` plugin will automatically configure everything else Garden needs to
work. The built-in nginx ingress controller will be automatically enabled and used to route requests to services.
73 changes: 63 additions & 10 deletions docs/introduction/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

This guide will walk you through setting up the Garden framework.


## Installation

### macOS
Expand All @@ -15,16 +14,17 @@ steps below if you prefer.
If you haven't already set up homebrew, please follow [their instructions](https://brew.sh/) to set it up.

#### Step 2: Docker and local Kubernetes
To install Docker, Kubernetes and kubectl, we strongly recommend Docker for Mac (edge version).

_Note: you need to install the **edge version** of Docker for Mac in
To install Docker, Kubernetes and kubectl, we strongly recommend Docker for Mac (edge version).

_Note: you need to install the **edge version** of Docker for Mac in
order to enable Kubernetes support._

Once installed, open the Docker for Mac preferences, go to the Kubernetes section,
tick `Enable Kubernetes` and save. Please refer to their
Once installed, open the Docker for Mac preferences, go to the Kubernetes section,
tick `Enable Kubernetes` and save. Please refer to their
[installation guide](https://docs.docker.com/engine/installation/) for details.

Alternatively, you can use Minikube. We generally find it less stable and more hassle to
Alternatively, you can use Minikube. We generally find it less stable and more hassle to
configure and use, but we do fully support it on Mac if you have it running. Please look at our
[Minikube guide](../guides/minikube.md) for details.

Expand All @@ -37,9 +37,61 @@ 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`
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).

### Windows

You can run garden on Windows 10 Pro or Enterprise editions. Follow these instructions to get started.

#### Step 1: Chocolatey

If you haven't already, install the [Chocolatey](https://chocolatey.org) package manager.

#### Step 2: Enable Hyper-V

This is required for _Docker for Windows_ to run. Open PowerShell as an administrator and run:

```powershell
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All
```

This will require a restart.

#### Step 2: Docker for Windows

Install the Edge version of [Docker for Windows](https://www.docker.com/docker-windows).

Once installed, open the Docker for Windows settings, go to the Kubernetes section,
tick `Enable Kubernetes` and save. Please refer to their
[installation guide](https://docs.docker.com/engine/installation/) for details.

#### Step 3: Install dependencies

Open PowerShell as an admistrator and run:

```powershell
# install choco packages (note: python is needed to build some dependencies)
choco install -y git nodejs rsync kubernetes-helm
# install Stern (currently not available as a choco package)
[Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls"
Invoke-WebRequest -Uri "https://github.com/wercker/stern/releases/download/1.7.0/stern_windows_amd64.exe" -OutFile "$Env:SystemRoot\system32\stern.exe"
# install build tools so that node-gyp works
npm install --global --production windows-build-tools
npm config set msvs_version 2015 --global
```

#### Step 4: Install `garden-cli`

Once you have the dependencies set up, open a new PowerShell and install the Garden CLI via `npm`:

```powershell
npm install -g garden-cli
```

To later upgrade to the newest version, run `npm install -g -U garden-cli`.

### Linux / manual installation

Expand All @@ -53,10 +105,12 @@ You need the following dependencies on your local machine to use Garden:
* Local installation of Kubernetes and kubectl

#### Step 1: Docker

To install Docker, please follow the instructions in the [official documentation](https://docs.docker.com/install/).

#### Step 2: Local Kubernetes
For local Kubernetes, you can use [Minikube](https://github.com/kubernetes/minikube). Please see our

For local Kubernetes, you can use [Minikube](https://github.com/kubernetes/minikube). Please see our
[Minikube guide](../guides/minikube.md) for instructions.

#### Step 3: Install other dependencies
Expand All @@ -74,10 +128,9 @@ npm install -g garden-cli

To later upgrade to the newest version, run `npm install -g -U garden-cli`.


## Using the CLI

With the CLI installed, we can now try out a few commands using the [hello-world](https://github.com/garden-io/garden-examples/tree/master/hello-world) project from our Github [examples repository](https://github.com/garden-io/garden-examples). The example consists of a container service that runs an [Express](http://expressjs.com/) app, a serverless function, and an npm library package.
With the CLI installed, we can now try out a few commands using the [hello-world](https://github.com/garden-io/garden-examples/tree/master/simple-project) project from our Github [examples repository](https://github.com/garden-io/garden-examples). The example consists of a a couple of simple services.

_Note: check if Kubernetes is running with `kubectl version`. You should see both a `Client Version` and a `Server Version` in the response. If not, please start it up before proceeding._

Expand Down
1 change: 0 additions & 1 deletion examples/hello-world/services/hello-function/libraries

This file was deleted.

46 changes: 38 additions & 8 deletions garden-cli/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions garden-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"@kubernetes/client-node": "^0.3.0",
"ansi-escapes": "^3.1.0",
"async-exit-hook": "^2.0.1",
"axios": "^0.18.0",
"bluebird": "^3.5.1",
"chalk": "^2.4.1",
"child-process-promise": "^2.2.1",
Expand Down Expand Up @@ -54,7 +53,7 @@
"moment": "^2.22.2",
"node-emoji": "^1.8.1",
"node-pty": "^0.7.4",
"rsync": "^0.6.1",
"shx": "^0.3.2",
"snyk": "^1.82.2",
"split": "^1.0.1",
"strip-ansi": "^4.0.0",
Expand Down Expand Up @@ -95,6 +94,7 @@
"@types/prettyjson": "0.0.28",
"@types/uniqid": "^4.1.2",
"@types/wrap-ansi": "^3.0.0",
"axios": "^0.18.0",
"chai": "^4.1.2",
"gulp": "^4.0.0",
"gulp-cached": "^1.1.1",
Expand Down Expand Up @@ -123,7 +123,7 @@
"scripts": {
"build": "npm run clean && gulp build",
"check-package-lock": "git diff-index --quiet HEAD -- package-lock.json || (echo 'package-lock.json is dirty!' && exit 1)",
"clean": "rm -rf build && git clean -X -f",
"clean": "shx rm -rf build && git clean -X -f",
"dev": "npm run clean && gulp build && npm link && gulp watch",
"dist": "npm run build",
"generate-docs": "gulp generate-docs",
Expand Down
18 changes: 11 additions & 7 deletions garden-cli/src/build-dir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,23 @@ import {
parse,
resolve,
sep,
win32,
posix,
} from "path"
import {
emptyDir,
ensureDir,
} from "fs-extra"
import * as Rsync from "rsync"
import { GARDEN_DIR_NAME } from "./constants"
import { ConfigurationError } from "./exceptions"
import { execRsyncCmd } from "./util/util"
import {
BuildCopySpec,
Module,
} from "./types/module"
import { zip } from "lodash"
import * as execa from "execa"
import { platform } from "os"
import { toCygwinPath } from "./util/util"

// Lazily construct a directory of modules inside which all build steps are performed.

Expand Down Expand Up @@ -96,11 +99,12 @@ export class BuildDir {
const destinationDir = parse(destinationPath).dir
await ensureDir(destinationDir)

const syncCmd = new Rsync()
.flags(["r", "p", "t", "g", "o"])
.source(sourcePath)
.destination(destinationPath)
if (platform() === "win32") {
// this is so that the cygwin-based rsync client can deal with the paths
sourcePath = toCygwinPath(sourcePath)
destinationPath = toCygwinPath(destinationPath)
}

await execRsyncCmd(syncCmd)
await execa("rsync", ["-rptgo", sourcePath, destinationPath])
}
}
4 changes: 2 additions & 2 deletions garden-cli/src/plugins/kubernetes/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
} from "lodash"
import { GardenBaseError, ConfigurationError } from "../../exceptions"
import { KubernetesObject } from "./helm"
import { homedir } from "os"

let kubeConfigStr: string
let kubeConfig: any
Expand All @@ -33,8 +34,7 @@ const configs: { [context: string]: KubeConfig } = {}

function getConfig(context: string): KubeConfig {
if (!kubeConfigStr) {
kubeConfigStr = readFileSync(process.env.KUBECONFIG || join(process.env.HOME || "/home", ".kube", "config"))
.toString()
kubeConfigStr = readFileSync(join(homedir(), ".kube", "config")).toString()
kubeConfig = safeLoad(kubeConfigStr)
}

Expand Down
Loading

0 comments on commit 9e9c218

Please sign in to comment.