Skip to content

Commit

Permalink
feat: tasks/workflows implemented
Browse files Browse the repository at this point in the history
Also implemented DependencyGraph, to support the corresponding changes
to dependant calculations.
  • Loading branch information
thsig committed Nov 20, 2018
1 parent 92742c0 commit de9275b
Show file tree
Hide file tree
Showing 105 changed files with 4,983 additions and 365 deletions.
13 changes: 13 additions & 0 deletions Gopkg.lock

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

32 changes: 29 additions & 3 deletions docs/reference/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -446,9 +446,9 @@ This is useful for debugging or ad-hoc experimentation with modules.

Examples:

garden run module my-container # run an ad-hoc instance of a my-container container and attach to it
garden run module my-container /bin/sh # run an interactive shell in a new my-container container
garden run module my-container --i=false /some/script # execute a script in my-container and return the output
garden run module my-container # run an ad-hoc instance of a my-container container and attach to it
garden run module my-container /bin/sh # run an interactive shell in a new my-container container
garden run module my-container --interactive=false /some/script # execute a script in my-container and return the output

##### Usage

Expand Down Expand Up @@ -494,6 +494,32 @@ Examples:
| -------- | ----- | ---- | ----------- |
| `--force-build` | | boolean | Force rebuild of module.

### garden run task

Run a task (in the context of its parent module).

This is useful for re-running tasks on the go, for example after writing/modifying database migrations.

Examples:

garden run task my-db-migration # run my-migration

##### Usage

garden run task <task> [options]

##### Arguments

| Argument | Required | Description |
| -------- | -------- | ----------- |
| `task` | Yes | The name of the task to run.

##### Options

| Argument | Alias | Type | Description |
| -------- | ----- | ---- | ----------- |
| `--force-build` | | boolean | Force rebuild of module before running.

### garden run test

Run the specified module test.
Expand Down
90 changes: 62 additions & 28 deletions docs/reference/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,8 @@ module:
# Required.
name:

# Names of the services that must be running before the test is run.
# The names of any services that must be running, and the names of any tasks that must be
# executed, before the test is run.
#
# Optional.
dependencies:
Expand Down Expand Up @@ -444,6 +445,36 @@ module:
# Optional.
image:

# 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. Services are only deployed with hot reloading enabled when their names
# are passed to the `--hot-reload` option in a call to the `deploy` or `dev` command.
#
# 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.
#
# Example: "src"
#
# Optional.
source: .

# POSIX-style absolute path to sync the directory to inside the container. The root path
# (i.e. "/") is not allowed.
#
# Example: "/app/src"
#
# Required.
target:

# POSIX-style name of Dockerfile, relative to project root. Defaults to $MODULE_ROOT/Dockerfile.
#
# Optional.
Expand All @@ -463,7 +494,8 @@ module:
# Required.
name:

# The names of services that this service depends on at runtime.
# The names of any services that this service depends on at runtime, and the names of any
# tasks that should be executed before this service is deployed.
#
# Optional.
dependencies:
Expand Down Expand Up @@ -622,7 +654,8 @@ module:
# Required.
name:

# Names of the services that must be running before the test is run.
# The names of any services that must be running, and the names of any tasks that must be
# executed, before the test is run.
#
# Optional.
dependencies:
Expand All @@ -646,34 +679,35 @@ module:
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. Services are only deployed with hot reloading enabled when their names
# are passed to the `--hot-reload` option in a call to the `deploy` or `dev` command.
# A list of tasks that can be run from this container module. These can be used as dependencies
# for services (executed before the service is deployed) or for other tasks.
#
# Optional.
hotReload:
# Specify one or more source files or directories to automatically sync into the running
# container.
tasks:
# The task specification for a generic module.
#
# 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.
#
# Example: "src"
#
# Optional.
source: .
# Optional.
- # The name of the task.
#
# Required.
name:

# POSIX-style absolute path to sync the directory to inside the container. The root path
# (i.e. "/") is not allowed.
#
# Example: "/app/src"
#
# Required.
target:
# The names of any tasks that must be executed, and the names of any services that must be
# running, before this task is executed.
#
# Optional.
dependencies:
-

# Maximum duration (in seconds) of the task's execution.
#
# Optional.
timeout: null

# The command that the task should run inside the container.
#
# Optional.
command:
-
```
5 changes: 0 additions & 5 deletions examples/hello-world/.garden/local-config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +0,0 @@
kubernetes:
previous-usernames:
- hello
linkedModuleSources: []
linkedProjectSources: []
6 changes: 6 additions & 0 deletions examples/tasks/garden.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
project:
name: tasks
environments:
- name: local
providers:
- name: local-kubernetes
4 changes: 4 additions & 0 deletions examples/tasks/hello-service/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
Dockerfile
garden.yml
app.yaml
13 changes: 13 additions & 0 deletions examples/tasks/hello-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM node:9-alpine

ENV PORT=8080
EXPOSE ${PORT}
WORKDIR /app

ADD package.json /app
RUN npm install knex -g
RUN npm install

ADD . /app

CMD ["npm", "start"]
25 changes: 25 additions & 0 deletions examples/tasks/hello-service/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const express = require("express")
const knex = require("knex")({
client: "postgresql",
connection: {
host: "postgres-service",
port: 5432,
database: "postgres",
user: "postgres",
},
pool: {
min: 4,
max: 10
},
})

const app = express();

app.get("/hello", (req, res) => {
knex.select("name").from("users")
.then((rows) => {
res.send(`Hello from Node! Usernames: ${rows.map(r => r.name).join(', ')}`)
})
});

module.exports = { app }
24 changes: 24 additions & 0 deletions examples/tasks/hello-service/garden.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module:
name: hello-service
description: Greeting service
type: container
services:
- name: hello-service
command: [npm, start]
ports:
- name: http
containerPort: 8080
ingresses:
- path: /hello
port: http
dependencies:
- node-migration
tests:
- name: unit
command: [npm, test]
tasks:
- name: node-migration
# sleep to give postgres time to get ready
command: ["sleep 5 && knex migrate:latest"]
dependencies:
- postgres-service
18 changes: 18 additions & 0 deletions examples/tasks/hello-service/knexfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
development: {
client: "postgresql",
connection: {
host: "postgres-service",
port: 5432,
database: "postgres",
user: "postgres",
},
pool: {
min: 4,
max: 10
},
migrations: {
tableName: "knex_migrations"
}
}
}
3 changes: 3 additions & 0 deletions examples/tasks/hello-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('Node service started'));
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

exports.up = function(knex) {
return knex.schema.createTable("users", function(t) {
t.increments("id").unsigned().primary();
t.dateTime("created_at").notNull();
t.dateTime("updated_at").nullable();
t.string("name").notNull();
});
};

exports.down = function(knex) {
return knex.schema.dropTable("users");
};
Loading

0 comments on commit de9275b

Please sign in to comment.