Skip to content

Commit

Permalink
Merge pull request #291 from garden-io/hot-reload
Browse files Browse the repository at this point in the history
Hot-reload functionality for local k8s
  • Loading branch information
thsig authored Oct 16, 2018
2 parents b0b5599 + c779618 commit 6c71a59
Show file tree
Hide file tree
Showing 74 changed files with 7,597 additions and 644 deletions.
23 changes: 16 additions & 7 deletions docs/reference/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,12 @@ Deploy service(s) to your environment.

Examples:

garden deploy # deploy all modules in the project
garden deploy my-service # only deploy my-service
garden deploy --force # force re-deploy of modules, even if they're already deployed
garden deploy --watch # watch for changes to code
garden deploy --env stage # deploy your services to an environment called stage
garden deploy # deploy all modules in the project
garden deploy my-service # only deploy my-service
garden deploy --force # force re-deploy of modules, even if they're already deployed
garden deploy --watch # watch for changes to code
garden deploy --hot-reload=my-service # deploys all services, with hot reloading enabled for my-service
garden deploy --env stage # deploy your services to an environment called stage


##### Usage
Expand All @@ -225,7 +226,7 @@ Deploy service(s) to your environment.

| Argument | Required | Description |
| -------- | -------- | ----------- |
| `service` | No | The name of the service(s) to deploy (skip to deploy all services). Use comma as separator to specify multiple services.
| `service` | No | The name(s) of the service(s) to deploy (skip to deploy all services). Use comma as separator to specify multiple services.

##### Options

Expand All @@ -234,6 +235,7 @@ Deploy service(s) to your environment.
| `--force` | | boolean | Force redeploy of service(s).
| `--force-build` | | boolean | Force rebuild of module(s).
| `--watch` | `-w` | boolean | Watch for changes in module(s) and auto-deploy.
| `--hot-reload` | | array:string | The name(s) of the service(s) to deploy with hot reloading enabled. Use comma as separator to specify multiple services. When this option is used, the command is run in watch mode (i.e. implicitly assumes the --watch/-w flag).

### garden dev

Expand All @@ -247,11 +249,18 @@ Starts the garden development console.
Examples:

garden dev
garden dev --hot-reload=foo-service,bar-service # enable hot reloading for foo-service and bar-service


##### Usage

garden dev
garden dev [options]

##### Options

| Argument | Alias | Type | Description |
| -------- | ----- | ---- | ----------- |
| `--hot-reload` | | array:string | The name(s) of the service(s) to deploy with hot reloading enabled. Use comma as separator to specify multiple services.

### garden exec

Expand Down
40 changes: 37 additions & 3 deletions docs/reference/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ project:
{}

# Valid RFC1035/RFC1123 (DNS) label (may contain lowercase letters, numbers and dashes, must
# start with a letter, and cannot end with a dash) and additionally cannot contain
# start with a letter,and cannot end with a dash) and additionally cannot contain
# consecutive dashes or be longer than 63 characters.
#
# Required.
Expand Down Expand Up @@ -452,7 +452,7 @@ module:
#
# Optional.
- # Valid RFC1035/RFC1123 (DNS) label (may contain lowercase letters, numbers and dashes, must
# start with a letter, and cannot end with a dash) and additionally cannot contain
# start with a letter,and cannot end with a dash) and additionally cannot contain
# consecutive dashes or be longer than 63 characters.
#
# Required.
Expand All @@ -463,7 +463,7 @@ module:
# Optional.
dependencies:
# Valid RFC1035/RFC1123 (DNS) label (may contain lowercase letters, numbers and dashes,
# must start with a letter, and cannot end with a dash) and additionally cannot contain
# must start with a letter,and cannot end with a dash) and additionally cannot contain
# consecutive dashes or be longer than 63 characters.
#
# Optional.
Expand Down Expand Up @@ -553,6 +553,14 @@ module:
# Optional.
tcpPort:

# If this module uses the `hotReload` field, the container will be run with these arguments
# instead of those in `command` while a Garden command with the -w (watch) flag, or `garden
# dev`, is running.
#
# Optional.
hotReloadCommand:
-

# List of ports that the service container exposes.
#
# Optional.
Expand Down Expand Up @@ -634,5 +642,31 @@ module:
# Optional.
env:
{}

# When this field is used, the files or directories specified within are automatically synced
# into the running container when they're modified. Additionally, any of this module's services
# that define a `hotReloadCommand` will be run with that command instead of the one specified in
# their `command` field. This behavior is only active while a Garden command with the -w (watch)
# flag, or `garden dev`, is running.
#
# Optional.
hotReload:
# Specify one or more source files or directories to automatically sync into the running
# container.
#
# Required.
sync:
- # POSIX-style path of the directory to sync to the target, relative to the module's
# top-level directory. Must be a relative path if provided. Defaults to the module's
# top-level directory if no value is provided.
#
# Optional.
source: .

# POSIX-style absolute path to sync the directory to inside the container. The root path
# (i.e. "/") is not allowed.
#
# Required.
target:
```
3 changes: 2 additions & 1 deletion examples/hello-world/.garden/local-config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
kubernetes:
username: hello
previous-usernames:
- hello
linkedModuleSources: []
linkedProjectSources: []
9 changes: 9 additions & 0 deletions examples/hot-reload/garden.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
project:
name: hot-reload
environmentDefaults:
providers:
- name: container
environments:
- name: local
providers:
- name: local-kubernetes
4 changes: 4 additions & 0 deletions examples/hot-reload/node-service/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
Dockerfile
garden.yml
app.yaml
12 changes: 12 additions & 0 deletions examples/hot-reload/node-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM node:9-alpine

ENV PORT=8080
EXPOSE ${PORT}

ADD . /app
WORKDIR /app

RUN npm install -g nodemon
RUN npm install

CMD ["npm", "start"]
14 changes: 14 additions & 0 deletions examples/hot-reload/node-service/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const express = require("express")

const app = express()

app.get("/hello", (req, res) => {
res.json({message: "Hello from Node!"})
})

// This is the path GAE uses for health checks
app.get("/_ah/health", (req, res) => {
res.sendStatus(200)
})

module.exports = { app }
21 changes: 21 additions & 0 deletions examples/hot-reload/node-service/garden.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module:
description: Node greeting service
name: node-service
type: container
hotReload:
sync:
- target: /app/
services:
- name: node-service
command: [npm, start]
hotReloadCommand: [npm, run, dev]
ports:
- name: http
containerPort: 8080
ingresses:
- path: /hello
port: http
healthCheck:
httpGet:
path: /_ah/health
port: http
3 changes: 3 additions & 0 deletions examples/hot-reload/node-service/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { app } = require("./app")

app.listen(process.env.PORT, "0.0.0.0", () => console.log("App started"))
Loading

0 comments on commit 6c71a59

Please sign in to comment.