Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruby on Rails: Do not run rake assets:precompile in build step if a Rails asset pipeline is not configured #839

Merged
merged 5 commits into from
Mar 25, 2023

Conversation

half0wl
Copy link
Member

@half0wl half0wl commented Mar 24, 2023

This PR resolves #751 by tweaking the Rails build plan to only include bundle exec rake assets:precompile if sprockets is installed.

Context

In Rails applications, bundle exec rake assets:precompile is only included when the sprockets (Rails' asset pipeline) gem is installed. If sprockets is not a dependency (a common setup for Rails API-only apps [0] because they have no assets), the nixpacks build will fail because rake assets:precompile is missing.

[0] https://guides.rubyonrails.org/api_app.html

Checklist

  • Tests are added/updated if needed
  • Docs are updated if needed

(WIP -- I'd like to include a snapshot plan test in this PR. Gonna research how to do it.) added in 1e3bac2

Copy link
Contributor

@coffee-cup coffee-cup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Can you please add a rails api only test to examples/ and run it in the docker_run_tests

@coffee-cup coffee-cup added the release/minor Author minor release label Mar 24, 2023
@half0wl
Copy link
Member Author

half0wl commented Mar 24, 2023

Looks good! Can you please add a rails api only test to examples/ and run it in the docker_run_tests

Added in 1e3bac2.

The diff is a bit gruesome to review because of the example app. Here are the main changes:

fn uses_sprockets(&self, app: &App) -> Result<bool> {
if app.includes_file("Gemfile") {
let gemfile = app.read_file("Gemfile").unwrap_or_default();
return Ok(gemfile.contains("sprockets"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Propshaft also requires an assets:precompile step

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch, thank you! Added in 291e19a.

src/providers/ruby.rs Outdated Show resolved Hide resolved
src/providers/ruby.rs Outdated Show resolved Hide resolved
@half0wl half0wl requested a review from piperswe March 24, 2023 23:08
Copy link
Contributor

@coffee-cup coffee-cup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@half0wl
Copy link
Member Author

half0wl commented Mar 25, 2023

Hm, CI seems to be failing on an error unrelated to this changeset, which cancelled all existing running checks.

The error is a 503: Egress is over the account limit from the GitHub API, coming from test_zig_gyro:

...
 #10 0.461 --2023-03-25 00:09:49--  https://objects.githubusercontent.com/github-production-release-asset-2e65be/271882032/c9b9bbbc-b802-4609-b360-90701604cc81?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20230325%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20230325T000949Z&X-Amz-Expires=300&X-Amz-Signature=c8ffe348227fcff50713fa8cbc1b9a872d696b928217edc9cc1d3c773a16db6a&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=271882032&response-content-disposition=attachment%3B%20filename%3Dgyro-0.6.0-linux-x86_64.tar.gz&response-content-type=application%2Foctet-stream
#10 0.462 Resolving objects.githubusercontent.com (objects.githubusercontent.com)... 185.199.110.133, 185.199.111.133, 185.199.108.133, ...
#10 0.464 Connecting to objects.githubusercontent.com (objects.githubusercontent.com)|185.199.110.133|:443... connected.
#10 0.469 HTTP request sent, awaiting response... 503 Egress is over the account limit.
...

https://github.com/railwayapp/nixpacks/actions/runs/4516055630/jobs/7954572560?pr=839#step:6:376

@coffee-cup
Copy link
Contributor

Hm, CI seems to be failing on an error unrelated to this changeset, which cancelled all existing running checks.

The error is a 503: Egress is over the account limit from the GitHub API, coming from test_zig_gyro:

...
 #10 0.461 --2023-03-25 00:09:49--  https://objects.githubusercontent.com/github-production-release-asset-2e65be/271882032/c9b9bbbc-b802-4609-b360-90701604cc81?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20230325%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20230325T000949Z&X-Amz-Expires=300&X-Amz-Signature=c8ffe348227fcff50713fa8cbc1b9a872d696b928217edc9cc1d3c773a16db6a&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=271882032&response-content-disposition=attachment%3B%20filename%3Dgyro-0.6.0-linux-x86_64.tar.gz&response-content-type=application%2Foctet-stream
#10 0.462 Resolving objects.githubusercontent.com (objects.githubusercontent.com)... 185.199.110.133, 185.199.111.133, 185.199.108.133, ...
#10 0.464 Connecting to objects.githubusercontent.com (objects.githubusercontent.com)|185.199.110.133|:443... connected.
#10 0.469 HTTP request sent, awaiting response... 503 Egress is over the account limit.
...

https://github.com/railwayapp/nixpacks/actions/runs/4516055630/jobs/7954572560?pr=839#step:6:376

Yeah seems GitHub is having a few issues. Reran and will see

@half0wl half0wl changed the title Ruby on Rails: Do not run rake assets:precompile in build step if sprockets is not installed Ruby on Rails: Do not run rake assets:precompile in build step if a Rails asset pipeline is not configured Mar 25, 2023
@coffee-cup coffee-cup merged commit 7d57ea3 into railwayapp:main Mar 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release/minor Author minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ruby: Rails build fails when configured as an api
4 participants