Skip to content

Commit

Permalink
Merge pull request #53 from matzika/master
Browse files Browse the repository at this point in the history
add service and a way to differentiate between gcloud groups and commands
  • Loading branch information
jprobinson authored May 13, 2019
2 parents b98f275 + 164031f commit e4b99d4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
34 changes: 29 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ type GAE struct {
// or to alter existing deployments.
// value will be sanitized (lowercase, replace non-alphanumeric with `-`, max 63 chars)
Version string `json:"version"`
// Service is used to set the service to be deployed
Service string `json:"service"`
// AEEnv allows users to set additional environment variables with `appcfg.py -E`
// in their App Engine environment. This can be useful for injecting
// secrets from your Drone secret store. No effect with `gcloud` commands.
Expand Down Expand Up @@ -164,8 +166,8 @@ func wrapMain() error {
return fmt.Errorf("error: %s\n", err)
}

// if gcloud app cmd, run it
if gcloudCmds[vargs.Action] {
// if gcloud app cmd or group, run it
if gcloudCmds[vargs.Action] || gcloudGroups[vargs.Action] {
err = runGcloud(runner, workspace, vargs)
} else {
// otherwise, do appcfg.py command
Expand Down Expand Up @@ -311,13 +313,18 @@ func validateVargs(vargs *GAE) error {
return nil
}

var gcloudCmds = map[string]bool{
"deploy": true,
// Gcloud Groups
var gcloudGroups = map[string]bool{
"services": true,
"versions": true,
"instances": true,
}

// Gcloud Commands
var gcloudCmds = map[string]bool{
"deploy": true,
}

func runGcloud(runner *Environ, workspace string, vargs GAE) error {
// add the action first (gcloud app X)
args := []string{
Expand All @@ -337,8 +344,25 @@ func runGcloud(runner *Environ, workspace string, vargs GAE) error {
args = append(args, "./app.yaml")

// add a version if we've got one
// (requires passing args differently based on whether it's a group or plain command)
if vargs.Version != "" {
args = append(args, "--version", vargs.Version)
if gcloudCmds[vargs.Action] {
args = append(args, "--version", vargs.Version)
} else {
// it's a gcloud command for a group, treat it differently
args = append(args, vargs.Version)
}
}

// add a service if we've got one
// (requires passing args differently based on whether it's a group or plain command)
if vargs.Service != "" {
if gcloudCmds[vargs.Action] {
args = append(args, "--service", vargs.Service)
} else {
// it's a gcloud command for a group, treat it differently
args = append(args, vargs.Service)
}
}

if vargs.FlexImage != "" {
Expand Down
12 changes: 12 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,18 @@ func TestValidateVargs(t *testing.T) {
}
assert.NoError(t, validateVargs(&vargs))
assert.Equal(t, "feature-prj-test123", vargs.Version)

// sanitize version short string
vargs = GAE{
Token: "mytoken",
Project: "myproject",
Action: "dostuff",
Service: "myservice",
Version: "version1",
}
assert.NoError(t, validateVargs(&vargs))
assert.Equal(t, "version1", vargs.Version)
assert.Equal(t, "myservice", vargs.Service)
}

func TestSetupFile(t *testing.T) {
Expand Down

0 comments on commit e4b99d4

Please sign in to comment.