GoogleCloudPlatform / ruby-docker

Ruby runtime for Google Cloud Platform
Apache License 2.0
134 stars 56 forks source link

`assets:precompile` fails to run when using webpacker exclusively #201

Closed eric-hemasystems closed 2 years ago

eric-hemasystems commented 3 years ago

Most Rails apps require rails assets:precompile to be run during the build process in order to build the client-side code. It appears this can be accomplished via the build list given in the app.yaml file. Since it's such a common need it appears if no build list is specified there are some heuristics to detect if an application may be a Rails app and if so a fallback build command to build these assets is automatically run.

Unfortunately it appears these heuristics are slightly dated. Rails now includes two options for building client-side assets. The older asset pipeline and the newer webpacker which wraps the webpack tool. Developers may choose to use one, the other or both. Regardless of this choice assets:precompile is still the command to build the assets.

The heuristics in this repo are to just detect the older asset pipeline by looking for the app/assets directory. If a developer is not using the asset pipeline but just using webpacker that directory may not exist and therefore assets:precompile will not be run.

This can obviously be worked around by just providing an explicit build command. But given that webpacker is "the new way" it seems GCP would best served by working out of the box with the new way.

A similar heuristic could be used of looking for the app/javascripts directory. This is the directory webpacker is setup to work with. This is just the default and it can be specified as a different directory. For example a lot of developers name it frontend since it holds more than just JavaScript. But perhaps looking for the default directory is sufficient as a fallback heuristic and people using a non-standard directory can explicitly configure their build list.


Side note. You are calling rake assets:precompile which is also a legacy calling convention. rails assets:precompile is the calling convention for any supported version of Rails (or really anything 5+). Maybe you prefer to use the old calling convention for folks running unsupported versions of Rails? But just figured I would mention it.

eric-hemasystems commented 2 years ago

Closing this out.

The new jsbuilding gem and cssbuilding gem now depends on the assets directory again (either via sprockets or propshaft) and therefore the directory should exist and the existing heuristics will work.

Webpacker was added in v5 of Rails but jsbuilding is only compatible with v6. Therefore in theory someone may still be on 5.2 (the oldest supported version of Rails) and therefore still have the need this issue addresses. But 5.2 support is only set to last until June 1st 2022 so it's only a issue for a limited time. Combined with the fact that you can work around this by explicitly building it seems best to just close this issue.