From 6ccc1729fb841f40a0aa91f2946140e06722865e Mon Sep 17 00:00:00 2001 From: Andrews Medina Date: Sat, 22 Mar 2014 23:22:01 -0300 Subject: [PATCH] implemented tsuru deploy plugin. --- pkg/plugin/deploy/deployment.go | 4 ++++ pkg/plugin/deploy/tsuru.go | 38 +++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 pkg/plugin/deploy/tsuru.go diff --git a/pkg/plugin/deploy/deployment.go b/pkg/plugin/deploy/deployment.go index fec3b28c8..44aef7fc1 100644 --- a/pkg/plugin/deploy/deployment.go +++ b/pkg/plugin/deploy/deployment.go @@ -18,6 +18,7 @@ type Deploy struct { Nodejitsu *Nodejitsu `yaml:"nodejitsu,omitempty"` Openshift *Openshift `yaml:"openshift,omitempty"` SSH *SSH `yaml:"ssh,omitempty"` + Tsuru *Tsuru `yaml:"tsuru,omitempty"` } func (d *Deploy) Write(f *buildfile.Buildfile) { @@ -51,4 +52,7 @@ func (d *Deploy) Write(f *buildfile.Buildfile) { if d.SSH != nil { d.SSH.Write(f) } + if d.Tsuru != nil { + d.Tsuru.Write(f) + } } diff --git a/pkg/plugin/deploy/tsuru.go b/pkg/plugin/deploy/tsuru.go new file mode 100644 index 000000000..12f9a3c59 --- /dev/null +++ b/pkg/plugin/deploy/tsuru.go @@ -0,0 +1,38 @@ +package deploy + +import ( + "fmt" + "github.com/drone/drone/pkg/build/buildfile" +) + +type Tsuru struct { + Force bool `yaml:"force,omitempty"` + Branch string `yaml:"branch,omitempty"` + Remote string `yaml:"remote,omitempty"` +} + +func (h *Tsuru) Write(f *buildfile.Buildfile) { + // get the current commit hash + f.WriteCmdSilent("COMMIT=$(git rev-parse HEAD)") + + // set the git user and email based on the individual + // that made the commit. + f.WriteCmdSilent("git config --global user.name $(git --no-pager log -1 --pretty=format:'%an')") + f.WriteCmdSilent("git config --global user.email $(git --no-pager log -1 --pretty=format:'%ae')") + + // add tsuru as a git remote + f.WriteCmd(fmt.Sprintf("git remote add tsuru %s", h.Remote)) + + switch h.Force { + case true: + // this is useful when the there are artifacts generated + // by the build script, such as less files converted to css, + // that need to be deployed to Tsuru. + f.WriteCmd(fmt.Sprintf("git add -A")) + f.WriteCmd(fmt.Sprintf("git commit -m 'adding build artifacts'")) + f.WriteCmd(fmt.Sprintf("git push tsuru $COMMIT:master --force")) + case false: + // otherwise we just do a standard git push + f.WriteCmd(fmt.Sprintf("git push tsuru $COMMIT:master")) + } +}