Skip to content

Commit

Permalink
add syslog_url from app.yaml (#543)
Browse files Browse the repository at this point in the history
right now in the cli the only way to set syslog url is via update or create
with the --syslog-url flag. this adds support in deploy when syslog_url is
present in app.yaml
  • Loading branch information
rdallman authored Feb 27, 2019
1 parent cff3ab6 commit 179030f
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 17 deletions.
31 changes: 16 additions & 15 deletions commands/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,31 +145,32 @@ func (p *deploycmd) deploy(c *cli.Context) error {
return errors.New("App name must be provided, try `--app APP_NAME`")
}

// appfApp is used to create/update app, with app file additions if provided
appfApp := models.App{
Name: appName,
}
if appf != nil {
// set other fields from app file
appfApp.Config = appf.Config
appfApp.Annotations = appf.Annotations
if appf.SyslogURL != "" {
// TODO consistent with some other fields (config), unsetting in app.yaml doesn't unset on server. undecided policy for all fields
appfApp.SyslogURL = &appf.SyslogURL
}
}

// find and create/update app if required
app, err := apps.GetAppByName(p.clientV2, appName)
if _, ok := err.(apps.NameNotFoundError); ok && p.createApp {
app = &models.App{
Name: appName,
}

if appf != nil {
// set other fields from app file
app.Config = appf.Config
app.Annotations = appf.Annotations
}

app, err = apps.CreateApp(p.clientV2, app)
app, err = apps.CreateApp(p.clientV2, &appfApp)
if err != nil {
return err
}
} else if err != nil {
return err
} else if appf != nil {
// app exists, but we need to update it if we have an app file
app, err = apps.PutApp(p.clientV2, app.ID, &models.App{
Config: appf.Config,
Annotations: appf.Annotations,
})
app, err = apps.PutApp(p.clientV2, app.ID, &appfApp)
if err != nil {
return fmt.Errorf("Failed to update app config: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions common/appfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ var (

// AppFile defines the internal structure of a app.yaml/json/yml
type AppFile struct {
Name string `yaml:"name,omitempty" json:"name,omitempty"`
// TODO: Config here is not yet used
Name string `yaml:"name,omitempty" json:"name,omitempty"`
Config map[string]string `yaml:"config,omitempty" json:"config,omitempty"`
Annotations map[string]interface{} `yaml:"annotations,omitempty" json:"annotations,omitempty"`
SyslogURL string `yaml:"syslog_url,omitempty" json:"syslog_url,omitempty"`
}

func findAppfile(path string) (string, error) {
Expand Down
46 changes: 46 additions & 0 deletions test/cli_misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,53 @@ func TestAppYamlDeployFailNotExist(t *testing.T) {
h.Fn("deploy", "--all", "--local").AssertFailed().AssertStderrContains("app " + appName + " not found")
}

func TestAppYamlDeployInspect(t *testing.T) {
// this test only inspects, does not invoke! for syslog, mostly
t.Parallel()

h := testharness.Create(t)
defer h.Cleanup()

appName := h.NewAppName()
fnName := h.NewFuncName(appName)
h.WithFile("app.yaml", fmt.Sprintf(`
name: %s
syslog_url: tcp://example.com:42
config:
animal: giraffe
`, appName), 0644)
h.MkDir(fnName)
h.Cd(fnName)
withMinimalFunction(h)
h.Cd("")
h.Fn("deploy", "--all", "--local", "--create-app").AssertSuccess()
// check config from app.yaml is set
inspect := h.Fn("inspect", "app", appName).AssertSuccess()
inspect.AssertStdoutContains(fmt.Sprintf(`"name": "%s"`, appName))
inspect.AssertStdoutContains(`"giraffe"`)
inspect.AssertStdoutContains(`"tcp://example.com:42"`)

// now should exist, this should work too
h.WithFile("app.yaml", fmt.Sprintf(`
name: %s
syslog_url: tcp://example.com:443
config:
animal: giraffe
tea: oolong
`, appName), 0644)
h.Fn("deploy", "--all", "--local").AssertSuccess()
// make sure config was updated
inspect = h.Fn("inspect", "app", appName).AssertSuccess()
inspect.AssertStdoutContains(fmt.Sprintf(`"name": "%s"`, appName))
inspect.AssertStdoutContains(`"oolong"`)
inspect.AssertStdoutContains(`"tcp://example.com:443"`)
}

func TestAppYamlDeploy(t *testing.T) {
// this test makes sure that functions can be invoked after using app.yaml deploy,
// the other test that looks just like this just inspects the function b/c syslog config
// in tests is a bad idea (ie don't test syslog here)

t.Parallel()

h := testharness.Create(t)
Expand Down

0 comments on commit 179030f

Please sign in to comment.