Skip to content

Commit

Permalink
add before and after hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
sethpollack committed Apr 3, 2019
1 parent 6a388b5 commit 574bd72
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ Full applet spec:
- `env_file` list
- `all_envs` bool (loads all local environment variables)
- `env_filter` string (regex to filter environment variables when using `all_envs`)
- `dependencies` list (list of applets to run first)
- `dependencies` (deprecated - use `before_hooks` instead)
- `before_hooks` list (list of applets to run first)
- `after_hooks` list (list of applets to run after)
- `links` list
- `image` string
- `image_tag` string
Expand Down
26 changes: 23 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,32 @@ func main() {
a.PreExec()
}

Exec(r, a, args...)
err := Exec(r, a, args...)
if err != nil {
fmt.Print(err)
os.Exit(1)
}
}
}

func Exec(r *repo.Repo, a repo.Applet, args ...string) error {
for _, dep := range a.Dependencies {
for _, dep := range a.BeforeHooks {
d, ok := r.Applets[dep]
if !ok {
return fmt.Errorf("dependency %s not found", dep)
}
err := Exec(r, d)
if err != nil {
return err
}
}

err := a.Exec(args...)
if err != nil {
return err
}

for _, dep := range a.AfterHooks {
d, ok := r.Applets[dep]
if !ok {
return fmt.Errorf("dependency %s not found", dep)
Expand All @@ -62,5 +82,5 @@ func Exec(r *repo.Repo, a repo.Applet, args ...string) error {
}
}

return a.Exec(args...)
return nil
}
5 changes: 5 additions & 0 deletions repo/applet.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ type Applet struct {
Ports []string `yaml:"ports"`
EnvFile []string `yaml:"env_file"`
Dependencies []string `yaml:"dependencies"`
BeforeHooks []string `yaml:"before_hooks"`
AfterHooks []string `yaml:"after_hooks"`
Links []string `yaml:"links"`

Image string `yaml:"image"`
Expand Down Expand Up @@ -73,6 +75,9 @@ func (a *Applet) UnmarshalYAML(unmarshal func(interface{}) error) error {
return err
}

raw.BeforeHooks = append(raw.Dependencies, raw.BeforeHooks...)
raw.Dependencies = nil

*a = Applet(raw)
return nil
}
Expand Down

0 comments on commit 574bd72

Please sign in to comment.