Created
June 12, 2017 15:38
-
-
Save craigfurman/0eaf34c220d4343d67bc3d235b91ddd1 to your computer and use it in GitHub Desktop.
Revisions
-
craigfurman created this gist
Jun 12, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,78 @@ package main import ( "crypto/tls" "fmt" "os" "os/exec" "github.com/cloudfoundry/noaa/consumer" "github.com/cloudfoundry/sonde-go/events" ) func main() { cfSystemDomain := envMustHave("CF_SYSTEM_DOMAIN") cfUser := envMustHave("CF_USER") cfPassword := envMustHave("CF_PASSWORD") cfOrg := envMustHave("CF_ORG") cfSpace := envMustHave("CF_SPACE") appPath := envMustHave("APP_PATH") fmt.Println("logging in to Cloud Foundry") loginCmd := exec.Command("cf", "login", "--skip-ssl-validation", "-a", fmt.Sprintf("https://api.%s", cfSystemDomain), "-u", cfUser, "-p", cfPassword, "-o", cfOrg, "-s", cfSpace) loginOutput, err := loginCmd.CombinedOutput() if err != nil { fmt.Println("login failed!") fmt.Println(string(loginOutput)) os.Exit(1) } authToken, err := exec.Command("cf", "oauth-token").CombinedOutput() if err != nil { fmt.Println("get auth token failed!") fmt.Println(string(authToken)) os.Exit(1) } firehose := consumer.New(fmt.Sprintf("wss://doppler.%s:443", cfSystemDomain), &tls.Config{InsecureSkipVerify: true}, nil) defer firehose.Close() messages, errs := firehose.Firehose("benchy-bench", string(authToken)) go processMessages(messages, errs) fmt.Printf("pushing app %s\n", appPath) appName := "benchy-bench" cmd := exec.Command("cf", "push", "-p", appPath, appName) pushOutput, err := cmd.CombinedOutput() if err != nil { fmt.Println("push failed!") fmt.Println(string(pushOutput)) os.Exit(1) } } func processMessages(messages <-chan *events.Envelope, errs <-chan error) { for { select { case msg := <-messages: go processMessage(msg) case err := <-errs: fmt.Println(err) os.Exit(1) } } } func processMessage(msg *events.Envelope) { // TODO! } func envMustHave(key string) string { value := os.Getenv(key) if value == "" { fmt.Printf("must set %s\n", key) os.Exit(1) } return value }