diff --git a/plugin/deploy/deployment.go b/plugin/deploy/deployment.go index 4d0697c4..6cb5e960 100644 --- a/plugin/deploy/deployment.go +++ b/plugin/deploy/deployment.go @@ -8,6 +8,7 @@ import ( "github.com/drone/drone/plugin/deploy/git" "github.com/drone/drone/plugin/deploy/heroku" "github.com/drone/drone/plugin/deploy/modulus" + "github.com/drone/drone/plugin/deploy/nodejitsu" "github.com/drone/drone/plugin/deploy/tsuru" ) @@ -15,14 +16,14 @@ import ( // for deploying build artifacts when // a Build has succeeded type Deploy struct { - CloudFoundry *CloudFoundry `yaml:"cloudfoundry,omitempty"` - Git *git.Git `yaml:"git,omitempty"` - Heroku *heroku.Heroku `yaml:"heroku,omitempty"` - Modulus *modulus.Modulus `yaml:"modulus,omitempty"` - Nodejitsu *Nodejitsu `yaml:"nodejitsu,omitempty"` - SSH *SSH `yaml:"ssh,omitempty"` - Tsuru *tsuru.Tsuru `yaml:"tsuru,omitempty"` - Bash *Bash `yaml:"bash,omitempty"` + CloudFoundry *CloudFoundry `yaml:"cloudfoundry,omitempty"` + Git *git.Git `yaml:"git,omitempty"` + Heroku *heroku.Heroku `yaml:"heroku,omitempty"` + Modulus *modulus.Modulus `yaml:"modulus,omitempty"` + Nodejitsu *nodejitsu.Nodejitsu `yaml:"nodejitsu,omitempty"` + SSH *SSH `yaml:"ssh,omitempty"` + Tsuru *tsuru.Tsuru `yaml:"tsuru,omitempty"` + Bash *Bash `yaml:"bash,omitempty"` } func (d *Deploy) Write(f *buildfile.Buildfile, r *repo.Repo) { diff --git a/plugin/deploy/nodejitsu/nodejitsu.go b/plugin/deploy/nodejitsu/nodejitsu.go new file mode 100644 index 00000000..11eb215c --- /dev/null +++ b/plugin/deploy/nodejitsu/nodejitsu.go @@ -0,0 +1,32 @@ +package nodejitsu + +import ( + "github.com/drone/drone/plugin/condition" + "github.com/drone/drone/shared/build/buildfile" +) + +type Nodejitsu struct { + User string `yaml:"user,omitempty"` + Token string `yaml:"token,omitempty"` + + Condition *condition.Condition `yaml:"when,omitempty"` +} + +func (n *Nodejitsu) Write(f *buildfile.Buildfile) { + if len(n.Token) == 0 || len(n.User) == 0 { + return + } + + f.WriteEnv("username", n.User) + f.WriteEnv("apiToken", n.Token) + + // Install the jitsu command line interface then + // deploy the configured app. + f.WriteCmdSilent("[ -f /usr/bin/sudo ] || npm install -g jitsu") + f.WriteCmdSilent("[ -f /usr/bin/sudo ] && sudo npm install -g jitsu") + f.WriteCmd("jitsu deploy") +} + +func (n *Nodejitsu) GetCondition() *condition.Condition { + return n.Condition +} diff --git a/plugin/deploy/nodejitsu/nodejitsu_test.go b/plugin/deploy/nodejitsu/nodejitsu_test.go new file mode 100644 index 00000000..f1424d94 --- /dev/null +++ b/plugin/deploy/nodejitsu/nodejitsu_test.go @@ -0,0 +1,52 @@ +package nodejitsu + +import ( + "testing" + + "github.com/drone/drone/shared/build/buildfile" + "github.com/franela/goblin" +) + +func Test_Modulus(t *testing.T) { + + g := goblin.Goblin(t) + g.Describe("Nodejitsu Deploy", func() { + + g.It("Requires a User", func() { + b := new(buildfile.Buildfile) + n := Nodejitsu{ + User: "foo", + } + + n.Write(b) + g.Assert(b.String()).Equal("") + }) + + g.It("Requires a Token", func() { + b := new(buildfile.Buildfile) + n := Nodejitsu{ + Token: "bar", + } + + n.Write(b) + g.Assert(b.String()).Equal("") + }) + + g.It("Should execute deploy commands", func() { + b := new(buildfile.Buildfile) + n := Nodejitsu{ + User: "foo", + Token: "bar", + } + + n.Write(b) + g.Assert(b.String()).Equal(`export username=foo +export apiToken=bar +[ -f /usr/bin/sudo ] || npm install -g jitsu +[ -f /usr/bin/sudo ] && sudo npm install -g jitsu +echo '#DRONE:6a69747375206465706c6f79' +jitsu deploy +`) + }) + }) +}