Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reuse ngrok if found in path #1556

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions testdrive/testdrive.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,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 @@ -143,18 +143,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 @@ -189,7 +196,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