Skip to content

Commit

Permalink
Mag/reuse ngrok (#2378)
Browse files Browse the repository at this point in the history
* reuse ngrok if found in path

* Add the path found to the output

* Fix the path where ngrok is
  • Loading branch information
magmax authored Jul 12, 2022
1 parent abb9e41 commit a6447d8
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions testdrive/testdrive.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ Follow these instructions to create a token (we don't store any tokens):
colorstring.Println("[green]=> fork completed![reset]")

// Detect terraform and install it if not installed.
_, err := exec.LookPath("terraform")
terraformPath, err := exec.LookPath("terraform")
if err != nil {
colorstring.Println("[yellow]=> terraform not found in $PATH.[reset]")
colorstring.Println("=> downloading terraform ")
Expand All @@ -142,18 +142,25 @@ Follow these instructions to create a token (we don't store any tokens):
}
colorstring.Println("[green]=> installed terraform successfully at /usr/local/bin[reset]")
} else {
colorstring.Println("[green]=> terraform found in $PATH![reset]")
colorstring.Printf("[green]=> terraform found in $PATH at %s\n[reset]", terraformPath)
}

// Download ngrok.
colorstring.Println("=> downloading ngrok ")
s.Start()
ngrokURL := fmt.Sprintf("%s/ngrok-stable-%s-%s.zip", ngrokDownloadURL, runtime.GOOS, runtime.GOARCH)
if err = downloadAndUnzip(ngrokURL, "/tmp/ngrok.zip", "/tmp"); err != nil {
return errors.Wrapf(err, "downloading and unzipping ngrok")
// Detect ngrok and install it if not installed
ngrokPath, ngrokErr := exec.LookPath("ngrok")
if ngrokErr != nil {
colorstring.Println("[yellow]=> ngrok not found in $PATH.[reset]")
colorstring.Println("=> downloading ngrok")
s.Start()
ngrokURL := fmt.Sprintf("%s/ngrok-stable-%s-%s.zip", ngrokDownloadURL, runtime.GOOS, runtime.GOARCH)
if err = downloadAndUnzip(ngrokURL, "/tmp/ngrok.zip", "/tmp"); err != nil {
return errors.Wrapf(err, "downloading and unzipping ngrok")
}
s.Stop()
colorstring.Println("[green]=> downloaded ngrok successfully![reset]")
ngrokPath = "/tmp/ngrok"
} else {
colorstring.Printf("[green]=> ngrok found in $PATH at %s\n[reset]", ngrokPath)
}
s.Stop()
colorstring.Println("[green]=> downloaded ngrok successfully![reset]")

// Create ngrok tunnel.
colorstring.Println("=> creating secure tunnel")
Expand Down Expand Up @@ -188,7 +195,7 @@ tunnels:
tunnelReadyLog := regexp.MustCompile("client session established")
tunnelTimeout := 20 * time.Second
cancelNgrok, ngrokErrors, err := execAndWaitForStderr(&wg, tunnelReadyLog, tunnelTimeout,
"/tmp/ngrok", "start", "atlantis", "--config", ngrokConfigFile.Name(), "--log", "stderr", "--log-format", "term")
ngrokPath, "start", "atlantis", "--config", ngrokConfigFile.Name(), "--log", "stderr", "--log-format", "term")
// Check if we got a fast error. Move on if we haven't (the command is still running).
if err != nil {
s.Stop()
Expand Down

0 comments on commit a6447d8

Please sign in to comment.