Merge pull request #735 from PierreKircher/master

deploy plugin for "DEIS PAAS"
This commit is contained in:
Brad Rydzewski 2014-12-01 01:48:11 -08:00
commit 8f6a031c6a
3 changed files with 129 additions and 0 deletions

View file

@ -0,0 +1,56 @@
package deis
import (
"fmt"
"github.com/drone/drone/plugin/condition"
"github.com/drone/drone/shared/build/buildfile"
)
const (
// Gommand to the current commit hash
CmdRevParse = "COMMIT=$(git rev-parse HEAD)"
// Command to set the git user and email based on the
// individual that made the commit.
CmdGlobalEmail = "git config --global user.email $(git --no-pager log -1 --pretty=format:'%ae')"
CmdGlobalUser = "git config --global user.name $(git --no-pager log -1 --pretty=format:'%an')"
)
// deploy:
// deis:
// app: safe-island-6261
// deisurl: deis.myurl.tdl:2222/
type Deis struct {
App string `yaml:"app,omitempty"`
Force bool `yaml:"force,omitempty"`
Deisurl string `yaml:"deisurl,omitempty"`
Condition *condition.Condition `yaml:"when,omitempty"`
}
func (h *Deis) Write(f *buildfile.Buildfile) {
f.WriteCmdSilent(CmdRevParse)
f.WriteCmdSilent(CmdGlobalUser)
f.WriteCmdSilent(CmdGlobalEmail)
// git@deis.yourdomain.com:2222/drone.git
f.WriteCmd(fmt.Sprintf("git remote add deis ssh://git@%s%s.git", h.Deisurl , h.App))
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 Deis.
f.WriteCmd(fmt.Sprintf("git add -A"))
f.WriteCmd(fmt.Sprintf("git commit -m 'adding build artifacts'"))
f.WriteCmd(fmt.Sprintf("git push deis HEAD:master --force"))
case false:
// otherwise we just do a standard git push
f.WriteCmd(fmt.Sprintf("git push deis $COMMIT:master"))
}
}
func (h *Deis) GetCondition() *condition.Condition {
return h.Condition
}

View file

@ -0,0 +1,68 @@
package deis
import (
"strings"
"testing"
"github.com/drone/drone/shared/build/buildfile"
"github.com/franela/goblin"
)
func Test_Deis(t *testing.T) {
g := goblin.Goblin(t)
g.Describe("Deis Deploy", func() {
g.It("Should set git.config", func() {
b := new(buildfile.Buildfile)
h := Deis{
App: "drone",
Deisurl: "deis.yourdomain.com:2222",
}
h.Write(b)
out := b.String()
g.Assert(strings.Contains(out, CmdRevParse)).Equal(true)
g.Assert(strings.Contains(out, CmdGlobalUser)).Equal(true)
g.Assert(strings.Contains(out, CmdGlobalEmail)).Equal(true)
})
g.It("Should add remote", func() {
b := new(buildfile.Buildfile)
h := Deis{
App: "drone",
Deisurl: "deis.yourdomain.com:2222/",
}
h.Write(b)
out := b.String()
g.Assert(strings.Contains(out, "\ngit remote add deis ssh://git@deis.yourdomain.com:2222/drone.git\n")).Equal(true)
})
g.It("Should push to remote", func() {
b := new(buildfile.Buildfile)
d := Deis{
App: "drone",
}
d.Write(b)
out := b.String()
g.Assert(strings.Contains(out, "\ngit push deis $COMMIT:master\n")).Equal(true)
})
g.It("Should force push to remote", func() {
b := new(buildfile.Buildfile)
h := Deis{
Force: true,
App: "drone",
}
h.Write(b)
out := b.String()
g.Assert(strings.Contains(out, "\ngit add -A\n")).Equal(true)
g.Assert(strings.Contains(out, "\ngit commit -m 'adding build artifacts'\n")).Equal(true)
g.Assert(strings.Contains(out, "\ngit push deis HEAD:master --force\n")).Equal(true)
})
})
}

View file

@ -7,6 +7,7 @@ import (
"github.com/drone/drone/plugin/deploy/git"
"github.com/drone/drone/plugin/deploy/heroku"
"github.com/drone/drone/plugin/deploy/deis"
"github.com/drone/drone/plugin/deploy/modulus"
"github.com/drone/drone/plugin/deploy/nodejitsu"
"github.com/drone/drone/plugin/deploy/tsuru"
@ -19,6 +20,7 @@ type Deploy struct {
CloudFoundry *CloudFoundry `yaml:"cloudfoundry,omitempty"`
Git *git.Git `yaml:"git,omitempty"`
Heroku *heroku.Heroku `yaml:"heroku,omitempty"`
Deis *deis.Deis `yaml:"deis,omitempty"`
Modulus *modulus.Modulus `yaml:"modulus,omitempty"`
Nodejitsu *nodejitsu.Nodejitsu `yaml:"nodejitsu,omitempty"`
SSH *SSH `yaml:"ssh,omitempty"`
@ -37,6 +39,9 @@ func (d *Deploy) Write(f *buildfile.Buildfile, r *repo.Repo) {
if d.Heroku != nil && match(d.Heroku.GetCondition(), r) {
d.Heroku.Write(f)
}
if d.Deis != nil && match(d.Deis.GetCondition(), r) {
d.Deis.Write(f)
}
if d.Modulus != nil && match(d.Modulus.GetCondition(), r) {
d.Modulus.Write(f)
}