Skip to content

Commit

Permalink
feat: hot-reload functionality for local k8s
Browse files Browse the repository at this point in the history
When the local-kubernetes provider is used, container modules can now be
configured to hot-reload their running services when the module's
sources change (i.e. without redeploying).

Services that can be run with an FS watcher that automatically applies
changed sources to the running application (e.g. nodemon and many other
web app frameworks) are a natural fit for this feature.
  • Loading branch information
thsig committed Oct 11, 2018
1 parent b0b5599 commit ff0001d
Show file tree
Hide file tree
Showing 59 changed files with 6,272 additions and 178 deletions.
34 changes: 34 additions & 0 deletions docs/reference/config.md
Original file line number Diff line number Diff line change
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:
```
4 changes: 4 additions & 0 deletions examples/hot-reload/build-dependant/.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/build-dependant/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/build-dependant/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("/dependant", (req, res) => {
res.json({message: "Build dependant"})
})

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

module.exports = { app }
20 changes: 20 additions & 0 deletions examples/hot-reload/build-dependant/garden.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module:
description: Build dependant
name: build-dependant
type: container
services:
- name: build-dependant
command: [npm, start]
ports:
- name: http
containerPort: 8080
ingresses:
- path: /dependant
port: http
healthCheck:
httpGet:
path: /_ah/health
port: http
build:
dependencies:
- good-morning
3 changes: 3 additions & 0 deletions examples/hot-reload/build-dependant/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 ff0001d

Please sign in to comment.