Unable to deploy Rails app with environment built with Docker

Hi!
I am Japanese. I am not good at English, so I apologize if my writing is poor.

I created my own Dockerfilet and docker-compose.yml and created a Rails 7.0.4 app with a Docker built environment.

I got a message that fly deploy was successful, but when I fly open, I get an error and I am not able to deploy!

Log on fly.io side ↓

2023-05-06T00:02:55.597 runner[be5a64ec] nrt [info] Starting instance

2023-05-06T00:02:55.679 runner[be5a64ec] nrt [info] Configuring virtual machine

2023-05-06T00:02:55.680 runner[be5a64ec] nrt [info] Pulling container image

2023-05-06T00:03:06.341 runner[be5a64ec] nrt [info] Unpacking image

2023-05-06T00:03:16.059 runner[be5a64ec] nrt [info] Preparing kernel init

2023-05-06T00:03:16.444 runner[be5a64ec] nrt [info] Configuring firecracker

2023-05-06T00:03:16.808 runner[be5a64ec] nrt [info] Starting virtual machine

2023-05-06T00:03:17.036 app[be5a64ec] nrt [info] Starting init (commit: 083df78)...

2023-05-06T00:03:17.061 app[be5a64ec] nrt [info] Preparing to run: `entrypoint.sh rails server -b 0.0.0.0 -e production` as root

2023-05-06T00:03:17.085 app[be5a64ec] nrt [info] 2023/05/06 09:03:17 listening on [fdaa:1:a422:a7b:fc:be5a:64ec:2]:22 (DNS: [fdaa::3]:53)

2023-05-06T00:03:20.802 app[be5a64ec] nrt [info] => Booting Puma

2023-05-06T00:03:20.802 app[be5a64ec] nrt [info] => Rails 7.0.4.2 application starting in production

2023-05-06T00:03:20.802 app[be5a64ec] nrt [info] => Run `bin/rails server --help` for more startup options

2023-05-06T00:03:22.936 app[be5a64ec] nrt [info] Puma starting in single mode...

2023-05-06T00:03:22.936 app[be5a64ec] nrt [info] * Puma version: 5.6.5 (ruby 3.1.2-p20) ("Birdie's Version")

2023-05-06T00:03:22.936 app[be5a64ec] nrt [info] * Min threads: 5

2023-05-06T00:03:22.936 app[be5a64ec] nrt [info] * Max threads: 5

2023-05-06T00:03:22.936 app[be5a64ec] nrt [info] * Environment: production

2023-05-06T00:03:22.936 app[be5a64ec] nrt [info] * PID: 520

2023-05-06T00:03:22.937 app[be5a64ec] nrt [info] * Listening on http://0.0.0.0:3000

2023-05-06T00:03:22.941 app[be5a64ec] nrt [info] Use Ctrl-C to stop

2023-05-06T00:03:23.181 health[be5a64ec] nrt [error] Health check on port 3000 has failed. Your app is not responding properly. Services exposed on ports [80, 443] will have intermittent failures until the health check passes.

2023-05-06T00:03:38.197 health[be5a64ec] nrt [info] Health check on port 3000 is now passing.

I got a message that the deployment was successful, but I am not able to display it on the screen because of the following error.

Health check on port 3000 has failed. Your app is not responding properly. Services exposed on ports [80, 443] will have intermittent failures until the health check passes.

I referred to the Reference Articles but could not find a solution.

I would like to know if there are any possible causes.
Is there anything in the following code that needs to be corrected?

  • Dockerfile
FROM ruby:3.1.2

ENV TZ Asia/Tokyo
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs && apt-get install -y vim

RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
  && echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
  && apt-get update \
  && apt-get install -y yarn

WORKDIR /myapp
COPY Gemfile Gemfile.lock /myapp/
RUN bundle install
COPY . /myapp

COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh

ENTRYPOINT ["entrypoint.sh"]
CMD ["rails", "server", "-b", "0.0.0.0", "-e", "production"]
  • fly.toml
# fly.toml app configuration file generated for sample_app on 2023-05-06T08:58:43+09:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = "sample_app"
kill_signal = "SIGINT"
kill_timeout = 5
primary_region = "nrt"
processes = []

[build]

[env]

[experimental]
  auto_rollback = true

[[services]]
  http_checks = []
  internal_port = 3000
  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 = "/myapp/public"
  url_prefix = "/"

Your English is excellent.

There are more log files you need to look at. This generally is easiest from the dashboard. See view log files for more information.

What I don’t see in your Dockerfile is assets:precompile. That is necessary for you to run in production.

I encourage you to run bin/rails generate dockerfile and use that Dockerfile instead. It contains all the necessary steps. It also will generate a smaller image that will load faster. You only need yarn and build-essential at build time.

Thank you very much!
Since I had built my environment with Docker, I created a file with docker-compose exec api bin/rails generate dockerfile and deployed it.
However, I get the following error

 => ERROR [build 9/9] RUN SECRET_KEY_BASE=DUMMY ./bin/rails assets:precompile                                   1.7s
------
 > [build 9/9] RUN SECRET_KEY_BASE=DUMMY ./bin/rails assets:precompile:
#19 1.650 rails aborted!
#19 1.651 NoMethodError: undefined method `[]' for nil:NilClass
#19 1.651
#19 1.651 YOUTUBE_API_KEY = Rails.application.credentials.youtube_api[:youtube_api_key]
#19 1.651                                                            ^^^^^^^^^^^^^^^^^^
#19 1.652 /rails/config/initializers/youtube.rb:3:in `<main>'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.2/lib/rails/engine.rb:667:in `load'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.2/lib/rails/engine.rb:667:in `block in load_config_initializer'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4.2/lib/active_support/notifications.rb:208:in `instrument'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.2/lib/rails/engine.rb:666:in `load_config_initializer'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.2/lib/rails/engine.rb:620:in `block (2 levels) in <class:Engine>'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.2/lib/rails/engine.rb:619:in `each'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.2/lib/rails/engine.rb:619:in `block in <class:Engine>'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.2/lib/rails/initializable.rb:32:in `instance_exec'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.2/lib/rails/initializable.rb:32:in `run'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.2/lib/rails/initializable.rb:61:in `block in run_initializers'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.2/lib/rails/initializable.rb:50:in `each'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.2/lib/rails/initializable.rb:50:in `tsort_each_child'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.2/lib/rails/initializable.rb:60:in `run_initializers'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.2/lib/rails/application.rb:372:in `initialize!'
#19 1.652 /rails/config/environment.rb:5:in `<main>'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/zeitwerk-2.6.7/lib/zeitwerk/kernel.rb:38:in `require'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.2/lib/rails/application.rb:348:in `require_environment!'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.2/lib/rails/application.rb:511:in `block in run_tasks_blocks'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `block in execute'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `each'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `execute'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:188:in `invoke'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/sprockets-rails-3.4.2/lib/sprockets/rails/task.rb:61:in `block (2 levels) in define'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `block in execute'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `each'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `execute'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:243:in `block in invoke_prerequisites'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `each'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `invoke_prerequisites'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:218:in `block in invoke_with_call_chain'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:188:in `invoke'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:160:in `invoke_task'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block (2 levels) in top_level'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `each'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block in top_level'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:125:in `run_with_threads'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:110:in `top_level'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.2/lib/rails/commands/rake/rake_command.rb:24:in `block (2 levels) in perform'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:186:in `standard_exception_handling'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.2/lib/rails/commands/rake/rake_command.rb:24:in `block in perform'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/rake_module.rb:59:in `with_application'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.2/lib/rails/commands/rake/rake_command.rb:18:in `perform'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.2/lib/rails/command.rb:51:in `invoke'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.2/lib/rails/commands.rb:18:in `<main>'
#19 1.652 /rails/vendor/bundle/ruby/3.1.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
#19 1.652 Tasks: TOP => environment
#19 1.652 (See full trace by running task with --trace)
------
Error: failed to fetch an image or build from source: error building: executor failed running [/bin/sh -c SECRET_KEY_BASE=DUMMY ./bin/rails assets:precompile]: exit code: 1

My app uses the Youtube API and is managed by credentials.
Is this due to the fact that master.kye does not exist in the production environment?
Or should I set something with flyctl secrets set?

Replace that line with:

if Rails.application.credentials.youtube_api
  YOUTUBE_API_KEY = Rails.application.credentials.youtube_api[:youtube_api_key]
end

The reason this is necessary is described in Access to Environment Variables at Build Time.

Thank you!
I changed youtube.rb


# YOUTUBE_API_KEY = Rails.application.credentials.youtube_api[:youtube_api_key]
if Rails.application.credentials.youtube_api
  YOUTUBE_API_KEY = Rails.application.credentials.youtube_api[:youtube_api_key]
end
Google::Apis::ClientOptions.default.application_name = 'MyApp'
Google::Apis::ClientOptions.default.application_version = '1.0'
Google::Apis::RequestOptions.default.retries = 3

YoutubeService = Google::Apis::YoutubeV3::YouTubeService.new
YoutubeService.key = YOUTUBE_API_KEY

However, there was an error

=> ERROR [build 9/9] RUN SECRET_KEY_BASE=DUMMY ./bin/rails assets:precompile                                   1.6s
------
 > [build 9/9] RUN SECRET_KEY_BASE=DUMMY ./bin/rails assets:precompile:
#19 1.574 rails aborted!
#19 1.580 NameError: uninitialized constant YOUTUBE_API_KEY
#19 1.580
#19 1.580 YoutubeService.key = YOUTUBE_API_KEY
#19 1.580                      ^^^^^^^^^^^^^^^
#19 1.580 /rails/config/initializers/youtube.rb:12:in `<main>'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.2/lib/rails/engine.rb:667:in `load'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.2/lib/rails/engine.rb:667:in `block in load_config_initializer'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4.2/lib/active_support/notifications.rb:208:in `instrument'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.2/lib/rails/engine.rb:666:in `load_config_initializer'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.2/lib/rails/engine.rb:620:in `block (2 levels) in <class:Engine>'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.2/lib/rails/engine.rb:619:in `each'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.2/lib/rails/engine.rb:619:in `block in <class:Engine>'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.2/lib/rails/initializable.rb:32:in `instance_exec'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.2/lib/rails/initializable.rb:32:in `run'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.2/lib/rails/initializable.rb:61:in `block in run_initializers'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.2/lib/rails/initializable.rb:50:in `each'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.2/lib/rails/initializable.rb:50:in `tsort_each_child'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.2/lib/rails/initializable.rb:60:in `run_initializers'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.2/lib/rails/application.rb:372:in `initialize!'
#19 1.580 /rails/config/environment.rb:5:in `<main>'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/zeitwerk-2.6.7/lib/zeitwerk/kernel.rb:38:in `require'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.2/lib/rails/application.rb:348:in `require_environment!'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.2/lib/rails/application.rb:511:in `block in run_tasks_blocks'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `block in execute'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `each'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `execute'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:188:in `invoke'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/sprockets-rails-3.4.2/lib/sprockets/rails/task.rb:61:in `block (2 levels) in define'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `block in execute'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `each'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `execute'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:243:in `block in invoke_prerequisites'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `each'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `invoke_prerequisites'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:218:in `block in invoke_with_call_chain'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:188:in `invoke'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:160:in `invoke_task'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block (2 levels) in top_level'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `each'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block in top_level'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:125:in `run_with_threads'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:110:in `top_level'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.2/lib/rails/commands/rake/rake_command.rb:24:in `block (2 levels) in perform'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:186:in `standard_exception_handling'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.2/lib/rails/commands/rake/rake_command.rb:24:in `block in perform'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/rake_module.rb:59:in `with_application'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.2/lib/rails/commands/rake/rake_command.rb:18:in `perform'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.2/lib/rails/command.rb:51:in `invoke'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.2/lib/rails/commands.rb:18:in `<main>'
#19 1.580 /rails/vendor/bundle/ruby/3.1.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
#19 1.580 Tasks: TOP => environment
#19 1.580 (See full trace by running task with --trace)
------
Error: failed to fetch an image or build from source: error building: executor failed running [/bin/sh -c SECRET_KEY_BASE=DUMMY ./bin/rails assets:precompile]: exit code: 1

I don’t think this is a fundamental solution, but once I commented out the YoutubeService.key = YOUTUBE_API_KEY in youtube.rb and deployed it.

But when I deploy, I get the same error as the first time.

2023-05-07T01:34:01Z   [info]Configuring firecracker
2023-05-07T01:34:03Z   [info]Starting virtual machine
2023-05-07T01:34:04Z   [info]Starting init (commit: 083df78)...
2023-05-07T01:34:04Z   [info]Preparing to run: `/rails/bin/docker-entrypoint ./bin/rails server` as rails
2023-05-07T01:34:04Z   [info]2023/05/07 01:34:04 listening on [fdaa:1:a422:a7b:d829:78d8:55df:2]:22 (DNS: [fdaa::3]:53)
2023-05-07T01:34:08Z   [warn]Health check on port 3000 is in a 'warning' state. Your app may not be responding properly. Services exposed on ports [80, 443] may have intermittent failures until the health check passes.
2023-05-07T01:34:13Z   [error]Health check on port 3000 has failed. Your app is not responding properly. Services exposed on ports [80, 443] will have intermittent failures until the health check passes.
2023-05-07T01:34:16Z   [info]=> Booting Puma
2023-05-07T01:34:16Z   [info]=> Rails 7.0.4.2 application starting in production
2023-05-07T01:34:16Z   [info]=> Run `bin/rails server --help` for more startup options
2023-05-07T01:34:16Z   [info]A server is already running. Check /rails/tmp/pids/server.pid.
2023-05-07T01:34:16Z   [info]Exiting
2023-05-07T01:34:17Z   [info]Starting clean up.
2023-05-07T01:34:28Z   [info]Starting instance
2023-05-07T01:34:28Z   [info]Configuring virtual machine
2023-05-07T01:34:28Z   [info]Pulling container image
2023-05-07T01:34:29Z   [info]Unpacking image
2023-05-07T01:34:29Z   [info]Preparing kernel init
2023-05-07T01:34:30Z   [info]Configuring firecracker
2023-05-07T01:34:32Z   [info]Starting virtual machine
2023-05-07T01:34:32Z   [info]Starting init (commit: 083df78)...
2023-05-07T01:34:32Z   [info]Preparing to run: `/rails/bin/docker-entrypoint ./bin/rails server` as rails
2023-05-07T01:34:33Z   [info]2023/05/07 01:34:32 listening on [fdaa:1:a422:a7b:d829:78d8:55df:2]:22 (DNS: [fdaa::3]:53)
2023-05-07T01:34:37Z   [error]Health check on port 3000 has failed. Your app is not responding properly. Services exposed on ports [80, 443] will have intermittent failures until the health check passes.
2023-05-07T01:34:44Z   [info]=> Booting Puma
2023-05-07T01:34:44Z   [info]=> Rails 7.0.4.2 application starting in production
2023-05-07T01:34:44Z   [info]=> Run `bin/rails server --help` for more startup options
2023-05-07T01:34:44Z   [info]A server is already running. Check /rails/tmp/pids/server.pid.
2023-05-07T01:34:44Z   [info]Exiting
2023-05-07T01:34:45Z   [info]Starting clean up.
--> v4 failed - Failed due to unhealthy allocations - no stable job version to auto revert to and deploying as v5

--> Troubleshooting guide at https://fly.io/docs/getting-started/troubleshooting/
Error: abort

What are the areas that need to be corrected?
Sorry to keep asking. I have been struggling with deployment errors for the past 2-3 weeks and it’s been tough mentally.

Try:

if Rails.application.credentials.youtube_api
  YOUTUBE_API_KEY = Rails.application.credentials.youtube_api[:youtube_api_key]

  Google::Apis::ClientOptions.default.application_name = 'MyApp'
  Google::Apis::ClientOptions.default.application_version = '1.0'
  Google::Apis::RequestOptions.default.retries = 3

  YoutubeService = Google::Apis::YoutubeV3::YouTubeService.new
  YoutubeService.key = YOUTUBE_API_KEY
end

Make sure your .dockerignore contains these lines: https://github.com/rubys/dockerfile-rails/blob/13d97dda1d59dddf26f7f4ab85fa31f4425847f1/test/results/esbuild/.dockerignore#L23-L26 ; In fact it might be best to copy the whole file.

Keep the questions coming! We want you to get your application up and running.

Thank you!
Changed.

if Rails.application.credentials.youtube_api
  YOUTUBE_API_KEY = Rails.application.credentials.youtube_api[:youtube_api_key]

  Google::Apis::ClientOptions.default.application_name = 'MyApp'
  Google::Apis::ClientOptions.default.application_version = '1.0'
  Google::Apis::RequestOptions.default.retries = 3

  YoutubeService = Google::Apis::YoutubeV3::YouTubeService.new
  YoutubeService.key = YOUTUBE_API_KEY
end

The error is the same as before.

2023-05-07T02:13:39Z   [info]Unpacking image
2023-05-07T02:13:39Z   [info]Preparing kernel init
2023-05-07T02:13:40Z   [info]Configuring firecracker
2023-05-07T02:13:40Z   [info]Starting virtual machine
2023-05-07T02:13:40Z   [info]Starting init (commit: 083df78)...
2023-05-07T02:13:40Z   [info]Preparing to run: `/rails/bin/docker-entrypoint ./bin/rails server` as rails
2023-05-07T02:13:40Z   [info]2023/05/07 02:13:40 listening on [fdaa:1:a422:a7b:99:2de8:9d34:2]:22 (DNS: [fdaa::3]:53)
2023-05-07T02:13:42Z   [warn]Health check on port 3000 is in a 'warning' state. Your app may not be responding properly. Services exposed on ports [80, 443] may have intermittent failures until the health check passes.
2023-05-07T02:13:43Z   [info]=> Booting Puma
2023-05-07T02:13:43Z   [info]=> Rails 7.0.4.2 application starting in production
2023-05-07T02:13:43Z   [info]=> Run `bin/rails server --help` for more startup options
2023-05-07T02:13:43Z   [info]A server is already running. Check /rails/tmp/pids/server.pid.
2023-05-07T02:13:43Z   [info]Exiting
2023-05-07T02:13:43Z   [info]Starting clean up.
2023-05-07T02:13:48Z   [info]Starting instance
2023-05-07T02:13:48Z   [info]Configuring virtual machine
2023-05-07T02:13:48Z   [info]Pulling container image
2023-05-07T02:13:49Z   [info]Unpacking image
2023-05-07T02:13:49Z   [info]Preparing kernel init
2023-05-07T02:13:49Z   [info]Configuring firecracker
2023-05-07T02:13:50Z   [info]Starting virtual machine
2023-05-07T02:13:50Z   [info]Starting init (commit: 083df78)...
2023-05-07T02:13:50Z   [info]Preparing to run: `/rails/bin/docker-entrypoint ./bin/rails server` as rails
2023-05-07T02:13:50Z   [info]2023/05/07 02:13:50 listening on [fdaa:1:a422:a7b:99:2de8:9d34:2]:22 (DNS: [fdaa::3]:53)
2023-05-07T02:13:53Z   [info]=> Booting Puma
2023-05-07T02:13:53Z   [info]=> Rails 7.0.4.2 application starting in production
2023-05-07T02:13:53Z   [info]=> Run `bin/rails server --help` for more startup options
2023-05-07T02:13:53Z   [info]A server is already running. Check /rails/tmp/pids/server.pid.
2023-05-07T02:13:53Z   [info]Exiting
2023-05-07T02:13:53Z   [info]Starting clean up.
--> v5 failed - Failed due to unhealthy allocations - no stable job version to auto revert to and deploying as v6

--> Troubleshooting guide at https://fly.io/docs/getting-started/troubleshooting/
Error: abort

The .dockerignore looks like this

# See https://docs.docker.com/engine/reference/builder/#dockerignore-file for more about ignoring files.

# Ignore git directory.
/.git/

# Ignore bundler config.
/.bundle

# Ignore all default key files.
/config/master.key
/config/credentials/*.key

# Ignore all environment files.
/.env*
!/.env.example

# Ignore all logfiles and tempfiles.
/log/*
/tmp/*
!/log/.keep
!/tmp/.keep

# Ignore pidfiles, but keep the directory.
/tmp/pids/*
!/tmp/pids/
!/tmp/pids/.keep

# Ignore storage (uploaded files in development and any SQLite databases).
/storage/*
!/storage/.keep
/tmp/storage/*
!/tmp/storage/
!/tmp/storage/.keep

# Ignore assets.
/node_modules/
/app/assets/builds/*
!/app/assets/builds/.keep
/public/assets

The .dockerignore looks like this

I can’t explain this. So I will explain what is going on and hopefully that will help.

When the rails server starts, it creates a file called tmp/pids/server.pid. If you try to create a second server, it will check for that file and refuse to start.

When you do a fly deploy we take all of the files in your application minus the ones listed in .dockerignore and deploy them. You may have run a server locally, so that’s why this directory is in .dockerignore.

Your .dockerignore looks right, but this file is getting deployed anyway. I can’t explain it.

One possible fix is to add the following to your Dockerfile:

RUN rm -f /rails/tmp/pids/server.pid

A good place to add this line would be after the following line:

RUN SECRET_KEY_BASE=DUMMY ./bin/rails assets:precompil

Thank you very much!
Deployment was successful and displayed in the browser.
The following log is on the fly.io side.
I think this log shows that the deployment was probably successful in the production environment.

2023-05-07T02:55:00.150 runner[eb09c172] nrt [info] Starting instance

2023-05-07T02:55:00.224 runner[eb09c172] nrt [info] Configuring virtual machine

2023-05-07T02:55:00.225 runner[eb09c172] nrt [info] Pulling container image

2023-05-07T02:55:09.681 runner[eb09c172] nrt [info] Unpacking image

2023-05-07T02:55:37.200 runner[eb09c172] nrt [info] Preparing kernel init

2023-05-07T02:55:39.470 runner[eb09c172] nrt [info] Configuring firecracker

2023-05-07T02:55:39.808 runner[eb09c172] nrt [info] Starting virtual machine

2023-05-07T02:55:40.059 app[eb09c172] nrt [info] Starting init (commit: 083df78)...

2023-05-07T02:55:40.083 app[eb09c172] nrt [info] Preparing to run: `/rails/bin/docker-entrypoint ./bin/rails server` as rails

2023-05-07T02:55:40.100 app[eb09c172] nrt [info] 2023/05/07 02:55:40 listening on [fdaa:1:a422:a7b:fc:eb09:c172:2]:22 (DNS: [fdaa::3]:53)

2023-05-07T02:55:43.250 app[eb09c172] nrt [info] => Booting Puma

2023-05-07T02:55:43.250 app[eb09c172] nrt [info] => Rails 7.0.4.2 application starting in production

2023-05-07T02:55:43.250 app[eb09c172] nrt [info] => Run `bin/rails server --help` for more startup options

2023-05-07T02:55:44.093 app[eb09c172] nrt [info] Puma starting in single mode...

2023-05-07T02:55:44.093 app[eb09c172] nrt [info] * Puma version: 5.6.5 (ruby 3.1.2-p20) ("Birdie's Version")

2023-05-07T02:55:44.093 app[eb09c172] nrt [info] * Min threads: 5

2023-05-07T02:55:44.093 app[eb09c172] nrt [info] * Max threads: 5

2023-05-07T02:55:44.093 app[eb09c172] nrt [info] * Environment: production

2023-05-07T02:55:44.093 app[eb09c172] nrt [info] * PID: 520

2023-05-07T02:55:44.093 app[eb09c172] nrt [info] * Listening on http://0.0.0.0:3000

2023-05-07T02:55:44.097 app[eb09c172] nrt [info] Use Ctrl-C to stop

2023-05-07T02:55:51.312 health[eb09c172] nrt [info] Health check on port 3000 is now passing.

However, I ran into two problems.
The first is that the layout is broken and the second is that I can’t introduce the seed data.

I think this question itself has been resolved, so I will ask it separately.

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