Last active
October 30, 2021 16:16
-
-
Save jdickey/5f06dd10252ddd148b9660f4dfe0abe9 to your computer and use it in GitHub Desktop.
Attempting Automation of Rails App Generation with .railsrc and App Generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # This is my ~/.railsrc file. There are many like it, but this one is mine. | |
| # known defaults | |
| --no-api | |
| --no-dev | |
| --no-edge | |
| --no-no-rc # obviously... | |
| --no-skip-action-cable | |
| --no-skip-active-record | |
| --no-skip-gemfile | |
| --no-skip-git | |
| --no-skip-javascript | |
| --no-skip-keeps | |
| --no-skip-listen | |
| --no-skip-puma | |
| --no-skip-sprockets | |
| --no-skip-turbolinks | |
| --no-skip-yarn | |
| --skip-coffee | |
| --skip-namespace | |
| --skip-system-test # ditto | |
| --skip-test # Don't use MiniTest; we'll add RSpec later | |
| # --ruby=/path/to/executable/ruby | |
| # --template=/path/to/app/template | |
| # Custom/non-default values | |
| --database=postgresql | |
| --skip-action-mailer | |
| --skip-active-storage | |
| --skip-bootsnap | |
| --skip-bundle | |
| --skip-spring | |
| --webpack=stimulus | |
| # --template=/path/to/template.rb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## Intro | |
| After too many years doing this, never mind how many, I'm attempting to automate the generation of Rails apps using a | |
| `.railsrc` file and an app-generation template. The `.railsrc` file, largely cribbed from numerous others, appears to work | |
| splendidly. | |
| The template file, which should automate setup of the newly-created app to current shop standards, is being developed incrementally; increments largely separated by *the next wall I hit*. The current "wall" has had me stopped cold for two days; my Stack Overflow skills and Google-fu are clearly not up to the task. | |
| ## Possibly Relevant Background Items | |
| 1. Ruby is installed by way of [`rbenv`](https://github.com/rbenv/rbenv#readme), which we have used for *years* without known issues. We are presently on Ruby 3.0.2p107. | |
| 2. I'm attempting to continue our long-time shop-standard usage of [`rbenv-gemsets`](https://github.com/jf/rbenv-gemset#readme), which has hitherto (before attempted use of an app generator) saved our proverbial bacon often enough that I still have *some* hair. It supports our experimentation and evolution of candidate Gems for use, without polluting the system Gem repository. | |
| ## Problem Statement | |
| When I generate a new app using the template, everything appears to work fine setting up the new app up to and including when `bundle install` is run. However, immediately after bundling reports success, the Gems are installed not in the Gemset, but in the `rbenv` Gem repository for the current Ruby version. Running the installation process manually stores the Gems in the expected place. | |
| Also, immediately after Bundler success, I see two error messages: | |
| ``` | |
| Skipping `rails webpacker:install` because `bundle install` was skipped. | |
| To complete setup, you must run `bundle install` followed by `rails webpacker:install`. | |
| ``` | |
| While I *do* specify `--skip-bundle` in the `~/.railsrc` file, I run `bundler install` explicitly in the generator, after the `Gemfile` is set up to suit. | |
| I'm fairly certain that this will boil down to a *d'oh!* moment as my nose is rubbed in the difference between what I *think* I see (in the generator source) vs what is actually there. For that, I extend my plea to you folks. | |
| So, my questions are: | |
| 1. Primarily, how do I get the generator to install Webpacker and continue with the existing bundle? | |
| 2. Why are the bundled Gems being installed in the `rbenv` Gem repository rather than my gemset, as occurs when I proceed manually? | |
| Help? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # This is my (WIP) ~/src/rails/template.rb file, patterned after an oft-used, documented manual procedure. | |
| # Explicitly specify Gems' dependencies to eliminate Dependabot warnings. | |
| # FIXME: Outdated, hardcoded Node packages are *evil*. | |
| # gem 'rails', '~> 6.1.4', '>= 6.1.4.1' | |
| # gem 'pg', '~> 1.1' | |
| # gem 'puma', '~> 5.0' | |
| # gem 'webpacker', '~> 5.0' | |
| # gem 'turbolinks', '~> 5' | |
| # gem 'jbuilder', '~> 2.7' | |
| gem 'redis', '~> 4.0' | |
| gem 'bcrypt', '~> 3.1.7' | |
| gem "bundler-audit", "~> 0.9.0" | |
| gem "dotenv-rails", "~> 2.7" | |
| gem "dry-monads", "~> 1.4" | |
| gem "ice_nine", "~> 0.11.2" | |
| gem "slim-rails", "~> 3.3" | |
| gem "foreman", "~> 0.87.2" | |
| gem "sassc-rails", "~> 2.1" | |
| gem "bundler", "~> 2.2" | |
| gem "database_cleaner", "~> 2.0" | |
| gem "pry-byebug", "~> 3.8" | |
| gem "pry-doc", "~> 1.2" | |
| gem "pry-rails", "~> 0.3.9" | |
| # gem "stimulus_reflex", "~> 3.4" | |
| gem "html2slim", "~> 0.2.0" | |
| gem "nokogiri", ">= 1.12.5" | |
| gem "view_component", "~> 2.40", require: 'view_component/engine' | |
| gem_group :development, :test do | |
| # gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] | |
| gem "flay", "~> 2.12" | |
| gem "flog", "~> 4.6" | |
| gem "inch", "~> 0.8.0" | |
| gem "reek", "~> 6.0" | |
| gem "rubocop-rails", "~> 2.12" | |
| gem "yard", "~> 0.9.26" | |
| gem "fabrication", "~> 2.22" | |
| gem "simplecov", "~> 0.21.2" | |
| gem "ffaker", "~> 2.19" | |
| gem "rspec-html-matchers", "~> 0.9.4" | |
| end | |
| # gem_group :development do | |
| # gem 'web-console', '>= 4.1.0' | |
| # gem 'rack-mini-profiler', '~> 2.0' | |
| # gem 'listen', '~> 3.3' | |
| # end | |
| gem_group :test do | |
| gem 'capybara', '>= 3.26' | |
| gem 'selenium-webdriver' | |
| # Easy installation and use of web drivers to run system tests with browsers | |
| gem 'webdrivers' | |
| gem "rspec-rails", "~> 5.0" | |
| end | |
| run "cp .ruby-version #{@app_name}" | |
| run 'rm -f .rbenv-gemset' | |
| run "mkdir -p bin tmp/gemset" | |
| run "rbenv gemset delete #{ENV['RBENV_VERSION']} ./tmp/gemset 2>&1 > /dev/null" | |
| run "rbenv gemset create #{ENV['RBENV_VERSION']} ./tmp/gemset" | |
| run 'rm -f .rbenv-gemset' | |
| run "rbenv gemset init ./tmp/gemset" | |
| # run "echo ./tmp/gemset > .rbenv-gemset" | |
| run 'cd #{@app_name}; rbenv rehash; echo "Active gemsets: " `rbenv gemset active`' | |
| run "ls -la ." | |
| run "pwd" | |
| run "bundle install" | |
| run "ls -la ./tmp/gemset/" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment