This is my first attempt with fly.io and I am trying to port an application that I currently have hosted on Heroic.
Rails 7.1.2
Ruby 3.2.2
The full section of logs related to the error is:
=> ERROR [build 10/10] RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile 2.4s
------
> [build 10/10] RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile:
2.319 bin/rails aborted!
2.320 ArgumentError: the :bucket option is nil (ArgumentError)
2.320
2.320 raise ArgumentError, "the :bucket option is nil" unless bucket
2.320 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2.320 /rails/config/initializers/shrine.rb:28:in `new'
2.320 /rails/config/initializers/shrine.rb:28:in `<main>'
2.320 /rails/config/environment.rb:5:in `<main>'
2.320 Tasks: TOP => environment
2.320 (See full trace by running task with --trace)
------
Error: failed to fetch an image or build from source: error building: failed to solve: process "/bin/sh -c SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile" did not complete successfully: exit code: 1
Seems that it may have something to do with shrine gem or AWS S3 bucket but I can’t interpret what is being indicated. Both Shrine and S3 work perfectly on Heroic. May Gemfile contains:
gem “shrine”, ‘~> 3.4’
gem “aws-sdk-s3”, “~> 1.114”
gem ‘image_processing’, ‘~> 1.12’ #1.7.1
gem ‘fastimage’, ‘~> 2.1’
My credentials contain for AWS:
aws:
s3:
id: ABCD etc
secret: RvqL etc
region: ap-southeast-2
bucket: shrine
The net is that Rails runs your initializers in preparation for running assets:precompile, and the build machine doesn’t have access to your secrets. The reality i that you don’t need access to s3 in order to precompile your css, js, etc.
The easiest fix is to not call shrine if bucket is null. Add an if statement before line 28 in config/initializers/shrine.rb.
Not sure I fully understand as I am a beginner. Do you mean:
if Rails.application.credentials.aws
s3_options = {
access_key_id: Rails.application.credentials.dig(:aws, :s3, :id),
secret_access_key: Rails.application.credentials.dig(:aws, :s3, :secret),
region: Rails.application.credentials.dig(:aws, :s3, :region),
bucket: Rails.application.credentials.dig(:aws, :s3, :bucket)
}
end
or do I check for not null on the bucket line? if not null
=> ERROR [build 10/10] RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile 3.2s
------
> [build 10/10] RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile:
3.110 bin/rails aborted!
3.111 NoMethodError: undefined method `[]' for nil:NilClass (NoMethodError)
3.111
3.111 if s3_options[:bucket]
3.111 ^^^^^^^^^
3.111 /rails/config/initializers/shrine.rb:14:in `<main>'
3.111 /rails/config/environment.rb:5:in `<main>'
3.111 Tasks: TOP => environment
3.111 (See full trace by running task with --trace)
------
Error: failed to fetch an image or build from source: error building: failed to solve: process "/bin/sh -c SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile" did not complete successfully: exit code: 1
The problem could be your server is failing to start, or that it is taking a while to start and the deploy process gave up waiting, or any of a number of other problems.
2024-04-07T03:16:35Z proxy[5683d643a624e8] syd [error]instance refused connection. is your app listening on 0.0.0.0:3000? make sure it is not only listening on 127.0.0.1 (hint: look at your startup logs, servers often print the address they are listening on)
2024-04-07T03:16:35Z app[5683d643a624e8] syd [info] INFO Main child exited normally with code: 1
2024-04-07T03:16:35Z app[5683d643a624e8] syd [info] INFO Starting clean up.
2024-04-07T03:16:35Z app[5683d643a624e8] syd [info][ 3.252181] reboot: Restarting system
2024-04-07T03:16:35Z runner[5683d643a624e8] syd [info]machine did not have a restart policy, defaulting to restart
2024-04-07T03:16:37Z proxy[5683d643a624e8] syd [info]Starting machine
2024-04-07T03:16:37Z proxy[5683d643a624e8] syd [error]failed to change machine state: machine still active, refusing to start
2024-04-07T03:16:38Z proxy[e7842369b607e8] syd [info]Starting machine
2024-04-07T03:16:38Z proxy[e7842369b607e8] syd [error]failed to change machine state: machine still active, refusing to start
The heroku app is listening on 25961
2024-04-07T03:15:53.322928+00:00 app[web.1]: * Listening on http://0.0.0.0:25961
I just noticed another error in the logs:
2024-04-07T04:23:02Z app[5683d643a624e8] syd [info]/usr/local/bundle/ruby/3.2.0/gems/activerecord-7.1.2/lib/active_record/connection_adapters/postgresql/database_statements.rb:19:in `exec’: ERROR: relation “taggings” does not exist (PG::UndefinedTable)
2024-04-07T04:23:02Z app[5683d643a624e8] syd [info]LINE 10: WHERE a.attrelid = ‘“taggings”’::regclass
2024-04-07T04:23:02Z app[5683d643a624e8] syd [info] ^
I wonder if it is because I haven’t transferred the heroku postgres db yet. I was making sure the app ran before I did this.