aedeploy.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Copyright 2015 Google Inc. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. // Program aedeploy assists with deploying App Engine "flexible environment" Go apps to production.
  5. // A temporary directory is created; the app, its subdirectories, and all its
  6. // dependencies from $GOPATH are copied into the directory; then the app
  7. // is deployed to production with the provided command.
  8. //
  9. // The app must be in "package main".
  10. //
  11. // This command must be issued from within the root directory of the app
  12. // (where the app.yaml file is located).
  13. package main
  14. import (
  15. "flag"
  16. "fmt"
  17. "log"
  18. "os"
  19. "os/exec"
  20. "strings"
  21. )
  22. func usage() {
  23. fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
  24. fmt.Fprintf(os.Stderr, "\t%s gcloud --verbosity debug app deploy --version myversion ./app.yaml\tDeploy app to production\n", os.Args[0])
  25. }
  26. var verbose bool
  27. // vlogf logs to stderr if the "-v" flag is provided.
  28. func vlogf(f string, v ...interface{}) {
  29. if !verbose {
  30. return
  31. }
  32. log.Printf("[aedeploy] "+f, v...)
  33. }
  34. func main() {
  35. flag.BoolVar(&verbose, "v", false, "Verbose logging.")
  36. flag.Usage = usage
  37. flag.Parse()
  38. if flag.NArg() < 1 {
  39. usage()
  40. os.Exit(1)
  41. }
  42. notice := func() {
  43. fmt.Fprintln(os.Stderr, `NOTICE: aedeploy is deprecated. Just use "gcloud app deploy".`)
  44. }
  45. notice()
  46. if err := deploy(); err != nil {
  47. fmt.Fprintf(os.Stderr, os.Args[0]+": Error: %v\n", err)
  48. notice()
  49. fmt.Fprintln(os.Stderr, `You might need to update gcloud. Run "gcloud components update".`)
  50. os.Exit(1)
  51. }
  52. notice() // Make sure they see it at the end.
  53. }
  54. // deploy calls the provided command to deploy the app from the temporary directory.
  55. func deploy() error {
  56. vlogf("Running command %v", flag.Args())
  57. cmd := exec.Command(flag.Arg(0), flag.Args()[1:]...)
  58. cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
  59. if err := cmd.Run(); err != nil {
  60. return fmt.Errorf("unable to run %q: %v", strings.Join(flag.Args(), " "), err)
  61. }
  62. return nil
  63. }