Unable to run flyctl launch

Hi, I’m trying to create and configure a new Rails app but I’m getting the following error message after running flyctl launch.

This is a brand new Rails 7 app (with importmap). I’m using flyctl v0.1.33.

Creating app in XXXXXXXXXXX
Scanning source code
Error: Failed to install bundle, exiting: exec: "bundle": cannot run executable found relative to current directory

Thanks for your help :slight_smile:

Do you have bundle command locally?

Yes I do, that’s what seems odd to me.

I tried creating another Rails app (rails new app_name) just now to see if it had anything to do with this app specifically, but I’m getting the same error…

Not that it is likely to help, but the code being run is here: flyctl/rails.go at 41e0a9e0f9583bc3a67faa22f70bd60a22133415 · superfly/flyctl · GitHub

What it is attempting to do is run the command bundle install --quiet, and checking that that returns a 0 status code. If it gets an error, it doesn’t proceed because proceeding would undoubtedly fail.

Thanks @rubys - I do get a 0 status code when I run the bundle install --quiet command myself.

➜  git:(main) ✗ bundle install --quiet
➜  git:(main) ✗ echo $?
0

Could it be that flyctl launch does not have the permission to run this command for some reason?

If flyctl can’t run commands on your behalf, launch won’t get very far.

I’d love to debug this further. If I constructed a minimal go program would you be able to compile and run it? If I were to build a minimal program and compile it for you, what operating system, instruction set would work for you (linux/mac/windows; intel/arm).

Put the following into test.go, and then run go run test.go. You may be able to install go with your favorite package manager, otherwise you can always download it.

package main

import (
    "fmt"
    "os"
    "os/exec"
)

func main() {
    cmd := exec.Command("bundle", "install")
    cmd.Stdin = nil
    cmd.Stdout = os.Stdout
    cmd.Stderr = os.Stderr
    err := cmd.Run()
    
    if (err == nil) {
       fmt.Println("it worked")
    } else {
       fmt.Println(fmt.Errorf("it failed: %w", err))
    }
}

Interesting, it failed again - with the same error message.

it failed: exec: "bundle": cannot run executable found relative to current directory

Can you try:

package main

import (
    "fmt"
    "os"
    "os/exec"
)

func main() {
    bundle, err := exec.LookPath("bundle")
    if (err != nil) {
       fmt.Println(fmt.Errorf("failure finding bundle executable: %w", err))
       return
    }

    cmd := exec.Command(bundle, "install")
    cmd.Stdin = nil
    cmd.Stdout = os.Stdout
    cmd.Stderr = os.Stderr
    err = cmd.Run()

    if (err == nil) {
       fmt.Println("it worked")
    } else {
       fmt.Println(fmt.Errorf("it failed: %w", err))
    }

}

Thanks for helping out @rubys - here’s the output.

failure finding bundle executable: exec: "bundle": cannot run executable found relative to current directory

So this means it can’t find the bundle. Indeed, bundle is not located at the root of the app, it’s located at bin/bundle. So I tried running flyctl launch from /bin and it’s working this time. Not sure it will be able to correctly build the app though, I’ll have a go at it.

It looks like there was a relatively recent change where go no longer allow results from a PATH search to be found relative to the current directory.

next attempt:

package main

import (
    "errors"
    "fmt"
    "os"
    "os/exec"
    "path/filepath"
)

func main() {
    bundle, err := exec.LookPath("bundle")
    if err != nil {
       if errors.Is(err, exec.ErrDot) {
           bundle, err = filepath.Abs(bundle)
       }

       if err != nil {
           fmt.Println(fmt.Errorf("failure finding path to bundle: %w", err))
       }
    }

    cmd := exec.Command(bundle, "install")
    cmd.Stdin = nil
    cmd.Stdout = os.Stdout
    cmd.Stderr = os.Stderr
    err = cmd.Run()

    if err == nil {
       fmt.Println("it worked")
    } else {
       fmt.Println(fmt.Errorf("it failed: %w", err))
    }
}

Yes, that works! Do you want to report the issue or open a PR for that? I’m happy opening an issue but I’m not comfortable with go so I won’t risk opening a PR :wink:

I’ve created a PR.

Meanwhile, it looks like you can work around this issue by setting an environment variable:

2 Likes

@rubys you’re a rockstar. Setting the env variable did the trick for now :wink:
Thank you so much for your help on this issue.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.