railwayapp / nixpacks

App source + Nix packages + Docker = Image
https://nixpacks.com
MIT License
2.64k stars 239 forks source link

Ruby nixpack attempts to precompile assets in some API-only apps #1154

Open mhuggins opened 3 months ago

mhuggins commented 3 months ago

Is there an existing issue for this?

Describe the bug

When building a GraphQL API, it can be useful to include GraphiQL for users to interact with the GraphQL API via the web. GraphiQL is the typical approach to providing such an interface. However, the graphiql-rails ruby gem depends on propshaft or sprockets being installed as well to serve the JS & CSS.

Because the ruby nixpack determines if a Rails app is API-only by checking for the existence of "propshaft" or "sprockets" in the app's Gemfile, it's getting false-positives.

To address this, I would suggest searching in either config/application.rb for the string config.api_only = true or app/application_controller.rb for the string ActionController::API instead.

To reproduce

  1. Create a rails app that is API-only: rails new my-api-app --api
  2. Add graphql, graphiql-rails, & propshaft dependencies to Gemfile:
    gem 'graphiql-rails'
    gem 'graphql'
    gem 'propshaft'
  3. Install gems: bundle install
  4. Add route to config/routes.rb for GraphQL & GraphiQL:
    Rails.application.routes.draw do
      post '/graphql', to: 'graphql#execute'
      mount GraphiQL::Rails::Engine, at: '/', graphql_path: '/graphql'
    end
  5. Use the ruby nixpack with this application.

Expected behavior

The ruby nixpack should not run bundle exec rake assets:precompile.

Environment

Railsway.app deployment

mhuggins commented 3 months ago

As a workaround, create a lib/tasks/assets.rake file with the following:

# frozen_string_literal: true

Rake::Task['assets:precompile'].clear

namespace :assets do
  task precompile: :environment do
    # noop
  end
end