From 3d7bf489b5edf3c510f58e9a08b4daa94a9b729d Mon Sep 17 00:00:00 2001 From: Alessandro Rodi Date: Thu, 11 Sep 2025 17:08:51 +0200 Subject: [PATCH 1/4] Some updates --- ruby_on_rails/README.md | 1 + ruby_on_rails/app_initialisation.md | 6 ++---- ruby_on_rails/template.rb | 9 +++++++++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/ruby_on_rails/README.md b/ruby_on_rails/README.md index e5129302..48343da8 100644 --- a/ruby_on_rails/README.md +++ b/ruby_on_rails/README.md @@ -11,6 +11,7 @@ The application (and relative GitHub repo) will be named after the `[project-nam > Have you decided if you need two environments (develop and main) or just one? > As a rule of thumb: for customers we always use two environments, for internal projects we usually only use one. > Why the difference? Because we can bare the risk of having a bug in an internal project, but we cannot do that for a customer. +> Decide with your team if you want one or two branches. 1. [Initialise the Rails Application](app_initialisation.md) 1. [Push to Git Repository](first_git_push.md) diff --git a/ruby_on_rails/app_initialisation.md b/ruby_on_rails/app_initialisation.md index 4dcb2361..f31becd2 100644 --- a/ruby_on_rails/app_initialisation.md +++ b/ruby_on_rails/app_initialisation.md @@ -20,7 +20,6 @@ rails new [project-name] --database=postgresql --skip-kamal --skip-ci --skip-act where the `project-name` is exactly the one you chose before. > ⚠️ You may want to choose a different database than Postgres, but most of the time this will be your choice.\ -> If you do not need a DB you may rethink the fact that you may not need Rails at all: Take a look at [Sinatra](http://www.sinatrarb.com/) or [Angular](https://angular.io/)\ > You might also need actionmailbox of course, so always double-check the parameters that you are using. > ⭐️ This setup does not include either js-bundling nor css-bundling by default.\ @@ -28,11 +27,10 @@ where the `project-name` is exactly the one you chose before. > If you need to do fancy stuff, discuss with your team the opportunity of including a js-bundling and css-bundling tool.\ > We want to go ["no build"](https://www.youtube.com/watch?v=iqXjGiQ_D-A) whenever possible. -* Run `bin/setup` - * Run `bundle exec rails db:migrate` to generate an empty `schema.rb` file. +* Run `bin/setup` -* Then check your default Rails setup by running `rails s` and visiting http://localhost:3000. +* Then check your default Rails setup by running `bin/run` and visiting http://[project-name].localhost:3000. You should be on Rails now, yay! * Finally check if http://localhost:3000/up is green. diff --git a/ruby_on_rails/template.rb b/ruby_on_rails/template.rb index 786ffeb8..df8fc4ed 100644 --- a/ruby_on_rails/template.rb +++ b/ruby_on_rails/template.rb @@ -8,6 +8,12 @@ RUBY end +insert_into_file "Gemfile", after: /^group :development, :test do\n/ do + <<~RUBY + gem "dotenv" + RUBY +end + # replace bin/rails db:prepare with bin/rails db:setup in bin/setup gsub_file "bin/setup", "bin/rails db:prepare", "bin/rails db:setup" @@ -37,6 +43,9 @@ RUBOCOP end +create_file ".env.example", force: true +create_file ".env", force: true + create_file "bin/run", force: true do <<~RUN #!/usr/bin/env bash From e0325869beb07ddff07d0271c559d0e30bb005c7 Mon Sep 17 00:00:00 2001 From: Alessandro Rodi Date: Thu, 11 Sep 2025 17:17:08 +0200 Subject: [PATCH 2/4] Setup dotenv automatically --- ruby_on_rails/app_initialisation.md | 29 --------------------------- ruby_on_rails/template.rb | 31 +++++++++++++++++++++++++---- 2 files changed, 27 insertions(+), 33 deletions(-) diff --git a/ruby_on_rails/app_initialisation.md b/ruby_on_rails/app_initialisation.md index f31becd2..44af186d 100644 --- a/ruby_on_rails/app_initialisation.md +++ b/ruby_on_rails/app_initialisation.md @@ -59,35 +59,6 @@ Some other adjustments must be performed manually. > ⭐️bin/check, bin/fastcheck and bin/run are standardized tools for more convenience at Renuo. -### Manual adjustments - -Please perform these adjustments manually: - -#### ENV variables - -* Add `dotenv-rails` to Gemfile. Check the [gem homepage](https://github.com/bkeepers/dotenv) to see how to install the gem. -* and create `.env.example` in the root folder of the project where you will specify the only environment variable you need for now: - `SECRET_KEY_BASE`. -* Going forward we will only push the `.env.example` file to the repository in order to protect our env variables. -* Add .env to .gitignore -* Add the following section to your `bin/setup` script so that the `.env` is created from the `.env` when the project is setup locally: - - ```ruby - puts "\n== Copying sample files ==" - unless File.exist?('.env') - system! 'cp .env.example .env' - end - ``` - -* add one more key to .env.example `APP_PORT=3000` -* To ensure you have all the required keys from the `.env.example` in your `.env`, -create the initializer for dotenv-rails in `config/initializers/dotenv_rails.rb`: - -```ruby -Dotenv.require_keys(Dotenv.parse(".env.example").keys) -``` - -* Run `bin/setup` again. ### Secrets diff --git a/ruby_on_rails/template.rb b/ruby_on_rails/template.rb index df8fc4ed..878e7c9b 100644 --- a/ruby_on_rails/template.rb +++ b/ruby_on_rails/template.rb @@ -17,11 +17,16 @@ # replace bin/rails db:prepare with bin/rails db:setup in bin/setup gsub_file "bin/setup", "bin/rails db:prepare", "bin/rails db:setup" -# add the renuo fetch-secrets command in bin/setup, before bin/rails db:setup +# add the renuo fetch-secrets command and copying the dotenv file in bin/setup, before bin/rails db:setup insert_into_file "bin/setup", before: "\n puts \"\\n== Preparing database ==\"" do <<-RUBY puts "\\n== Fetching 1password dependencies ==" - system! 'renuo fetch-secrets' + system! 'renuo fetch-secrets' + + puts "\n== Copying sample files ==" + unless File.exist?('.env') + system! 'cp .env.example .env' + end RUBY end @@ -43,8 +48,26 @@ RUBOCOP end -create_file ".env.example", force: true -create_file ".env", force: true + +create_file ".env.example", force: true do + <<~ENV + SECRET_KEY_BASE=<%= `bin/rails secret`.strip %> + APP_PORT=3000 + ENV +end + +create_file ".env", force: true do + <<~ENV + SECRET_KEY_BASE=#{`bin/rails secret`.strip} + APP_PORT=3000 + ENV +end + +create_file "config/initializers/dotenv.rb", force: true do + <<~DOTENV + Dotenv.require_keys(Dotenv.parse(".env.example").keys) + DOTENV +end create_file "bin/run", force: true do <<~RUN From 065fc9001fc94c0c8ba9d7723ba79ca6b117bb20 Mon Sep 17 00:00:00 2001 From: Alessandro Rodi Date: Thu, 11 Sep 2025 17:23:16 +0200 Subject: [PATCH 3/4] Setup dotenv --- ruby_on_rails/app_initialisation.md | 1 - ruby_on_rails/template.rb | 63 ++++++++++++++++------------- 2 files changed, 35 insertions(+), 29 deletions(-) diff --git a/ruby_on_rails/app_initialisation.md b/ruby_on_rails/app_initialisation.md index 44af186d..d9b138ee 100644 --- a/ruby_on_rails/app_initialisation.md +++ b/ruby_on_rails/app_initialisation.md @@ -59,7 +59,6 @@ Some other adjustments must be performed manually. > ⭐️bin/check, bin/fastcheck and bin/run are standardized tools for more convenience at Renuo. - ### Secrets We store the secrets necessary to configure the project locally in a 1password Item. diff --git a/ruby_on_rails/template.rb b/ruby_on_rails/template.rb index 878e7c9b..393cca27 100644 --- a/ruby_on_rails/template.rb +++ b/ruby_on_rails/template.rb @@ -8,25 +8,14 @@ RUBY end -insert_into_file "Gemfile", after: /^group :development, :test do\n/ do - <<~RUBY - gem "dotenv" - RUBY -end - # replace bin/rails db:prepare with bin/rails db:setup in bin/setup gsub_file "bin/setup", "bin/rails db:prepare", "bin/rails db:setup" -# add the renuo fetch-secrets command and copying the dotenv file in bin/setup, before bin/rails db:setup +# add the renuo fetch-secrets command in bin/setup, before bin/rails db:setup insert_into_file "bin/setup", before: "\n puts \"\\n== Preparing database ==\"" do <<-RUBY puts "\\n== Fetching 1password dependencies ==" system! 'renuo fetch-secrets' - - puts "\n== Copying sample files ==" - unless File.exist?('.env') - system! 'cp .env.example .env' - end RUBY end @@ -48,25 +37,43 @@ RUBOCOP end +answer = ask("Do you want to setup dotenv? (y/n)", default: "y") -create_file ".env.example", force: true do - <<~ENV - SECRET_KEY_BASE=<%= `bin/rails secret`.strip %> - APP_PORT=3000 - ENV -end +if answer.downcase == "y" + insert_into_file "Gemfile", after: /^group :development, :test do\n/ do + <<~RUBY + gem "dotenv" + RUBY + end -create_file ".env", force: true do - <<~ENV - SECRET_KEY_BASE=#{`bin/rails secret`.strip} - APP_PORT=3000 - ENV -end + create_file ".env.example", force: true do + <<~ENV + SECRET_KEY_BASE=<%= `bin/rails secret`.strip %> + APP_PORT=3000 + ENV + end + + create_file ".env", force: true do + <<~ENV + SECRET_KEY_BASE=#{SecureRandom.hex(64)} + APP_PORT=3000 + ENV + end + + create_file "config/initializers/dotenv.rb", force: true do + <<~DOTENV + Dotenv.require_keys(Dotenv.parse(".env.example").keys) + DOTENV + end -create_file "config/initializers/dotenv.rb", force: true do - <<~DOTENV - Dotenv.require_keys(Dotenv.parse(".env.example").keys) - DOTENV + insert_into_file "bin/setup", before: "\n puts \"\\n== Preparing database ==\"" do + <<-RUBY + puts "\n== Copying sample files ==" + unless File.exist?('.env') + system! 'cp .env.example .env' + end + RUBY + end end create_file "bin/run", force: true do From 25c3b04f2bbae8bba1a80131a20937c141824d09 Mon Sep 17 00:00:00 2001 From: Alessandro Rodi Date: Thu, 11 Sep 2025 21:02:30 +0200 Subject: [PATCH 4/4] More changes --- configure_git_repository.md | 6 +++--- ruby_on_rails/app_initialisation.md | 18 +++--------------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/configure_git_repository.md b/configure_git_repository.md index 00885308..8b30e822 100644 --- a/configure_git_repository.md +++ b/configure_git_repository.md @@ -7,9 +7,9 @@ Please stick to it unless you have special needs. * Features: Remove *Wikis*, *Issues* and *Projects* * Pull Requests * Disable *Allow merge commits* and *Allow rebase merging* + * Always suggest updating pull request branches * Allow auto-merge * Automatically delete head branches - * Always suggest updating pull request branches * Manage access * Add *staff* team as a collaborator with Admin access * Add *security* team as collaborator with Write access @@ -18,13 +18,13 @@ Please stick to it unless you have special needs. * Rules/Rulesets * `develop` * Enforcement status: `Active` - * Branch targeting criteria: `develop` * Bypass list: add `Repository Admin` Role with *allow for pull requests only* option + * Branch targeting criteria: `develop` * Restrict deletions * Require linear history * Require a pull request before merging * Require status checks to pass - * Select `ci/semaphore/push` + * Select `ci/semaphore/push` (WRONG. NOT AVAILABLE NOW) * Block force pushes * `main` (same as develop but...) * Branch targeting criteria: `main` diff --git a/ruby_on_rails/app_initialisation.md b/ruby_on_rails/app_initialisation.md index d9b138ee..a2f5b489 100644 --- a/ruby_on_rails/app_initialisation.md +++ b/ruby_on_rails/app_initialisation.md @@ -75,32 +75,20 @@ Check existing projects for an example of the usage. * Update `config/application.rb` and set the default language and timezone ```ruby - config.time_zone = 'Zurich' # may vary - config.i18n.default_locale = :de # may vary - ``` - -* Update your `config/environments/production.rb` settings: - - ```ruby - config.force_ssl = true # uncomment - config.log_level = ENV.fetch("RAILS_LOG_LEVEL", "warn") # change + config.time_zone = 'Zurich' + config.i18n.default_locale = :de ``` * Update `config/environments/development.rb` settings: ```ruby - config.action_controller.action_on_unpermitted_parameters = :raise config.i18n.raise_on_missing_translations = true # uncomment - - config.generators do |g| - g.apply_rubocop_autocorrect_after_generate! - end + config.generators.apply_rubocop_autocorrect_after_generate! # uncomment ``` * Update `config/environments/test.rb` settings: ```ruby - config.action_controller.action_on_unpermitted_parameters = :raise config.i18n.raise_on_missing_translations = true # uncomment config.i18n.exception_handler = Proc.new { |exception| raise exception.to_exception } # add config.active_record.verbose_query_logs = true # add