summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Duvall <dduvall@wikimedia.org>2017-04-25 16:29:58 -0700
committerDan Duvall <dduvall@wikimedia.org>2017-04-25 16:29:58 -0700
commit72a866a74aade72fd9b22a6f364a68193087e8f3 (patch)
tree35c33df8b389cffe917bd9bb86122f114dc448a0
parentb993d5c7398fd5bba968d400d5731df7d321a557 (diff)
downloadblubber-72a866a74aade72fd9b22a6f364a68193087e8f3.tar.gz
Use a YAML config format instead of JSON
-rw-r--r--README.md86
-rw-r--r--blubber.example.json23
-rw-r--r--blubber.example.yaml33
-rw-r--r--config/apt.go2
-rw-r--r--config/artifacts.go6
-rw-r--r--config/common.go12
-rw-r--r--config/config.go4
-rw-r--r--config/npm.go4
-rw-r--r--config/reader.go4
-rw-r--r--config/run.go8
-rw-r--r--config/variant.go6
-rw-r--r--main.go2
12 files changed, 106 insertions, 84 deletions
diff --git a/README.md b/README.md
index 8aa409b..6635e67 100644
--- a/README.md
+++ b/README.md
@@ -10,30 +10,39 @@ running ad-hoc commands.
## Example configuration
-```json
-{
- "base": "debian:jessie",
- "apt": { "packages": ["libjpeg", "libyaml"] },
- "npm": { "install": true },
- "run": { "in": "/srv/service", "as": "runuser", "uid": 666, "gid": 666 },
- "variants": {
- "development": {
- "apt": { "packages": ["libjpeg-dev", "libyaml-dev"] }
- },
- "test": {
- "includes": ["development"],
- "apt": { "packages": ["chromium"] },
- "copiestree": true,
- "entrypoint": ["npm", "test"]
- },
- "production": {
- "base": "debian:jessie-slim",
- "npm": { "env": "production" },
- "artifacts": [{ "from": "test", "source": "/srv/service", "destination": "." }],
- "entrypoint": ["npm", "start"]
- }
- }
-}
+```yaml
+base: debian:jessie
+apt:
+ packages: [libjpeg, libyaml]
+npm:
+ install: true
+run:
+ in: /srv/service
+ as: runuser
+ uid: 666
+ gid: 666
+
+variants:
+ development:
+ apt:
+ packages: [libjpeg-dev, libyaml-dev]
+ sharedvolume: true
+
+ test:
+ includes: [development]
+ apt:
+ packages: [chromium]
+ entrypoint: [npm, test]
+
+ production:
+ base: debian:jessie-slim
+ npm:
+ env: production
+ artifacts:
+ - from: test
+ source: /srv/service
+ destination: .
+ entrypoint: [npm, start]
```
## Variants
@@ -52,15 +61,18 @@ properties, like `apt:packages` are combined when inherited or included.
In the example configuration, the `test` variant when expanded effectively
becomes:
-```json
-{
- "base": "debian:jessie",
- "apt": { "packages": ["libjpeg", "libyaml", "libjpeg-dev", "libyaml-dev", "chromium"] },
- "npm": { "install": true },
- "run": { "in": "/srv/service", "as": "runuser", "uid": 666, "gid": 666 },
- "copiestree": true,
- "entrypoint": ["npm", "test"]
-}
+```yaml
+base: debian:jessie
+apt:
+ packages: [libjpeg, libyaml, libjpeg-dev, libyaml-dev, chromium]
+npm:
+ install: true
+run:
+ in: /srv/service
+ as: runuser
+ uid: 666
+ gid: 666
+entrypoint: [npm, test]
```
## Artifacts
@@ -82,12 +94,12 @@ be copied over from the result of building the `test` image.
Running the `blubber` command will be produce `Dockerfile` output for the
given variant.
- blubber config.json variant
+ blubber config.yaml variant
You can see the result of the example configuration by cloning this repo and
running (assuming you have go and your GOPATH set up properly):
go build
- ./blubber blubber blubber.example.json development
- ./blubber blubber blubber.example.json test
- ./blubber blubber blubber.example.json production
+ ./blubber blubber blubber.example.yaml development
+ ./blubber blubber blubber.example.yaml test
+ ./blubber blubber blubber.example.yaml production
diff --git a/blubber.example.json b/blubber.example.json
deleted file mode 100644
index b911764..0000000
--- a/blubber.example.json
+++ /dev/null
@@ -1,23 +0,0 @@
-{
- "base": "debian:jessie",
- "apt": { "packages": ["libjpeg", "libyaml"] },
- "npm": { "install": true },
- "run": { "in": "/srv/service", "as": "runuser", "uid": 666, "gid": 666 },
- "variants": {
- "development": {
- "apt": { "packages": ["libjpeg-dev", "libyaml-dev"] },
- "sharedvolume": true
- },
- "test": {
- "includes": ["development"],
- "apt": { "packages": ["chromium"] },
- "entrypoint": ["npm", "test"]
- },
- "production": {
- "base": "debian:jessie-slim",
- "npm": { "env": "production" },
- "artifacts": [{ "from": "test", "source": "/srv/service", "destination": "." }],
- "entrypoint": ["npm", "start"]
- }
- }
-}
diff --git a/blubber.example.yaml b/blubber.example.yaml
new file mode 100644
index 0000000..0134062
--- /dev/null
+++ b/blubber.example.yaml
@@ -0,0 +1,33 @@
+---
+base: debian:jessie
+apt:
+ packages: [libjpeg, libyaml]
+npm:
+ install: true
+run:
+ in: /srv/service
+ as: runuser
+ uid: 666
+ gid: 666
+
+variants:
+ development:
+ apt:
+ packages: [libjpeg-dev, libyaml-dev]
+ sharedvolume: true
+
+ test:
+ includes: [development]
+ apt:
+ packages: [chromium]
+ entrypoint: [npm, test]
+
+ production:
+ base: debian:jessie-slim
+ npm:
+ env: production
+ artifacts:
+ - from: test
+ source: /srv/service
+ destination: .
+ entrypoint: [npm, start]
diff --git a/config/apt.go b/config/apt.go
index e6ad22c..f9e631f 100644
--- a/config/apt.go
+++ b/config/apt.go
@@ -6,7 +6,7 @@ import (
)
type AptConfig struct {
- Packages []string `json:packages`
+ Packages []string `yaml:"packages"`
}
func (apt *AptConfig) Merge(apt2 AptConfig) {
diff --git a/config/artifacts.go b/config/artifacts.go
index 78b6276..fd7b741 100644
--- a/config/artifacts.go
+++ b/config/artifacts.go
@@ -1,7 +1,7 @@
package config
type ArtifactsConfig struct {
- From string `json:from`
- Source string `json:source`
- Destination string `json:destination`
+ From string `yaml:"from"`
+ Source string `yaml:"source"`
+ Destination string `yaml:"destination"`
}
diff --git a/config/common.go b/config/common.go
index 492171e..36ebc01 100644
--- a/config/common.go
+++ b/config/common.go
@@ -1,12 +1,12 @@
package config
type CommonConfig struct {
- Base string `json:base`
- Apt AptConfig `json:apt`
- Npm NpmConfig `json:npm`
- Run RunConfig `json:run`
- SharedVolume bool `json:sharedvolume`
- EntryPoint []string `json:entrypoint`
+ Base string `yaml:"base"`
+ Apt AptConfig `yaml:"apt"`
+ Npm NpmConfig `yaml:"npm"`
+ Run RunConfig `yaml:"run"`
+ SharedVolume bool `yaml:"sharedvolume"`
+ EntryPoint []string `yaml:"entrypoint"`
}
func (cc1 *CommonConfig) Merge(cc2 CommonConfig) {
diff --git a/config/config.go b/config/config.go
index 36eb6e4..dcf1adb 100644
--- a/config/config.go
+++ b/config/config.go
@@ -1,8 +1,8 @@
package config
type Config struct {
- CommonConfig
- Variants map[string]VariantConfig `json:variants`
+ CommonConfig `yaml:",inline"`
+ Variants map[string]VariantConfig `yaml:"variants"`
}
type CommandCompileable interface {
diff --git a/config/npm.go b/config/npm.go
index 250607e..c4a52c1 100644
--- a/config/npm.go
+++ b/config/npm.go
@@ -5,8 +5,8 @@ import (
)
type NpmConfig struct {
- Install bool `json:install`
- Env string `json:env`
+ Install bool `yaml:"install"`
+ Env string `yaml:"env"`
}
func (npm *NpmConfig) Merge(npm2 NpmConfig) {
diff --git a/config/reader.go b/config/reader.go
index f63a4c9..478a312 100644
--- a/config/reader.go
+++ b/config/reader.go
@@ -3,7 +3,7 @@ package config
import (
"errors"
"io/ioutil"
- "encoding/json"
+ "gopkg.in/yaml.v2"
)
func ExpandVariant(config *Config, name string) (*VariantConfig, error) {
@@ -29,7 +29,7 @@ func ExpandVariant(config *Config, name string) (*VariantConfig, error) {
func ReadConfig(data []byte) (*Config, error) {
var config Config
- err := json.Unmarshal(data, &config)
+ err := yaml.Unmarshal(data, &config)
return &config, err
}
diff --git a/config/run.go b/config/run.go
index c3ffd08..410eca6 100644
--- a/config/run.go
+++ b/config/run.go
@@ -6,10 +6,10 @@ import (
)
type RunConfig struct {
- In string `json:in`
- As string `json:as`
- Uid int `json:uid`
- Gid int `json:gid`
+ In string `yaml:"in"`
+ As string `yaml:"as"`
+ Uid int `yaml:"uid"`
+ Gid int `yaml:"uid"`
}
func (run *RunConfig) Merge(run2 RunConfig) {
diff --git a/config/variant.go b/config/variant.go
index d1640bb..808db72 100644
--- a/config/variant.go
+++ b/config/variant.go
@@ -1,9 +1,9 @@
package config
type VariantConfig struct {
- Includes []string `json:includes`
- Artifacts []ArtifactsConfig `json:artifacts`
- CommonConfig
+ Includes []string `yaml:"includes"`
+ Artifacts []ArtifactsConfig `yaml:"artifacts"`
+ CommonConfig `yaml:",inline"`
}
func (vc1 *VariantConfig) Merge(vc2 VariantConfig) {
diff --git a/main.go b/main.go
index 0c1e764..877bfe0 100644
--- a/main.go
+++ b/main.go
@@ -9,7 +9,7 @@ import (
func main() {
if len(os.Args) < 3 {
- fmt.Println("Usage: blubber config.json variant")
+ fmt.Println("Usage: blubber config.yaml variant")
os.Exit(1)
}