diff --git a/tools/.gitignore b/tools/.gitignore index b6ea60f8f..635dff1f1 100644 --- a/tools/.gitignore +++ b/tools/.gitignore @@ -2,5 +2,6 @@ cover/cover socks/proxy socks/image.tar runner/runner +cmd/wcloud/wcloud *.pyc *~ diff --git a/tools/circle.yml b/tools/circle.yml index 0c1ebddb1..74cf3d40a 100644 --- a/tools/circle.yml +++ b/tools/circle.yml @@ -20,4 +20,5 @@ test: - cd $SRCDIR/cover; make - cd $SRCDIR/socks; make - cd $SRCDIR/runner; make + - cd $SRCDIR/cmd/wcloud; make diff --git a/tools/cmd/wcloud/Makefile b/tools/cmd/wcloud/Makefile new file mode 100644 index 000000000..86b0df380 --- /dev/null +++ b/tools/cmd/wcloud/Makefile @@ -0,0 +1,11 @@ +.PHONY: all clean + +all: wcloud + +wcloud: *.go + go get ./$(@D) + go build -o $@ ./$(@D) + +clean: + rm -rf wcloud + go clean ./... diff --git a/tools/cmd/wcloud/cli.go b/tools/cmd/wcloud/cli.go index cd11bd30f..663119ed5 100644 --- a/tools/cmd/wcloud/cli.go +++ b/tools/cmd/wcloud/cli.go @@ -7,6 +7,7 @@ import ( "fmt" "io/ioutil" "os" + "os/user" "path/filepath" "strings" "time" @@ -15,6 +16,19 @@ import ( "gopkg.in/yaml.v2" ) +// ArrayFlags allows you to collect repeated flags +type ArrayFlags []string + +func (a *ArrayFlags) String() string { + return strings.Join(*a, ",") +} + +// Set implements flags.Value +func (a *ArrayFlags) Set(value string) error { + *a = append(*a, value) + return nil +} + func env(key, def string) string { if val, ok := os.LookupEnv(key); ok { return val @@ -62,6 +76,17 @@ func main() { } func deploy(c Client, args []string) { + var ( + flags = flag.NewFlagSet("", flag.ContinueOnError) + username = flags.String("u", "", "Username to report to deploy service (default with be current user)") + services ArrayFlags + ) + flag.Var(&services, "service", "Service to update (can be repeated)") + if err := flags.Parse(args); err != nil { + usage() + return + } + args = flags.Args() if len(args) != 1 { usage() return @@ -71,9 +96,19 @@ func deploy(c Client, args []string) { usage() return } + if *username == "" { + user, err := user.Current() + if err != nil { + fmt.Println(err.Error()) + os.Exit(1) + } + *username = user.Username + } deployment := Deployment{ - ImageName: parts[0], - Version: parts[1], + ImageName: parts[0], + Version: parts[1], + TriggeringUser: *username, + IntendedServices: services, } if err := c.Deploy(deployment); err != nil { fmt.Println(err.Error()) diff --git a/tools/cmd/wcloud/types.go b/tools/cmd/wcloud/types.go index b02ee4c14..178655c28 100644 --- a/tools/cmd/wcloud/types.go +++ b/tools/cmd/wcloud/types.go @@ -12,13 +12,16 @@ type Deployment struct { Version string `json:"version"` Priority int `json:"priority"` State string `json:"status"` - LogKey string `json:"-"` + + TriggeringUser string `json:"triggering_user"` + IntendedServices []string `json:"intended_services"` } // Config for the deployment system for a user. type Config struct { RepoURL string `json:"repo_url" yaml:"repo_url"` RepoPath string `json:"repo_path" yaml:"repo_path"` + RepoBranch string `json:"repo_branch" yaml:"repo_branch"` RepoKey string `json:"repo_key" yaml:"repo_key"` KubeconfigPath string `json:"kubeconfig_path" yaml:"kubeconfig_path"` @@ -26,10 +29,13 @@ type Config struct { // Globs of files not to change, relative to the route of the repo ConfigFileBlackList []string `json:"config_file_black_list" yaml:"config_file_black_list"` + + CommitMessageTemplate string `json:"commit_message_template" yaml:"commit_message_template"` // See https://golang.org/pkg/text/template/ } // NotificationConfig describes how to send notifications type NotificationConfig struct { SlackWebhookURL string `json:"slack_webhook_url" yaml:"slack_webhook_url"` SlackUsername string `json:"slack_username" yaml:"slack_username"` + MessageTemplate string `json:"message_template" yaml:"message_template"` } diff --git a/tools/integration/gce.sh b/tools/integration/gce.sh index 1f1019fce..dd0e92770 100755 --- a/tools/integration/gce.sh +++ b/tools/integration/gce.sh @@ -39,6 +39,7 @@ function vm_names { # Delete all vms in this account function destroy { + local names names="$(vm_names)" if [ "$(gcloud compute instances list --zone "$ZONE" -q "$names" | wc -l)" -le 1 ] ; then return 0 diff --git a/tools/runner/runner.go b/tools/runner/runner.go index 707369d81..c92ac6b5b 100644 --- a/tools/runner/runner.go +++ b/tools/runner/runner.go @@ -14,8 +14,8 @@ import ( "sync" "time" - "github.com/docker/docker/pkg/mflag" "github.com/mgutz/ansi" + "github.com/weaveworks/docker/pkg/mflag" ) const ( diff --git a/tools/shell-lint b/tools/shell-lint index 5cc77cb2a..2bf3587bf 100755 --- a/tools/shell-lint +++ b/tools/shell-lint @@ -10,4 +10,5 @@ # - files-with-type # - file >= 5.22 -"$(dirname "${BASH_SOURCE[0]}")/files-with-type" text/x-shellscript "$@" | xargs shellcheck +"$(dirname "${BASH_SOURCE[0]}")/files-with-type" text/x-shellscript "$@" | xargs --no-run-if-empty shellcheck + diff --git a/tools/socks/main.go b/tools/socks/main.go index 520df27d9..83a214980 100644 --- a/tools/socks/main.go +++ b/tools/socks/main.go @@ -9,7 +9,7 @@ import ( "text/template" socks5 "github.com/armon/go-socks5" - "github.com/docker/docker/pkg/mflag" + "github.com/weaveworks/docker/pkg/mflag" "github.com/weaveworks/weave/common/mflagext" "golang.org/x/net/context" )