deploy ERROR [stage-3 7/7] RUN bin/rails fly:build

Hi, I’m getting this error anytime I attempt to fly deploy on my mac, my project is write by ruby on rails.

 $fly deploy
==> Verifying app config
--> Verified app config
==> Building image
Remote builder fly-builder-billowing-wave-9574 ready
==> Creating build context
--> Creating build context done
==> Building image with Docker
--> docker host: 20.10.12 linux x86_64
Sending build context to Docker daemon  23.48kB
[+] Building 8.8s (20/20) FINISHED
 => [internal] load remote build context                                                           0.0s
 => copy /context /                                                                                0.1s
 => resolve image config for docker.io/docker/dockerfile:experimental                              1.9s
 => CACHED docker-image://docker.io/docker/dockerfile:experimental@sha256:600e5c62eedff338b3f7a08  0.0s
 => [internal] load metadata for quay.io/evl.ms/fullstaq-ruby:2.7.6-jemalloc-slim                  2.5s
 => [base 1/5] FROM quay.io/evl.ms/fullstaq-ruby:2.7.6-jemalloc-slim@sha256:a7a7889400d58bea89344  0.0s
 => CACHED [base 2/5] RUN mkdir /app                                                               0.0s
 => CACHED [base 3/5] WORKDIR /app                                                                 0.0s
 => CACHED [base 4/5] RUN mkdir -p tmp/pids                                                        0.0s
 => CACHED [base 5/5] RUN gem update --system --no-document &&     gem install -N bundler -v 2.1.  0.0s
 => CACHED [stage-3 1/7] RUN --mount=type=cache,id=prod-apt-cache,sharing=locked,target=/var/cach  0.0s
 => CACHED [build_deps 1/1] RUN --mount=type=cache,id=dev-apt-cache,sharing=locked,target=/var/ca  0.0s
 => CACHED [gems 1/2] COPY Gemfile* ./                                                             0.0s
 => CACHED [gems 2/2] RUN bundle install && rm -rf vendor/bundle/ruby/*/cache                      0.0s
 => CACHED [stage-3 2/7] COPY --from=gems /app /app                                                0.0s
 => CACHED [stage-3 3/7] COPY --from=gems /usr/lib/fullstaq-ruby/versions /usr/lib/fullstaq-ruby/  0.0s
 => CACHED [stage-3 4/7] COPY --from=gems /usr/local/bundle /usr/local/bundle                      0.0s
 => [stage-3 5/7] COPY . .                                                                         0.0s
 => [stage-3 6/7] RUN chmod +x /app/bin/* &&     sed -i 's/ruby.exe\r*/ruby/' /app/bin/* &&     s  0.5s
 => ERROR [stage-3 7/7] RUN bin/rails fly:build                                                    3.5s
------
 > [stage-3 7/7] RUN bin/rails fly:build:
#20 3.477 rails aborted!
#20 3.477 ExecJS::RuntimeUnavailable: Could not find a JavaScript runtime. See https://github.com/rails/execjs for a list of available runtimes.
#20 3.477 /app/vendor/bundle/ruby/2.7.0/gems/execjs-2.8.1/lib/execjs/runtimes.rb:58:in `autodetect'
#20 3.477 /app/vendor/bundle/ruby/2.7.0/gems/execjs-2.8.1/lib/execjs.rb:5:in `<module:ExecJS>'
#20 3.477 /app/vendor/bundle/ruby/2.7.0/gems/execjs-2.8.1/lib/execjs.rb:4:in `<main>'
#20 3.477 /app/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
#20 3.477 /app/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
#20 3.477 /app/vendor/bundle/ruby/2.7.0/gems/uglifier-4.2.0/lib/uglifier.rb:5:in `<main>'
#20 3.477 /app/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
#20 3.477 /app/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
#20 3.477 /usr/local/bundle/gems/bundler-2.1.4/lib/bundler/runtime.rb:74:in `block (2 levels) in require'
#20 3.477 /usr/local/bundle/gems/bundler-2.1.4/lib/bundler/runtime.rb:69:in `each'
#20 3.477 /usr/local/bundle/gems/bundler-2.1.4/lib/bundler/runtime.rb:69:in `block in require'
#20 3.477 /usr/local/bundle/gems/bundler-2.1.4/lib/bundler/runtime.rb:58:in `each'
#20 3.477 /usr/local/bundle/gems/bundler-2.1.4/lib/bundler/runtime.rb:58:in `require'
#20 3.477 /usr/local/bundle/gems/bundler-2.1.4/lib/bundler.rb:174:in `require'
#20 3.477 /app/config/application.rb:18:in `<main>'
#20 3.477 /app/Rakefile:4:in `require_relative'
#20 3.477 /app/Rakefile:4:in `<main>'
#20 3.477 /app/vendor/bundle/ruby/2.7.0/gems/railties-5.2.8.1/lib/rails/commands/rake/rake_command.rb:22:in `block in perform'
#20 3.477 /app/vendor/bundle/ruby/2.7.0/gems/railties-5.2.8.1/lib/rails/commands/rake/rake_command.rb:20:in `perform'
#20 3.477 /app/vendor/bundle/ruby/2.7.0/gems/railties-5.2.8.1/lib/rails/command.rb:48:in `invoke'
#20 3.477 /app/vendor/bundle/ruby/2.7.0/gems/railties-5.2.8.1/lib/rails/commands.rb:18:in `<main>'
#20 3.477 /app/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
#20 3.477 /app/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
#20 3.477 bin/rails:10:in `<main>'
#20 3.477 (See full trace by running task with --trace)
------
Error failed to fetch an image or build from source: error building: executor failed running [/bin/bash -o pipefail -c ${BUILD_COMMAND}]: exit code: 1

my fly.toml:

# fly.toml file generated for stocks on 2023-01-05T15:39:15+11:00

app = "stocks"
kill_signal = "SIGINT"
kill_timeout = 5
processes = []

[build]
  [build.args]
    BUNDLER_VERSION = "2.1.4"
    NODE_VERSION = "18" 
    RUBY_VERSION = "2.7.6"

    BUILD_COMMAND = "bin/rails fly:build"
    SERVER_COMMAND = "bin/rails fly:server"

[deploy]
  release_command = "bin/rails fly:release"

[env]
  PORT = "8080"

[experimental]
  allowed_public_ports = []
  auto_rollback = true

[[services]]
  http_checks = []
  internal_port = 8080
  processes = ["app"]
  protocol = "tcp"
  script_checks = []
  [services.concurrency]
    hard_limit = 25
    soft_limit = 20
    type = "connections"

  [[services.ports]]
    force_https = true
    handlers = ["http"]
    port = 80

  [[services.ports]]
    handlers = ["tls", "http"]
    port = 443

  [[services.tcp_checks]]
    grace_period = "1s"
    interval = "15s"
    restart_limit = 0
    timeout = "2s"

[[statics]]
  guest_path = "/app/public"
  url_prefix = "/"

I have same error. Did you find the solution?

Yes. After you run fly launch, Fly create a file named Dockerfile, add nodejs at the end of ARG DEPLOY_PACKAGES. It worked in my project, good luck to you.

1 Like

My solution is blow, good luck to you