mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-23 02:11:01 +00:00
support deploy to cloudfoundry
This commit is contained in:
parent
070caa3833
commit
3bf5135547
2 changed files with 116 additions and 2 deletions
|
@ -1,12 +1,37 @@
|
||||||
package deploy
|
package deploy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/drone/drone/pkg/build/buildfile"
|
"fmt"
|
||||||
|
"github.com/drone/drone/pkg/build/buildfile"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CloudFoundry struct {
|
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"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CloudFoundry) Write(f *buildfile.Buildfile) {
|
func (cf *CloudFoundry) Write(f *buildfile.Buildfile) {
|
||||||
|
// login
|
||||||
|
loginCmd := "cf login -a %s -u %s -p %s -o %s -s %s"
|
||||||
|
|
||||||
|
organization := cf.Org
|
||||||
|
if organization == "" {
|
||||||
|
organization = cf.Username
|
||||||
|
}
|
||||||
|
|
||||||
|
space := cf.Space
|
||||||
|
if space == "" {
|
||||||
|
space = "dev"
|
||||||
|
}
|
||||||
|
|
||||||
|
f.WriteCmdSilent(fmt.Sprintf(loginCmd, cf.Target, cf.Username, cf.Password, organization, space))
|
||||||
|
|
||||||
|
// push app
|
||||||
|
pushCmd := "cf push %s"
|
||||||
|
f.WriteCmd(fmt.Sprintf(pushCmd, cf.App))
|
||||||
}
|
}
|
||||||
|
|
89
pkg/plugin/deploy/cloudfoundry_test.go
Normal file
89
pkg/plugin/deploy/cloudfoundry_test.go
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
package deploy
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/drone/drone/pkg/build/buildfile"
|
||||||
|
|
||||||
|
"launchpad.net/goyaml"
|
||||||
|
)
|
||||||
|
|
||||||
|
// emulate Build struct
|
||||||
|
type DeployToCF struct {
|
||||||
|
Deploy *Deploy `yaml:"deploy,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
var sampleYmlBasic = `
|
||||||
|
deploy:
|
||||||
|
cloudfoundry:
|
||||||
|
target: https://api.example.com
|
||||||
|
username: foo
|
||||||
|
password: bar
|
||||||
|
`
|
||||||
|
|
||||||
|
var sampleYmlWithOrg = `
|
||||||
|
deploy:
|
||||||
|
cloudfoundry:
|
||||||
|
target: https://api.example.com
|
||||||
|
username: foo
|
||||||
|
password: bar
|
||||||
|
org: custom-org
|
||||||
|
`
|
||||||
|
|
||||||
|
var sampleYmlWithAppName = `
|
||||||
|
deploy:
|
||||||
|
cloudfoundry:
|
||||||
|
target: https://api.example.com
|
||||||
|
username: foo
|
||||||
|
password: bar
|
||||||
|
app: test-app
|
||||||
|
`
|
||||||
|
|
||||||
|
func setUpWithCF(input string) (string, error) {
|
||||||
|
var buildStruct DeployToCF
|
||||||
|
err := goyaml.Unmarshal([]byte(input), &buildStruct)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
bf := buildfile.New()
|
||||||
|
buildStruct.Deploy.Write(bf)
|
||||||
|
return bf.String(), err
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCloudFoundryDeployment(t *testing.T) {
|
||||||
|
bscr, err := setUpWithCF(sampleYmlBasic)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Can't unmarshal deploy script: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !strings.Contains(bscr, "cf login -a https://api.example.com -u foo -p bar -o foo -s dev") {
|
||||||
|
t.Error("Expect login script to contains default space")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !strings.Contains(bscr, "cf push") {
|
||||||
|
t.Error("Expect script to contains push")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCloudFoundryDeploymentWithOrg(t *testing.T) {
|
||||||
|
bscr, err := setUpWithCF(sampleYmlWithOrg)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Can't unmarshal deploy script: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !strings.Contains(bscr, "cf login -a https://api.example.com -u foo -p bar -o custom-org") {
|
||||||
|
t.Error("Expect login script to contains organization")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCloudFoundryDeploymentWithApp(t *testing.T) {
|
||||||
|
bscr, err := setUpWithCF(sampleYmlWithAppName)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Can't unmarshal deploy script: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !strings.Contains(bscr, "cf push test-app") {
|
||||||
|
t.Error("Expect login script to contains app name")
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue