Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add service and a way to differentiate between gcloud groups and commands #53

Merged
merged 2 commits into from
May 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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