mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-01-11 17:18:09 +02:00
Merge pull request #535 from bradrydzewski/master
working on unit tests for Deploy plugins + misc
This commit is contained in:
commit
12757476d8
@ -1,5 +1,6 @@
|
|||||||
[![Build Status](http://test.drone.io/v1/badge/github.com/drone/drone/status.svg)](http://test.drone.io/github.com/drone/drone)
|
[![Build Status](http://test.drone.io/v1/badge/github.com/drone/drone/status.svg)](http://test.drone.io/github.com/drone/drone)
|
||||||
[![GoDoc](https://godoc.org/github.com/drone/drone?status.png)](https://godoc.org/github.com/drone/drone)
|
[![GoDoc](https://godoc.org/github.com/drone/drone?status.png)](https://godoc.org/github.com/drone/drone)
|
||||||
|
[![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/drone/drone?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||||
|
|
||||||
## System Requirements
|
## System Requirements
|
||||||
|
|
||||||
@ -29,7 +30,7 @@ described in the **Setup** section.
|
|||||||
|
|
||||||
Below are some example configurations that you can use as reference:
|
Below are some example configurations that you can use as reference:
|
||||||
|
|
||||||
```
|
```toml
|
||||||
# to use postgres
|
# to use postgres
|
||||||
[database]
|
[database]
|
||||||
driver="postgres"
|
driver="postgres"
|
||||||
@ -39,7 +40,6 @@ datasource="host=127.0.0.1 user=postgres dbname=drone sslmode=disable"
|
|||||||
[database]
|
[database]
|
||||||
driver="mysql"
|
driver="mysql"
|
||||||
datasource="root@tcp(127.0.0.1:3306)/drone"
|
datasource="root@tcp(127.0.0.1:3306)/drone"
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Setup
|
## Setup
|
||||||
@ -64,6 +64,10 @@ port=""
|
|||||||
key=""
|
key=""
|
||||||
cert=""
|
cert=""
|
||||||
|
|
||||||
|
[session]
|
||||||
|
secret=""
|
||||||
|
duration=""
|
||||||
|
|
||||||
[database]
|
[database]
|
||||||
driver=""
|
driver=""
|
||||||
datasource=""
|
datasource=""
|
||||||
|
8
debian/drone/etc/drone/drone.toml
vendored
8
debian/drone/etc/drone/drone.toml
vendored
@ -3,16 +3,18 @@
|
|||||||
port=":80"
|
port=":80"
|
||||||
|
|
||||||
#####################################################################
|
#####################################################################
|
||||||
# SSL configuration for Drone. Provide you key and cert chain
|
# SSL configuration
|
||||||
# to server Drone over https.
|
|
||||||
#
|
#
|
||||||
# [server.ssl]
|
# [server.ssl]
|
||||||
# key=""
|
# key=""
|
||||||
# cert=""
|
# cert=""
|
||||||
|
|
||||||
|
# [session]
|
||||||
|
# secret=""
|
||||||
|
# duration=""
|
||||||
|
|
||||||
#####################################################################
|
#####################################################################
|
||||||
# Database configuration for Drone, by default using SQLite3.
|
# Database configuration, by default using SQLite3.
|
||||||
# You can also use postgres and mysql. See the documentation
|
# You can also use postgres and mysql. See the documentation
|
||||||
# for more details.
|
# for more details.
|
||||||
|
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
package deploy
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/drone/drone/shared/build/buildfile"
|
|
||||||
)
|
|
||||||
|
|
||||||
type AppFog struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *AppFog) Write(f *buildfile.Buildfile) {
|
|
||||||
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
package deploy
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/drone/drone/shared/build/buildfile"
|
|
||||||
)
|
|
||||||
|
|
||||||
type CloudControl struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *CloudControl) Write(f *buildfile.Buildfile) {
|
|
||||||
|
|
||||||
}
|
|
51
plugin/deploy/cloudfoundry/cloudfoundry.go
Normal file
51
plugin/deploy/cloudfoundry/cloudfoundry.go
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
package cloudfoundry
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/drone/drone/plugin/condition"
|
||||||
|
"github.com/drone/drone/shared/build/buildfile"
|
||||||
|
)
|
||||||
|
|
||||||
|
type CloudFoundry struct {
|
||||||
|
Target string `yaml:"target,omitempty"`
|
||||||
|
Username string `yaml:"username,omitempty"`
|
||||||
|
Password string `yaml:"password,omitempty"`
|
||||||
|
Org string `yaml:"org,omitempty"`
|
||||||
|
Space string `yaml:"space,omitempty"`
|
||||||
|
|
||||||
|
App string `yaml:"app,omitempty"`
|
||||||
|
|
||||||
|
Condition *condition.Condition `yaml:"when,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cf *CloudFoundry) Write(f *buildfile.Buildfile) {
|
||||||
|
downloadCmd := "curl -sLO http://go-cli.s3-website-us-east-1.amazonaws.com/releases/latest/cf-cli_amd64.deb"
|
||||||
|
installCmd := "dpkg -i cf-cli_amd64.deb 1> /dev/null 2> /dev/null"
|
||||||
|
|
||||||
|
// download and install the cf tool
|
||||||
|
f.WriteCmdSilent(fmt.Sprintf("[ -f /usr/bin/sudo ] && sudo %s || %s", downloadCmd, downloadCmd))
|
||||||
|
f.WriteCmdSilent(fmt.Sprintf("[ -f /usr/bin/sudo ] && sudo %s || %s", installCmd, installCmd))
|
||||||
|
|
||||||
|
// login
|
||||||
|
loginCmd := "cf login -a %s -u %s -p %s"
|
||||||
|
|
||||||
|
organization := cf.Org
|
||||||
|
if organization != "" {
|
||||||
|
loginCmd += fmt.Sprintf(" -o %s", organization)
|
||||||
|
}
|
||||||
|
|
||||||
|
space := cf.Space
|
||||||
|
if space != "" {
|
||||||
|
loginCmd += fmt.Sprintf(" -s %s", space)
|
||||||
|
}
|
||||||
|
|
||||||
|
f.WriteCmdSilent(fmt.Sprintf(loginCmd, cf.Target, cf.Username, cf.Password))
|
||||||
|
|
||||||
|
// push app
|
||||||
|
pushCmd := "cf push %s"
|
||||||
|
f.WriteCmd(fmt.Sprintf(pushCmd, cf.App))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cf *CloudFoundry) GetCondition() *condition.Condition {
|
||||||
|
return cf.Condition
|
||||||
|
}
|
@ -4,24 +4,26 @@ import (
|
|||||||
"github.com/drone/drone/plugin/condition"
|
"github.com/drone/drone/plugin/condition"
|
||||||
"github.com/drone/drone/shared/build/buildfile"
|
"github.com/drone/drone/shared/build/buildfile"
|
||||||
"github.com/drone/drone/shared/build/repo"
|
"github.com/drone/drone/shared/build/repo"
|
||||||
|
|
||||||
|
"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"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Deploy stores the configuration details
|
// Deploy stores the configuration details
|
||||||
// for deploying build artifacts when
|
// for deploying build artifacts when
|
||||||
// a Build has succeeded
|
// a Build has succeeded
|
||||||
type Deploy struct {
|
type Deploy struct {
|
||||||
AppFog *AppFog `yaml:"appfog,omitempty"`
|
CloudFoundry *CloudFoundry `yaml:"cloudfoundry,omitempty"`
|
||||||
CloudControl *CloudControl `yaml:"cloudcontrol,omitempty"`
|
Git *git.Git `yaml:"git,omitempty"`
|
||||||
CloudFoundry *CloudFoundry `yaml:"cloudfoundry,omitempty"`
|
Heroku *heroku.Heroku `yaml:"heroku,omitempty"`
|
||||||
EngineYard *EngineYard `yaml:"engineyard,omitempty"`
|
Modulus *modulus.Modulus `yaml:"modulus,omitempty"`
|
||||||
Git *Git `yaml:"git,omitempty"`
|
Nodejitsu *nodejitsu.Nodejitsu `yaml:"nodejitsu,omitempty"`
|
||||||
Heroku *Heroku `yaml:"heroku,omitempty"`
|
SSH *SSH `yaml:"ssh,omitempty"`
|
||||||
Modulus *Modulus `yaml:"modulus,omitempty"`
|
Tsuru *tsuru.Tsuru `yaml:"tsuru,omitempty"`
|
||||||
Nodejitsu *Nodejitsu `yaml:"nodejitsu,omitempty"`
|
Bash *Bash `yaml:"bash,omitempty"`
|
||||||
Openshift *Openshift `yaml:"openshift,omitempty"`
|
|
||||||
SSH *SSH `yaml:"ssh,omitempty"`
|
|
||||||
Tsuru *Tsuru `yaml:"tsuru,omitempty"`
|
|
||||||
Bash *Bash `yaml:"bash,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Deploy) Write(f *buildfile.Buildfile, r *repo.Repo) {
|
func (d *Deploy) Write(f *buildfile.Buildfile, r *repo.Repo) {
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
package deploy
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/drone/drone/shared/build/buildfile"
|
|
||||||
)
|
|
||||||
|
|
||||||
type EngineYard struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *EngineYard) Write(f *buildfile.Buildfile) {
|
|
||||||
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
package deploy
|
package git
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -6,6 +6,16 @@ import (
|
|||||||
"github.com/drone/drone/shared/build/buildfile"
|
"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')"
|
||||||
|
)
|
||||||
|
|
||||||
type Git struct {
|
type Git struct {
|
||||||
Target string `yaml:"target,omitempty"`
|
Target string `yaml:"target,omitempty"`
|
||||||
Force bool `yaml:"force,omitempty"`
|
Force bool `yaml:"force,omitempty"`
|
||||||
@ -15,20 +25,16 @@ type Git struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *Git) Write(f *buildfile.Buildfile) {
|
func (g *Git) Write(f *buildfile.Buildfile) {
|
||||||
// get the current commit hash
|
f.WriteCmdSilent(CmdRevParse)
|
||||||
f.WriteCmdSilent("COMMIT=$(git rev-parse HEAD)")
|
f.WriteCmdSilent(CmdGlobalUser)
|
||||||
|
f.WriteCmdSilent(CmdGlobalEmail)
|
||||||
// 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 target as a git remote
|
// add target as a git remote
|
||||||
f.WriteCmd(fmt.Sprintf("git remote add deploy %s", g.Target))
|
f.WriteCmd(fmt.Sprintf("git remote add deploy %s", g.Target))
|
||||||
|
|
||||||
destinationBranch := g.Branch
|
dest := g.Branch
|
||||||
if destinationBranch == "" {
|
if len(dest) == 0 {
|
||||||
destinationBranch = "master"
|
dest = "master"
|
||||||
}
|
}
|
||||||
|
|
||||||
switch g.Force {
|
switch g.Force {
|
||||||
@ -38,10 +44,10 @@ func (g *Git) Write(f *buildfile.Buildfile) {
|
|||||||
// that need to be deployed to git remote.
|
// that need to be deployed to git remote.
|
||||||
f.WriteCmd(fmt.Sprintf("git add -A"))
|
f.WriteCmd(fmt.Sprintf("git add -A"))
|
||||||
f.WriteCmd(fmt.Sprintf("git commit -m 'add build artifacts'"))
|
f.WriteCmd(fmt.Sprintf("git commit -m 'add build artifacts'"))
|
||||||
f.WriteCmd(fmt.Sprintf("git push deploy HEAD:%s --force", destinationBranch))
|
f.WriteCmd(fmt.Sprintf("git push deploy HEAD:%s --force", dest))
|
||||||
case false:
|
case false:
|
||||||
// otherwise we just do a standard git push
|
// otherwise we just do a standard git push
|
||||||
f.WriteCmd(fmt.Sprintf("git push deploy $COMMIT:%s", destinationBranch))
|
f.WriteCmd(fmt.Sprintf("git push deploy $COMMIT:%s", dest))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
78
plugin/deploy/git/git_test.go
Normal file
78
plugin/deploy/git/git_test.go
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
package git
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/drone/drone/shared/build/buildfile"
|
||||||
|
"github.com/franela/goblin"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_Git(t *testing.T) {
|
||||||
|
|
||||||
|
g := goblin.Goblin(t)
|
||||||
|
g.Describe("Git Deploy", func() {
|
||||||
|
|
||||||
|
g.It("Should set git.config", func() {
|
||||||
|
b := new(buildfile.Buildfile)
|
||||||
|
d := Git{
|
||||||
|
Target: "git://foo.com/bar/baz.git",
|
||||||
|
}
|
||||||
|
|
||||||
|
d.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)
|
||||||
|
d := Git{
|
||||||
|
Target: "git://foo.com/bar/baz.git",
|
||||||
|
}
|
||||||
|
|
||||||
|
d.Write(b)
|
||||||
|
out := b.String()
|
||||||
|
g.Assert(strings.Contains(out, "\ngit remote add deploy git://foo.com/bar/baz.git\n")).Equal(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
g.It("Should push to remote", func() {
|
||||||
|
b := new(buildfile.Buildfile)
|
||||||
|
d := Git{
|
||||||
|
Target: "git://foo.com/bar/baz.git",
|
||||||
|
}
|
||||||
|
|
||||||
|
d.Write(b)
|
||||||
|
out := b.String()
|
||||||
|
g.Assert(strings.Contains(out, "\ngit push deploy $COMMIT:master\n")).Equal(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
g.It("Should push to alternate branch", func() {
|
||||||
|
b := new(buildfile.Buildfile)
|
||||||
|
d := Git{
|
||||||
|
Branch: "foo",
|
||||||
|
Target: "git://foo.com/bar/baz.git",
|
||||||
|
}
|
||||||
|
|
||||||
|
d.Write(b)
|
||||||
|
out := b.String()
|
||||||
|
g.Assert(strings.Contains(out, "\ngit push deploy $COMMIT:foo\n")).Equal(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
g.It("Should force push to remote", func() {
|
||||||
|
b := new(buildfile.Buildfile)
|
||||||
|
d := Git{
|
||||||
|
Force: true,
|
||||||
|
Target: "git://foo.com/bar/baz.git",
|
||||||
|
}
|
||||||
|
|
||||||
|
d.Write(b)
|
||||||
|
out := b.String()
|
||||||
|
g.Assert(strings.Contains(out, "\ngit add -A\n")).Equal(true)
|
||||||
|
g.Assert(strings.Contains(out, "\ngit commit -m 'add build artifacts'\n")).Equal(true)
|
||||||
|
g.Assert(strings.Contains(out, "\ngit push deploy HEAD:master --force\n")).Equal(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package deploy
|
package heroku
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -6,22 +6,27 @@ import (
|
|||||||
"github.com/drone/drone/shared/build/buildfile"
|
"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')"
|
||||||
|
)
|
||||||
|
|
||||||
type Heroku struct {
|
type Heroku struct {
|
||||||
App string `yaml:"app,omitempty"`
|
App string `yaml:"app,omitempty"`
|
||||||
Force bool `yaml:"force,omitempty"`
|
Force bool `yaml:"force,omitempty"`
|
||||||
Branch string `yaml:"branch,omitempty"`
|
|
||||||
|
|
||||||
Condition *condition.Condition `yaml:"when,omitempty"`
|
Condition *condition.Condition `yaml:"when,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Heroku) Write(f *buildfile.Buildfile) {
|
func (h *Heroku) Write(f *buildfile.Buildfile) {
|
||||||
// get the current commit hash
|
f.WriteCmdSilent(CmdRevParse)
|
||||||
f.WriteCmdSilent("COMMIT=$(git rev-parse HEAD)")
|
f.WriteCmdSilent(CmdGlobalUser)
|
||||||
|
f.WriteCmdSilent(CmdGlobalEmail)
|
||||||
// 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 heroku as a git remote
|
// add heroku as a git remote
|
||||||
f.WriteCmd(fmt.Sprintf("git remote add heroku git@heroku.com:%s.git", h.App))
|
f.WriteCmd(fmt.Sprintf("git remote add heroku git@heroku.com:%s.git", h.App))
|
66
plugin/deploy/heroku/heroku_test.go
Normal file
66
plugin/deploy/heroku/heroku_test.go
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
package heroku
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/drone/drone/shared/build/buildfile"
|
||||||
|
"github.com/franela/goblin"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_Heroku(t *testing.T) {
|
||||||
|
|
||||||
|
g := goblin.Goblin(t)
|
||||||
|
g.Describe("Heroku Deploy", func() {
|
||||||
|
|
||||||
|
g.It("Should set git.config", func() {
|
||||||
|
b := new(buildfile.Buildfile)
|
||||||
|
h := Heroku{
|
||||||
|
App: "drone",
|
||||||
|
}
|
||||||
|
|
||||||
|
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 := Heroku{
|
||||||
|
App: "drone",
|
||||||
|
}
|
||||||
|
|
||||||
|
h.Write(b)
|
||||||
|
out := b.String()
|
||||||
|
g.Assert(strings.Contains(out, "\ngit remote add heroku git@heroku.com:drone.git\n")).Equal(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
g.It("Should push to remote", func() {
|
||||||
|
b := new(buildfile.Buildfile)
|
||||||
|
d := Heroku{
|
||||||
|
App: "drone",
|
||||||
|
}
|
||||||
|
|
||||||
|
d.Write(b)
|
||||||
|
out := b.String()
|
||||||
|
g.Assert(strings.Contains(out, "\ngit push heroku $COMMIT:master\n")).Equal(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
g.It("Should force push to remote", func() {
|
||||||
|
b := new(buildfile.Buildfile)
|
||||||
|
h := Heroku{
|
||||||
|
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 heroku HEAD:master --force\n")).Equal(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package deploy
|
package modulus
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -14,13 +14,21 @@ type Modulus struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *Modulus) Write(f *buildfile.Buildfile) {
|
func (m *Modulus) Write(f *buildfile.Buildfile) {
|
||||||
|
if len(m.Token) == 0 || len(m.Project) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
f.WriteEnv("MODULUS_TOKEN", m.Token)
|
f.WriteEnv("MODULUS_TOKEN", m.Token)
|
||||||
|
|
||||||
|
// Verify npm exists, otherwise we cannot install the
|
||||||
|
// modulus command line utility.
|
||||||
|
f.WriteCmdSilent("[ -f /usr/bin/npm ] || echo ERROR: npm is required for modulus.io deployments")
|
||||||
|
f.WriteCmdSilent("[ -f /usr/bin/npm ] || exit 1")
|
||||||
|
|
||||||
// Install the Modulus command line interface then deploy the configured
|
// Install the Modulus command line interface then deploy the configured
|
||||||
// project.
|
// project.
|
||||||
f.WriteCmdSilent("[ -f /usr/bin/sudo ] || npm install -g modulus")
|
f.WriteCmdSilent("[ -f /usr/bin/sudo ] || npm install -g modulus")
|
||||||
f.WriteCmdSilent("[ -f /usr/bin/sudo ] && sudo npm install -g modulus")
|
f.WriteCmdSilent("[ -f /usr/bin/sudo ] && sudo npm install -g modulus")
|
||||||
f.WriteCmd(fmt.Sprintf("modulus deploy -p '%s'", m.Project))
|
f.WriteCmd(fmt.Sprintf("modulus deploy -p %q", m.Project))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Modulus) GetCondition() *condition.Condition {
|
func (m *Modulus) GetCondition() *condition.Condition {
|
53
plugin/deploy/modulus/modulus_test.go
Normal file
53
plugin/deploy/modulus/modulus_test.go
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
package modulus
|
||||||
|
|
||||||
|
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("Modulus Deploy", func() {
|
||||||
|
|
||||||
|
g.It("Requires a Project name", func() {
|
||||||
|
b := new(buildfile.Buildfile)
|
||||||
|
m := Modulus{
|
||||||
|
Project: "foo",
|
||||||
|
}
|
||||||
|
|
||||||
|
m.Write(b)
|
||||||
|
g.Assert(b.String()).Equal("")
|
||||||
|
})
|
||||||
|
|
||||||
|
g.It("Requires a Token", func() {
|
||||||
|
b := new(buildfile.Buildfile)
|
||||||
|
m := Modulus{
|
||||||
|
Token: "bar",
|
||||||
|
}
|
||||||
|
|
||||||
|
m.Write(b)
|
||||||
|
g.Assert(b.String()).Equal("")
|
||||||
|
})
|
||||||
|
|
||||||
|
g.It("Should execute deploy commands", func() {
|
||||||
|
b := new(buildfile.Buildfile)
|
||||||
|
m := Modulus{
|
||||||
|
Project: "foo",
|
||||||
|
Token: "bar",
|
||||||
|
}
|
||||||
|
|
||||||
|
m.Write(b)
|
||||||
|
g.Assert(b.String()).Equal(`export MODULUS_TOKEN=bar
|
||||||
|
[ -f /usr/bin/npm ] || echo ERROR: npm is required for modulus.io deployments
|
||||||
|
[ -f /usr/bin/npm ] || exit 1
|
||||||
|
[ -f /usr/bin/sudo ] || npm install -g modulus
|
||||||
|
[ -f /usr/bin/sudo ] && sudo npm install -g modulus
|
||||||
|
echo '#DRONE:6d6f64756c7573206465706c6f79202d702022666f6f22'
|
||||||
|
modulus deploy -p "foo"
|
||||||
|
`)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package deploy
|
package nodejitsu
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/drone/drone/plugin/condition"
|
"github.com/drone/drone/plugin/condition"
|
||||||
@ -6,7 +6,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Nodejitsu struct {
|
type Nodejitsu struct {
|
||||||
App string `yaml:"app,omitempty"`
|
|
||||||
User string `yaml:"user,omitempty"`
|
User string `yaml:"user,omitempty"`
|
||||||
Token string `yaml:"token,omitempty"`
|
Token string `yaml:"token,omitempty"`
|
||||||
|
|
||||||
@ -14,6 +13,10 @@ type Nodejitsu struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (n *Nodejitsu) Write(f *buildfile.Buildfile) {
|
func (n *Nodejitsu) Write(f *buildfile.Buildfile) {
|
||||||
|
if len(n.Token) == 0 || len(n.User) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
f.WriteEnv("username", n.User)
|
f.WriteEnv("username", n.User)
|
||||||
f.WriteEnv("apiToken", n.Token)
|
f.WriteEnv("apiToken", n.Token)
|
||||||
|
|
52
plugin/deploy/nodejitsu/nodejitsu_test.go
Normal file
52
plugin/deploy/nodejitsu/nodejitsu_test.go
Normal file
@ -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
|
||||||
|
`)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
@ -1,12 +0,0 @@
|
|||||||
package deploy
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/drone/drone/shared/build/buildfile"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Openshift struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (o *Openshift) Write(f *buildfile.Buildfile) {
|
|
||||||
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
package deploy
|
package tsuru
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -6,22 +6,27 @@ import (
|
|||||||
"github.com/drone/drone/shared/build/buildfile"
|
"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')"
|
||||||
|
)
|
||||||
|
|
||||||
type Tsuru struct {
|
type Tsuru struct {
|
||||||
Force bool `yaml:"force,omitempty"`
|
Force bool `yaml:"force,omitempty"`
|
||||||
Branch string `yaml:"branch,omitempty"`
|
|
||||||
Remote string `yaml:"remote,omitempty"`
|
Remote string `yaml:"remote,omitempty"`
|
||||||
|
|
||||||
Condition *condition.Condition `yaml:"when,omitempty"`
|
Condition *condition.Condition `yaml:"when,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Tsuru) Write(f *buildfile.Buildfile) {
|
func (t *Tsuru) Write(f *buildfile.Buildfile) {
|
||||||
// get the current commit hash
|
f.WriteCmdSilent(CmdRevParse)
|
||||||
f.WriteCmdSilent("COMMIT=$(git rev-parse HEAD)")
|
f.WriteCmdSilent(CmdGlobalUser)
|
||||||
|
f.WriteCmdSilent(CmdGlobalEmail)
|
||||||
// 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
|
// add tsuru as a git remote
|
||||||
f.WriteCmd(fmt.Sprintf("git remote add tsuru %s", t.Remote))
|
f.WriteCmd(fmt.Sprintf("git remote add tsuru %s", t.Remote))
|
66
plugin/deploy/tsuru/tsuru_test.go
Normal file
66
plugin/deploy/tsuru/tsuru_test.go
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
package tsuru
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/drone/drone/shared/build/buildfile"
|
||||||
|
"github.com/franela/goblin"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_Tsuru(t *testing.T) {
|
||||||
|
|
||||||
|
g := goblin.Goblin(t)
|
||||||
|
g.Describe("Tsuru Deploy", func() {
|
||||||
|
|
||||||
|
g.It("Should set git.config", func() {
|
||||||
|
b := new(buildfile.Buildfile)
|
||||||
|
d := Tsuru{
|
||||||
|
Remote: "git://foo.com/bar/baz.git",
|
||||||
|
}
|
||||||
|
|
||||||
|
d.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)
|
||||||
|
d := Tsuru{
|
||||||
|
Remote: "git://foo.com/bar/baz.git",
|
||||||
|
}
|
||||||
|
|
||||||
|
d.Write(b)
|
||||||
|
out := b.String()
|
||||||
|
g.Assert(strings.Contains(out, "\ngit remote add tsuru git://foo.com/bar/baz.git\n")).Equal(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
g.It("Should push to remote", func() {
|
||||||
|
b := new(buildfile.Buildfile)
|
||||||
|
d := Tsuru{
|
||||||
|
Remote: "git://foo.com/bar/baz.git",
|
||||||
|
}
|
||||||
|
|
||||||
|
d.Write(b)
|
||||||
|
out := b.String()
|
||||||
|
g.Assert(strings.Contains(out, "\ngit push tsuru $COMMIT:master\n")).Equal(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
g.It("Should force push to remote", func() {
|
||||||
|
b := new(buildfile.Buildfile)
|
||||||
|
d := Tsuru{
|
||||||
|
Force: true,
|
||||||
|
Remote: "git://foo.com/bar/baz.git",
|
||||||
|
}
|
||||||
|
|
||||||
|
d.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 tsuru HEAD:master --force\n")).Equal(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
@ -36,19 +36,6 @@ func Test_NPM(t *testing.T) {
|
|||||||
g.Assert(strings.Contains(out, "\nnpm config set")).Equal(false)
|
g.Assert(strings.Contains(out, "\nnpm config set")).Equal(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
/*
|
|
||||||
n := NPM{
|
|
||||||
Email: "foo@bar.com",
|
|
||||||
Username: "foo",
|
|
||||||
Password: "bar",
|
|
||||||
Force: true,
|
|
||||||
Registry: "",
|
|
||||||
Folder: "/path/to/repo",
|
|
||||||
Tag: "1.0.0",
|
|
||||||
AlwaysAuth: false,
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
g.It("Should set force", func() {
|
g.It("Should set force", func() {
|
||||||
b := new(buildfile.Buildfile)
|
b := new(buildfile.Buildfile)
|
||||||
n := NPM{
|
n := NPM{
|
||||||
|
@ -7,14 +7,21 @@ import (
|
|||||||
|
|
||||||
"code.google.com/p/go.net/context"
|
"code.google.com/p/go.net/context"
|
||||||
"github.com/dgrijalva/jwt-go"
|
"github.com/dgrijalva/jwt-go"
|
||||||
|
"github.com/drone/config"
|
||||||
"github.com/drone/drone/server/datastore"
|
"github.com/drone/drone/server/datastore"
|
||||||
"github.com/drone/drone/shared/httputil"
|
"github.com/drone/drone/shared/httputil"
|
||||||
"github.com/drone/drone/shared/model"
|
"github.com/drone/drone/shared/model"
|
||||||
"github.com/gorilla/securecookie"
|
"github.com/gorilla/securecookie"
|
||||||
)
|
)
|
||||||
|
|
||||||
// secret key used to create jwt
|
// random key used to create jwt if none
|
||||||
var secret = securecookie.GenerateRandomKey(32)
|
// provided in the configuration.
|
||||||
|
var random = securecookie.GenerateRandomKey(32)
|
||||||
|
|
||||||
|
var (
|
||||||
|
secret = config.String("session-secret", string(random))
|
||||||
|
expires = config.Duration("session-expires", time.Hour*72)
|
||||||
|
)
|
||||||
|
|
||||||
// GetUser gets the currently authenticated user for the
|
// GetUser gets the currently authenticated user for the
|
||||||
// http.Request. The user details will be stored as either
|
// http.Request. The user details will be stored as either
|
||||||
@ -38,7 +45,7 @@ func GenerateToken(c context.Context, r *http.Request, user *model.User) (string
|
|||||||
token.Claims["user_id"] = user.ID
|
token.Claims["user_id"] = user.ID
|
||||||
token.Claims["audience"] = httputil.GetURL(r)
|
token.Claims["audience"] = httputil.GetURL(r)
|
||||||
token.Claims["expires"] = time.Now().UTC().Add(time.Hour * 72).Unix()
|
token.Claims["expires"] = time.Now().UTC().Add(time.Hour * 72).Unix()
|
||||||
return token.SignedString(secret)
|
return token.SignedString([]byte(*secret))
|
||||||
}
|
}
|
||||||
|
|
||||||
// getUserToken gets the currently authenticated user for the given
|
// getUserToken gets the currently authenticated user for the given
|
||||||
@ -56,7 +63,7 @@ func getUserBearer(c context.Context, r *http.Request) *model.User {
|
|||||||
fmt.Sscanf(tokenstr, "Bearer %s", &tokenstr)
|
fmt.Sscanf(tokenstr, "Bearer %s", &tokenstr)
|
||||||
|
|
||||||
var token, err = jwt.Parse(tokenstr, func(t *jwt.Token) (interface{}, error) {
|
var token, err = jwt.Parse(tokenstr, func(t *jwt.Token) (interface{}, error) {
|
||||||
return secret, nil
|
return []byte(*secret), nil
|
||||||
})
|
})
|
||||||
if err != nil || !token.Valid {
|
if err != nil || !token.Valid {
|
||||||
println("invalid token")
|
println("invalid token")
|
||||||
|
Loading…
Reference in New Issue
Block a user