2017-12-29 22:13:47 +00:00
|
|
|
// Copyright 2015 Google Inc. All rights reserved.
|
|
|
|
// Use of this source code is governed by the Apache 2.0
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
// Program aedeploy assists with deploying App Engine "flexible environment" Go apps to production.
|
|
|
|
// A temporary directory is created; the app, its subdirectories, and all its
|
|
|
|
// dependencies from $GOPATH are copied into the directory; then the app
|
|
|
|
// is deployed to production with the provided command.
|
|
|
|
//
|
|
|
|
// The app must be in "package main".
|
|
|
|
//
|
|
|
|
// This command must be issued from within the root directory of the app
|
|
|
|
// (where the app.yaml file is located).
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
2019-01-21 14:27:20 +00:00
|
|
|
"log"
|
2017-12-29 22:13:47 +00:00
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
func usage() {
|
|
|
|
fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
|
2019-01-21 14:27:20 +00:00
|
|
|
fmt.Fprintf(os.Stderr, "\t%s gcloud --verbosity debug app deploy --version myversion ./app.yaml\tDeploy app to production\n", os.Args[0])
|
|
|
|
}
|
|
|
|
|
|
|
|
var verbose bool
|
|
|
|
|
|
|
|
// vlogf logs to stderr if the "-v" flag is provided.
|
|
|
|
func vlogf(f string, v ...interface{}) {
|
|
|
|
if !verbose {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
log.Printf("[aedeploy] "+f, v...)
|
2017-12-29 22:13:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2019-01-21 14:27:20 +00:00
|
|
|
flag.BoolVar(&verbose, "v", false, "Verbose logging.")
|
2017-12-29 22:13:47 +00:00
|
|
|
flag.Usage = usage
|
|
|
|
flag.Parse()
|
|
|
|
if flag.NArg() < 1 {
|
|
|
|
usage()
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
2019-01-21 14:27:20 +00:00
|
|
|
notice := func() {
|
|
|
|
fmt.Fprintln(os.Stderr, `NOTICE: aedeploy is deprecated. Just use "gcloud app deploy".`)
|
2017-12-29 22:13:47 +00:00
|
|
|
}
|
|
|
|
|
2019-01-21 14:27:20 +00:00
|
|
|
notice()
|
|
|
|
if err := deploy(); err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, os.Args[0]+": Error: %v\n", err)
|
|
|
|
notice()
|
|
|
|
fmt.Fprintln(os.Stderr, `You might need to update gcloud. Run "gcloud components update".`)
|
|
|
|
os.Exit(1)
|
2017-12-29 22:13:47 +00:00
|
|
|
}
|
2019-01-21 14:27:20 +00:00
|
|
|
notice() // Make sure they see it at the end.
|
2017-12-29 22:13:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// deploy calls the provided command to deploy the app from the temporary directory.
|
|
|
|
func deploy() error {
|
2019-01-21 14:27:20 +00:00
|
|
|
vlogf("Running command %v", flag.Args())
|
2017-12-29 22:13:47 +00:00
|
|
|
cmd := exec.Command(flag.Arg(0), flag.Args()[1:]...)
|
|
|
|
cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
|
|
|
|
if err := cmd.Run(); err != nil {
|
|
|
|
return fmt.Errorf("unable to run %q: %v", strings.Join(flag.Args(), " "), err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|