Skip to content

Commit

Permalink
Allow globbing in src for -overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
markriggins committed Apr 5, 2016
1 parent dfdf1ed commit a0807de
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
21 changes: 16 additions & 5 deletions dockerfy.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log"
"os"
"os/exec"
"path/filepath"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -154,17 +155,27 @@ func main() {
log.Fatalf("bad overlay argument: '%s'. expected \"/src:/dest\"", o)
}
src, dest := os.ExpandEnv(string_template_eval(parts[0])), os.ExpandEnv(string_template_eval(parts[1]))

if _, err := os.Stat(src); os.IsNotExist(err) {
log.Printf("overlay source: %s does not exist. Skipping", src)
continue
}
log.Printf("overlaying %s --> %s", src, dest)

cmd := exec.Command("cp", "-rv", src, dest)
cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr
if err := cmd.Run(); err != nil {
log.Fatal(err)
var cmd *exec.Cmd

if strings.HasSuffix(src, "/") {
src += "*"
}
if matches, err := filepath.Glob(src); err == nil {
for _, dir := range matches {
cmd = exec.Command("cp", "-rv", dir, dest)
cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr
if err := cmd.Run(); err != nil {
log.Fatal(err)
}
}
} else {
log.Printf("No matches for overlay source: '%s':%s", src, err)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/nginx/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ run-prod-secrets: stop
-v $(PWD):/secrets \
-e SECRETS_FILE=/secrets/secrets.env \
dockerfied-nginx \
-overlay /tmp/overlays/_common/html:/usr/share/nginx/ \
-overlay /tmp/overlays/_common/:/usr/share/nginx/ \
-overlay '/tmp/overlays/{{ .Env.DEPLOYMENT_ENV }}/html:/usr/share/nginx/' \
-template '/secrets/secrets.html.tmpl:/usr/share/nginx/html/secrets.html' \
-- nginx
Expand Down

0 comments on commit a0807de

Please sign in to comment.