Skip to content

Commit

Permalink
config: parse yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
boz committed Apr 26, 2017
1 parent 146340b commit fab5026
Show file tree
Hide file tree
Showing 39 changed files with 441 additions and 359 deletions.
89 changes: 37 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ development machines.
To run the server, supply a configuration file:

```sh
$ ephemerald -c config.json
$ ephemerald -c config.yaml
```

Press Q to quit the server.
Expand All @@ -61,53 +61,43 @@ Note: use Ctrl-C to stop the server wen not in `--ui tui` mode (`SIGINT`,`SIGQUI
For example, to see only log messages (at debug level) use:

```sh
$ ephememerald --ui none --log-level debug --log-file /dev/stdout -c config.json
$ ephememerald --ui none --log-level debug --log-file /dev/stdout -c config.yaml
```

## Configuration

Container pools are configured in a json file. Each pool has options for the container parameters and
Container pools are configured in a yaml (or json) file. Each pool has options for the container parameters and
for lifecycle actions.

The following configuration creates a single pool called "pg" which maintains five containers from the "postgres" image and
exposes port 5432 to clients. See the [`params`](#params) and [`actions`](#lifecycle-actions) below for documentation on those fields.

```json
{
"pools": {
"pg": {
"image": "postgres",
"size": 5,
"port": 5432,
"params": {
"username": "postgres",
"password": "",
"database": "postgres",
"url": "postgres://{{.Username}}:{{.Password}}@{{.Hostname}}:{{.Port}}/{{.Database}}?sslmode=disable"
},
"actions": {
"healthcheck": {
"type": "postgres.ping",
"retries": 10,
"delay": "50ms"
},
"initialize": {
"type": "exec",
"path": "make",
"args": ["db:migrate"],
"env": ["DATABASE_URL={{.Url}}"],
"timeout": "10s",
},
"reset": {
"type": "postgres.truncate"
}
}
}
}
}
```yaml
pools:
pg:
image: postgres
size: 5
port: 5432
params:
username: postgres
database: postgres
url: postgres://{{.Username}}:@{{.Hostname}}:{{.Port}}/{{.Database}}?sslmode=disable
actions:
healthcheck:
type: postgres.ping
retries: 10
delay: 50ms
initialize:
type: exec
path: make
args: [ 'db:migrate' ]
env: [ 'DATABASE_URL={{.Url}}' ]
timeout: 10s
reset:
type: postgres.truncate
```
See [example/config.json](_example/config.json) for a full working configuration.
See [example/config.yaml](_example/config.yaml) for a full working configuration.
### Params
Expand All @@ -126,13 +116,10 @@ Database | The `database` field declared in `params`

A `params` section for postgres may look like this:

```json
{
"username": "postgres",
"password": "",
"database": "postgres",
"url": "postgres://{{.Username}}:{{.Password}}@{{.Hostname}}:{{.Port}}/{{.Database}}?sslmode=disable"
}
```yaml
username: postgres
database: postgres
url: postgres://{{.Username}}:{{.Password}}@{{.Hostname}}:{{.Port}}/{{.Database}}?sslmode=disable
```

### Container
Expand Down Expand Up @@ -233,12 +220,10 @@ args | `[]` | values to be escaped with positional arguments in `command`.

Example:

```json
{
"type": "postgres.exec",
"command": "INSERT INTO users (name) VALUES ($1)",
"args": "Robert'); DROP TABLE STUDENTS;--"
}
```yaml
type: postgres.exec
command: 'INSERT INTO users (name) VALUES ($1)'
args: "Robert'); DROP TABLE STUDENTS;--"
```

#### postgres.ping
Expand Down Expand Up @@ -365,7 +350,7 @@ $ make server example
Run the example server and client in separate terminals

```sh
$ ./ephemerald/ephemerald -f ./_example/config.json
$ ./ephemerald/ephemerald -c _example/config.yaml
```

```sh
Expand All @@ -389,7 +374,7 @@ Download the [latest release](https://github.com/boz/ephemerald/releases/latest)
```sh
$ release="https://github.com/boz/ephemerald/releases/download/v0.3.1/ephemerald_Linux_x86_64.tar.gz"
$ curl -L "$release" | tar -C /tmp -zxv
$ /tmp/ephemerald -c config.json
$ /tmp/ephemerald -c config.yaml
```

### Homebrew
Expand Down
44 changes: 0 additions & 44 deletions _example/config.json

This file was deleted.

35 changes: 35 additions & 0 deletions _example/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
pools:
redis:
image: redis
size: 5
port: 6379
params:
database: "0"
url: redis://{{.Hostname}}:{{.Port}}/{{.Database}}
actions:
healthcheck:
type: redis.ping
reset:
type: redis.truncate
postgres:
image: postgres
size: 5
port: 5432
params:
username: postgres
database: postgres
url: postgres://{{.Username}}:{{.Password}}@{{.Hostname}}:{{.Port}}/{{.Database}}?sslmode=disable
actions:
initialize:
type: postgres.exec
query: |
CREATE TABLE users (
id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL,
UNIQUE(name)
)
healthcheck:
type: postgres.ping
reset:
type: postgres.truncate
63 changes: 0 additions & 63 deletions _example/demo.json

This file was deleted.

50 changes: 50 additions & 0 deletions _example/demo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
pools:
redis:
image: redis
size: 5
port: 6379
params:
database: '0'
url: redis://{{.Hostname}}:{{.Port}}/{{.Database}}
actions:
healthcheck:
type: redis.ping
reset:
type: exec
path: sleep
args: [ '1' ]
vault:
image: vault
size: 5
port: 8200
container:
env:
- SKIP_SETCAP=1
params:
url: http://{{.Hostname}}:{{.Port}}
actions:
healthcheck:
type: http.get
postgres:
image: postgres
size: 5
port: 5432
params:
username: postgres
database: postgres
url: postgres://{{.Username}}:{{.Password}}@{{.Hostname}}:{{.Port}}/{{.Database}}?sslmode=disable
actions:
initialize:
type: postgres.exec
query: |
CREATE TABLE users (
id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL,
UNIQUE(name)
)
healthcheck:
type: postgres.ping
retries: 20
reset:
type: postgres.truncate
18 changes: 0 additions & 18 deletions _example/ui.json

This file was deleted.

12 changes: 12 additions & 0 deletions _example/ui.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
pools:
redis:
image: redis
size: 5
port: 6379
params:
database: '0'
url: redis://{{.Hostname}}:{{.Port}}/{{.Database}}
actions:
healthcheck:
type: redis.ping
2 changes: 1 addition & 1 deletion _testdata/pool.redis.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"size": 1,
"image": "redis"
"image": "redis",
"port": 6379,
"actions": {
"healthcheck": {
Expand Down
2 changes: 1 addition & 1 deletion _testdata/pools.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"redis": {
"size": 1,
"image": "redis"
"image": "redis",
"port": 6379,
"params": {
"database": "0",
Expand Down
Loading

0 comments on commit fab5026

Please sign in to comment.