Skip to content

Commit

Permalink
Merge pull request #56 from jmcarp/support-vars
Browse files Browse the repository at this point in the history
Support vars and vars-files.
  • Loading branch information
vito authored Aug 23, 2018
2 parents 71fecf8 + bdd8483 commit 32d7a1d
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 21 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ be specified.
that this will re-deploy over. If this is set the resource will perform a
zero-downtime deploy.
* `environment_variables`: *Optional.* It is not necessary to set the variables in [manifest][cf-manifests] if this parameter is set.
* `vars`: *Optional.* Map of variables to pass to manifest
* `vars_files`: *Optional.* List of variables files to pass to manifest
* `docker_username`: *Optional.* This is used as the username to authenticate against a protected docker registry.
* `docker_password`: *Optional.* This should be the users password when authenticating against a protected docker registry.
* `show_app_log`: *Optional.* Tails the app log during startup, useful to debug issues when using blue/green deploys together with the `current_app_name` option.
Expand Down
21 changes: 19 additions & 2 deletions out/cloud_foundry.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package out

import (
"fmt"
"os"
"os/exec"
)
Expand All @@ -9,7 +10,7 @@ import (
type PAAS interface {
Login(api string, username string, password string, clientID string, clientSecret string, insecure bool) error
Target(organization string, space string) error
PushApp(manifest string, path string, currentAppName string, dockerUser string, showLogs bool, noStart bool) error
PushApp(manifest string, path string, currentAppName string, vars map[string]interface{}, varsFiles []string, dockerUser string, showLogs bool, noStart bool) error
}

type CloudFoundry struct {
Expand Down Expand Up @@ -41,7 +42,15 @@ func (cf *CloudFoundry) Target(organization string, space string) error {
return cf.cf("target", "-o", organization, "-s", space).Run()
}

func (cf *CloudFoundry) PushApp(manifest string, path string, currentAppName string, dockerUser string, showLogs bool, noStart bool) error {
func (cf *CloudFoundry) PushApp(
manifest string,
path string, currentAppName string,
vars map[string]interface{},
varsFiles []string,
dockerUser string,
showLogs bool,
noStart bool,
) error {
args := []string{}

if currentAppName == "" {
Expand All @@ -56,6 +65,14 @@ func (cf *CloudFoundry) PushApp(manifest string, path string, currentAppName str
}
}

for name, value := range vars {
args = append(args, "--var", fmt.Sprintf("%s=%s", name, value))
}

for _, varsFile := range varsFiles {
args = append(args, "--vars-file", varsFile)
}

if dockerUser != "" {
args = append(args, "--docker-username", dockerUser)
}
Expand Down
2 changes: 2 additions & 0 deletions out/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ func (command *Command) Run(request Request) (Response, error) {
request.Params.ManifestPath,
request.Params.Path,
request.Params.CurrentAppName,
request.Params.Vars,
request.Params.VarsFiles,
request.Params.DockerUsername,
request.Params.ShowAppLog,
request.Params.NoStart,
Expand Down
12 changes: 8 additions & 4 deletions out/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ var _ = Describe("Out Command", func() {
},
Params: out.Params{
ManifestPath: "assets/manifest.yml",
Vars: map[string]interface{}{"foo": "bar"},
VarsFiles: []string{"vars.yml"},
},
}
})
Expand Down Expand Up @@ -81,10 +83,12 @@ var _ = Describe("Out Command", func() {
By("pushing the app")
Expect(cloudFoundry.PushAppCallCount()).To(Equal(1))

manifest, path, currentAppName, dockerUser, showAppLog, noStart := cloudFoundry.PushAppArgsForCall(0)
manifest, path, currentAppName, vars, varsFiles, dockerUser, showAppLog, noStart := cloudFoundry.PushAppArgsForCall(0)
Expect(manifest).To(Equal(request.Params.ManifestPath))
Expect(path).To(Equal(""))
Expect(currentAppName).To(Equal(""))
Expect(vars).To(Equal(map[string]interface{}{"foo": "bar"}))
Expect(varsFiles).To(Equal([]string{"vars.yml"}))
Expect(dockerUser).To(Equal(""))
Expect(showAppLog).To(Equal(false))
Expect(noStart).To(Equal(false))
Expand Down Expand Up @@ -129,7 +133,7 @@ var _ = Describe("Out Command", func() {
_, err := command.Run(request)
Expect(err).NotTo(HaveOccurred())

_, _, _, _, _, noStart := cloudFoundry.PushAppArgsForCall(0)
_, _, _, _, _, _, _, noStart := cloudFoundry.PushAppArgsForCall(0)
Expect(noStart).To(Equal(true))
})
})
Expand Down Expand Up @@ -272,7 +276,7 @@ var _ = Describe("Out Command", func() {
By("pushing the app")
Expect(cloudFoundry.PushAppCallCount()).To(Equal(1))

_, _, currentAppName, _, _, _ := cloudFoundry.PushAppArgsForCall(0)
_, _, currentAppName, _, _, _, _, _ := cloudFoundry.PushAppArgsForCall(0)
Expect(currentAppName).To(Equal("cool-app-name"))
})

Expand All @@ -298,7 +302,7 @@ var _ = Describe("Out Command", func() {
By("pushing the app")
Expect(cloudFoundry.PushAppCallCount()).To(Equal(1))

_, _, _, dockerUser, _, _ := cloudFoundry.PushAppArgsForCall(0)
_, _, _, _, _, dockerUser, _, _ := cloudFoundry.PushAppArgsForCall(0)
Expect(dockerUser).To(Equal("DOCKER_USER"))
})

Expand Down
37 changes: 37 additions & 0 deletions out/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,43 @@ var _ = Describe("Out", func() {
})
})

Context("when specifying vars", func() {
BeforeEach(func() {
request.Params.Vars = map[string]interface{}{"foo": "bar"}
request.Params.VarsFiles = []string{"vars.yml"}
})

It("pushes an application to cloud foundry", func() {
session, err := gexec.Start(
cmd,
GinkgoWriter,
GinkgoWriter,
)
Expect(err).NotTo(HaveOccurred())

Eventually(session).Should(gexec.Exit(0))

var response out.Response
err = json.Unmarshal(session.Out.Contents(), &response)
Expect(err).NotTo(HaveOccurred())

Expect(response.Version.Timestamp).To(BeTemporally("~", time.Now(), time.Second))

// shim outputs arguments
Expect(session.Err).To(gbytes.Say("cf api https://api.run.pivotal.io --skip-ssl-validation"))
Expect(session.Err).To(gbytes.Say("cf auth [email protected] hunter2"))
Expect(session.Err).To(gbytes.Say("cf target -o org -s space"))
Expect(session.Err).To(gbytes.Say("cf zero-downtime-push awesome-app -f %s --var foo=bar --vars-file vars.yml",
filepath.Join(tmpDir, "project/manifest.yml"),
))
Expect(session.Err).To(gbytes.Say(filepath.Join(tmpDir, "another-project")))

// color should be always
Eventually(session.Err).Should(gbytes.Say("CF_COLOR=true"))
Eventually(session.Err).Should(gbytes.Say("CF_TRACE=/dev/stderr"))
})
})

Context("when my manifest and file paths contain a glob", func() {
var tmpFileManifest *os.File
var tmpFileSearch *os.File
Expand Down
18 changes: 10 additions & 8 deletions out/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ type Request struct {
}

type Params struct {
ManifestPath string `json:"manifest"`
Path string `json:"path"`
CurrentAppName string `json:"current_app_name"`
EnvironmentVariables map[string]string `json:"environment_variables"`
DockerUsername string `json:"docker_username"`
DockerPassword string `json:"docker_password"`
ShowAppLog bool `json:"show_app_log"`
NoStart bool `json:"no_start"`
ManifestPath string `json:"manifest"`
Path string `json:"path"`
CurrentAppName string `json:"current_app_name"`
Vars map[string]interface{} `json:"vars"`
VarsFiles []string `json:"vars_files"`
EnvironmentVariables map[string]string `json:"environment_variables"`
DockerUsername string `json:"docker_username"`
DockerPassword string `json:"docker_password"`
ShowAppLog bool `json:"show_app_log"`
NoStart bool `json:"no_start"`
}

type Response struct {
Expand Down
23 changes: 16 additions & 7 deletions out/outfakes/fake_paas.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 32d7a1d

Please sign in to comment.