|
# This template: |
|
# * commits new generated rails skeleton, |
|
# * fetches latest bullettrain template sources and stores |
|
# it in separate commit |
|
# * sets up docker-compose |
|
|
|
# Usage: rails new myapp -m https://gist.githubusercontent.com/kubicek/58f2dddc7b8f823ba73923693efa64c1/raw/template.rb |
|
|
|
# template source based on: https://github.com/mattbrictson/rails-template |
|
|
|
def rails_version |
|
@rails_version ||= Gem::Version.new(Rails::VERSION::STRING) |
|
end |
|
|
|
def rails_7_0_0? |
|
Gem::Requirement.new("= 7.0.0").satisfied_by? rails_version |
|
end |
|
|
|
unless rails_7_0_0? |
|
puts "Please use Rails 7.0.0 by executing rails _7.0.0_ new" |
|
end |
|
|
|
def commit_skeleton |
|
git add: "." |
|
# git commit will fail if user.email is not configured |
|
begin |
|
git commit: %( -m 'Rails 7.0.0 generated skeleton' ) |
|
rescue StandardError => e |
|
puts e.message |
|
end |
|
end |
|
|
|
def commit_bullettrain |
|
git clone: "--depth 1 "+ |
|
"https://github.com/bullet-train-co/bullet_train origin" |
|
|
|
# create folders |
|
run "git --git-dir origin/.git diff --name-only | xargs -n 1 dirname | xargs mkdir -p" |
|
# copy files |
|
run "git --git-dir origin/.git diff --name-only | xargs -L1 -I % cp ./origin/% ./%" |
|
|
|
run "rm -rf origin" |
|
git add: "." |
|
git commit: '-m "Added bullet_train based on #`git --git-dir origin/.git rev-parse --short HEAD`"' |
|
end |
|
|
|
def configure_bullettrain |
|
# from bullettrains bin/configure |
|
require "active_support/inflector" |
|
|
|
human = ask "What is the name of your new application in title case? (e.g. \"Some Great Application\")" |
|
variable = ActiveSupport::Inflector.parameterize(human, separator: '_') |
|
environment_variable = ActiveSupport::Inflector.parameterize(human, separator: '_').upcase |
|
class_name = variable.classify |
|
kebab_case = variable.tr("_", "-") |
|
|
|
puts "" |
|
say "Replacing instances of \"Untitled Application\" with \"#{human}\" throughout the codebase.", :green |
|
|
|
gsub_file("./.circleci/config.yml", "untitled_application", variable) |
|
gsub_file("./config/database.yml", "untitled_application", variable) |
|
gsub_file("./config/database.yml", "UNTITLED_APPLICATION", environment_variable) |
|
gsub_file("./config/cable.yml", "untitled_application", variable) |
|
gsub_file("./config/initializers/session_store.rb", "untitled_application", variable) |
|
gsub_file("./config/environments/production.rb", "untitled_application", variable) |
|
gsub_file("./config/application.rb", "UntitledApplication", class_name) |
|
# TODO: gsub_file("./config/locales/en/application.en.yml", "Untitled Application", human, /name/) |
|
gsub_file("./config/locales/en/application.en.yml", "untitled_application", variable) |
|
# TODO: gsub_file("./config/locales/en/application.en.yml", "untitled application", human.downcase, /keywords/) |
|
gsub_file("./config/locales/en/user_mailer.en.yml", "Untitled Application", human) |
|
say |
|
say "Moving `./README.example.md` to `./README.md`.", :green |
|
run "mv ./README.example.md ./README.md" |
|
|
|
# We can only do this after the README is moved into place. |
|
gsub_file("./README.md", "Untitled Application", human) |
|
|
|
git add: "." |
|
git commit: %( -m 'Configured bullettrain' ) |
|
end |
|
|
|
def commit_docker |
|
get "https://gist.githubusercontent.com/kubicek/58f2dddc7b8f823ba73923693efa64c1/raw/Dockerfile", "Dockerfile" |
|
get "https://gist.githubusercontent.com/kubicek/58f2dddc7b8f823ba73923693efa64c1/raw/docker-compose.yml", "docker-compose.yml" |
|
|
|
say "Applying changes for docker" |
|
gsub_file("Procfile.dev","-p 3000","-p 3000 -b 0.0.0.0") |
|
insert_into_file "config/cable.yml", " url: <%= ENV.fetch(\"REDIS_URL\") %>\n", :after => "adapter: redis\n" |
|
git add: "." |
|
git commit: %( -m 'Added docker' ) |
|
end |
|
|
|
after_bundle do |
|
git :init |
|
commit_skeleton |
|
commit_bullettrain |
|
configure_bullettrain |
|
commit_docker |
|
say |
|
say "Bullettrain app successfully created!", :blue |
|
say |
|
say "To get started with your new app:", :green |
|
say " cd #{original_app_name}" |
|
say |
|
say " docker compose build" |
|
say " docker compose run web bin/setup" |
|
say " docker compose up" |
|
end |
Hi, I tried this Dockerfile but got the following error - wonder if you have any suggestions:
Dockerfile:37
36 | COPY --link Gemfile Gemfile.lock ./
37 | >>> RUN bundle install &&
38 | >>> rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby//cache "${BUNDLE_PATH}"/ruby//bundler/gems/*/.git &&
39 | >>> bundle exec bootsnap precompile --gemfile
40 |
ERROR: failed to solve: process "/bin/sh -c bundle install && rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby//cache "${BUNDLE_PATH}"/ruby//bundler/gems/*/.git && bundle exec bootsnap precompile --gemfile" did not complete successfully: exit code: 5