You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.9 KiB

  1. // Copyright 2015 The Go Authors. 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. package main
  5. import (
  6. "bytes"
  7. "errors"
  8. "fmt"
  9. "os"
  10. "os/exec"
  11. "path/filepath"
  12. "runtime"
  13. )
  14. type talksBuilder struct {
  15. }
  16. func (b talksBuilder) Signature(heads map[string]string) string {
  17. return heads["talks"]
  18. }
  19. const talksToolsRev = "e04df2157ae7263e17159baabadc99fb03fc7514"
  20. func (b talksBuilder) Init(dir, hostport string, heads map[string]string) (*exec.Cmd, error) {
  21. toolsDir := filepath.Join(dir, "gopath/src/golang.org/x/tools")
  22. if err := checkout(repoURL+"tools", talksToolsRev, toolsDir); err != nil {
  23. return nil, err
  24. }
  25. talksDir := filepath.Join(dir, "gopath/src/golang.org/x/talks")
  26. if err := checkout(repoURL+"talks", heads["talks"], talksDir); err != nil {
  27. return nil, err
  28. }
  29. goDir := os.Getenv("GOROOT_BOOTSTRAP")
  30. if goDir == "" {
  31. goDir = runtime.GOROOT()
  32. }
  33. goBin := filepath.Join(goDir, "bin/go")
  34. goPath := filepath.Join(dir, "gopath")
  35. presentPath := "golang.org/x/tools/cmd/present"
  36. install := exec.Command(goBin, "install", "-tags=appenginevm", presentPath)
  37. install.Env = []string{"GOROOT=" + goDir, "GOPATH=" + goPath}
  38. if err := runErr(install); err != nil {
  39. return nil, err
  40. }
  41. talksBin := filepath.Join(goPath, "bin/present")
  42. presentSrc := filepath.Join(goPath, "src", presentPath)
  43. present := exec.Command(talksBin, "-http="+hostport, "-base="+presentSrc)
  44. present.Dir = talksDir
  45. // TODO(adg): log this somewhere useful
  46. present.Stdout = os.Stdout
  47. present.Stderr = os.Stderr
  48. if err := present.Start(); err != nil {
  49. return nil, err
  50. }
  51. return present, nil
  52. }
  53. var talksMsg = []byte("Talks - The Go Programming Language")
  54. func (b talksBuilder) HealthCheck(hostport string) error {
  55. body, err := getOK(fmt.Sprintf("http://%v/", hostport))
  56. if err != nil {
  57. return err
  58. }
  59. if !bytes.Contains(body, talksMsg) {
  60. return errors.New("couldn't match string")
  61. }
  62. return nil
  63. }