Rails API failed to deploy - 'assets:precompile'

i’m trying to deploy my Rails API and ran into an issue:

[+] Building 1.7s (0/1)                                                                                         
[+] Building 6.7s (24/24) FINISHED                                                                              
 => [internal] load remote build context                                                                   0.0s
 => copy /context /                                                                                        0.1s
 => resolve image config for docker.io/docker/dockerfile:experimental                                      0.2s
 => CACHED docker-image://docker.io/docker/dockerfile:experimental@<removed>
 => [internal] load metadata for quay.io/evl.ms/fullstaq-ruby:3.1.2-jemalloc-slim                          0.1s
 => [base 1/6] FROM quay.io/evl.ms/fullstaq-ruby:3.1.2-jemalloc-slim@<removed> 0.0s
 => CACHED [base 2/6] RUN mkdir /app                                                                       0.0s
 => CACHED [base 3/6] WORKDIR /app                                                                         0.0s
 => CACHED [base 4/6] RUN mkdir -p tmp/pids                                                                0.0s
 => CACHED [base 5/6] RUN curl https://get.volta.sh | bash                                                 0.0s
 => CACHED [base 6/6] RUN volta install node@16.14.2 && volta install yarn                                 0.0s
 => CACHED [stage-4 1/6] RUN --mount=type=cache,id=prod-apt-cache,sharing=locked,target=/var/cache/apt     0.0s
 => CACHED [build_deps 1/1] RUN --mount=type=cache,id=dev-apt-cache,sharing=locked,target=/var/cache/apt   0.0s
 => CACHED [gems 1/3] RUN gem install -N bundler -v 2.3.22                                                 0.0s
 => CACHED [gems 2/3] COPY Gemfile* ./                                                                     0.0s
 => CACHED [gems 3/3] RUN bundle install &&  rm -rf vendor/bundle/ruby/*/cache                             0.0s
 => CACHED [stage-4 2/6] COPY --from=gems /app /app                                                        0.0s
 => CACHED [node_modules 1/3] COPY package*json ./                                                         0.0s
 => CACHED [node_modules 2/3] COPY yarn.* ./                                                               0.0s
 => CACHED [node_modules 3/3] RUN if [ -f "yarn.lock" ]; then     yarn install;     elif [ -f "package-lo  0.0s
 => CACHED [stage-4 3/6] COPY --from=node_modules /app/node_modules /app/node_modules                      0.0s
 => [stage-4 4/6] COPY . .                                                                                 0.1s
 => [stage-4 5/6] RUN chmod +x /app/bin/* &&     sed -i 's/ruby.exe/ruby/' /app/bin/* &&     sed -i '/^#!  0.3s
 => ERROR [stage-4 6/6] RUN bin/rails fly:build                                                            5.6s
------                                                                                                          
 > [stage-4 6/6] RUN bin/rails fly:build:                                                                       
#24 5.504 rails aborted!                                                                                        
#24 5.504 Don't know how to build task 'assets:precompile' (See the list of available tasks with `rails --tasks`)                                                                                                               
#24 5.504 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task_manager.rb:59:in `[]'                    
#24 5.504 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:66:in `lookup_prerequisite'
#24 5.504 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:62:in `block in prerequisite_tasks'
#24 5.504 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:62:in `map'
#24 5.504 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:62:in `prerequisite_tasks'
#24 5.504 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `invoke_prerequisites'
#24 5.504 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:218:in `block in invoke_with_call_chain'
#24 5.504 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
#24 5.504 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
#24 5.504 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:188:in `invoke'
#24 5.504 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:160:in `invoke_task'
#24 5.504 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block (2 levels) in top_level'
#24 5.504 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `each'
#24 5.504 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block in top_level'
#24 5.504 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:125:in `run_with_threads'
#24 5.504 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:110:in `top_level'
#24 5.504 /app/vendor/bundle/ruby/3.1.0/gems/railties-7.0.3.1/lib/rails/commands/rake/rake_command.rb:24:in `block (2 levels) in perform'
#24 5.504 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:186:in `standard_exception_handling'
#24 5.504 /app/vendor/bundle/ruby/3.1.0/gems/railties-7.0.3.1/lib/rails/commands/rake/rake_command.rb:24:in `block in perform'
#24 5.504 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/rake_module.rb:59:in `with_application'
#24 5.504 /app/vendor/bundle/ruby/3.1.0/gems/railties-7.0.3.1/lib/rails/commands/rake/rake_command.rb:18:in `perform'
#24 5.504 /app/vendor/bundle/ruby/3.1.0/gems/railties-7.0.3.1/lib/rails/command.rb:51:in `invoke'
#24 5.504 /app/vendor/bundle/ruby/3.1.0/gems/railties-7.0.3.1/lib/rails/commands.rb:18:in `<main>'
#24 5.504 /app/vendor/bundle/ruby/3.1.0/gems/bootsnap-1.13.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
#24 5.504 /app/vendor/bundle/ruby/3.1.0/gems/bootsnap-1.13.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
#24 5.505 Tasks: TOP => fly:build
#24 5.505 (See full trace by running task with --trace)

so, i don’t think my API has assets like a normal rails app, so is it ok to comment out the build action in the fly.io rake file?

# commands used to deploy a Rails application
namespace :fly do
  # BUILD step:
  #  - changes to the filesystem made here DO get deployed
  #  - NO access to secrets, volumes, databases
  #  - Failures here prevent deployment
  task :build => 'assets:precompile'

  # RELEASE step:
  #  - changes to the filesystem made here are DISCARDED
  #  - full access to secrets, databases
  #  - failures here prevent deployment
  task :release => 'db:migrate'

  # SERVER step:
  #  - changes to the filesystem made here are deployed
  #  - full access to secrets, databases
  #  - failures here result in VM being stated, shutdown, and rolled back
  #    to last successful deploy (if any).
  task :server do
    sh 'bin/rails server'
  end
end

1 Like

Don’t comment out the entire line. If you want a build step that does nothing, replace that line with:

task :build

If you have things you would later like to add, you can make that task do shell commands or arbitrary ruby code.

1 Like

i’ll give that a shot! thank you!

hope the new gig is going well :slight_smile:

hope the new gig is going well :slight_smile:

I’m having fun!

I don’t have much experience with an Rails API app. Is there a convenient way to detect such an app? If so, I can adjust the generated files to better match what is required.

that’s great! i’m not sure how we could determine that, actually.

well, some success, got past that step and now running into OOM errors.

i can create a new thread but even after changing the max threads to 2 and max workers, and using a dedicated server it’s still showing this:

Recent Events
TIMESTAMP               TYPE            MESSAGE                         
2022-09-11T16:12:37Z    Received        Task received by client        
2022-09-11T16:12:37Z    Task Setup      Building Task Directory        
2022-09-11T16:12:54Z    Started         Task started by client         
2022-09-11T16:15:12Z    Terminated      OOM Killed                     
2022-09-11T16:15:12Z    Restarting      Task restarting in 1.248129751s
2022-09-11T16:15:21Z    Started         Task started by client         
2022-09-11T16:15:57Z    Terminated      OOM Killed                     
2022-09-11T16:15:57Z    Restarting      Task restarting in 1.245580871s
2022-09-11T16:16:05Z    Started         Task started by client         

2022-09-11T16:15:20Z   [info]Configuring virtual machine
2022-09-11T16:15:20Z   [info]Pulling container image
2022-09-11T16:15:20Z   [info]Unpacking image
2022-09-11T16:15:20Z   [info]Preparing kernel init
2022-09-11T16:15:20Z   [info]Configuring firecracker
2022-09-11T16:15:21Z   [info]Starting virtual machine
2022-09-11T16:15:21Z   [info]Starting init (commit: 249766e)...
2022-09-11T16:15:21Z   [info]Preparing to run: `/bin/bash -c ${SERVER_COMMAND}` as root
2022-09-11T16:15:21Z   [info]2022/09/11 16:15:21 listening on [fdaa:0:9d64:a7b:ab2:f7cf:7880:2]:22 (DNS: [fdaa::3]:53)
2022-09-11T16:15:23Z   [info]bin/rails server
2022-09-11T16:15:54Z   [info][   33.316751] Out of memory: Killed process 515 (ruby) total-vm:191068kB, anon-rss:101340kB, file-rss:4kB, shmem-rss:0kB, UID:0 pgtables:392kB oom_score_adj:0
2022-09-11T16:15:54Z   [info]=> Booting Puma
2022-09-11T16:15:54Z   [info]=> Rails 7.0.3.1 application starting in production
2022-09-11T16:15:54Z   [info]=> Run `bin/rails server --help` for more startup options
2022-09-11T16:15:55Z   [info]Starting clean up.
2022-09-11T16:15:55Z   [info]Process appears to have been OOM killed!
2022-09-11T16:16:02Z   [info]Starting instance
2022-09-11T16:16:04Z   [info]Configuring virtual machine
2022-09-11T16:16:04Z   [info]Pulling container image
2022-09-11T16:16:05Z   [info]Unpacking image
2022-09-11T16:16:05Z   [info]Preparing kernel init
2022-09-11T16:16:05Z   [info]Configuring firecracker
2022-09-11T16:16:05Z   [info]Starting virtual machine
2022-09-11T16:16:05Z   [info]Starting init (commit: 249766e)...
2022-09-11T16:16:05Z   [info]Preparing to run: `/bin/bash -c ${SERVER_COMMAND}` as root
2022-09-11T16:16:05Z   [info]2022/09/11 16:16:05 listening on [fdaa:0:9d64:a7b:ab2:f7cf:7880:2]:22 (DNS: [fdaa::3]:53)
2022-09-11T16:16:08Z   [info]bin/rails server
2022-09-11T16:17:24Z   [info][   78.877429] Out of memory: Killed process 515 (ruby) total-vm:199260kB, anon-rss:109704kB, file-rss:4kB, shmem-rss:0kB, UID:0 pgtables:408kB oom_score_adj:0
2022-09-11T16:17:24Z   [info]Starting clean up.
2022-09-11T16:17:24Z   [info]Process appears to have been OOM killed!
--> v1 failed - Failed due to unhealthy allocations - no stable job version to auto revert to and deploying as v2 

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

I’ve not had a lot of luck deploying anything but trivial Rails apps on fly.io’s free tier. See: Getting Started · Fly Docs for information on increasing memory and the pricing implications of doing so.

1 Like

ah yeah, i thought i had selected a higher tier when i initially deployed it but that was indeed my issue. went into my dashboard and scaled it up to the tier i wanted and it deployed successfully!

thanks again for all your help, really do appreciate it!