How-to-create-a-new-Rails-application
These are the steps that I used to create the store-integration Rails
application from scratch:
- Check that
cd uala-backend && rails -vis the same ofcd uala-backend/uala-core && bundle exec rails -v. If it doesn't, rungem uninstall railtiesand select the version not matching withuala-core's one - Generate a new Rails application. I used the following options:
cd uala-backend && rails new store-integration --database postgresql --api \--skip-git --skip-action-mailer --skip-action-mailbox --skip-action-cable \--skip-asset-pipeline --skip-javascript --skip-testcd store-integration
- Delete redundant files
# Already defined and/or configured elsewhererm app/models/application_record.rb config/initializers/cors.rb config/initializers/inflections.rb
- Copy several files from a sibling application. For the
store-integration, I copied them fromuala-internal-tools:cp ../uala-internal-tools/{Gemfile,.env.development,.env.test,.rubocop.yml,.undercover,.rspec} .cp ../uala-internal-tools/config/{sidekiq.yml,database.yml,database.ci.yml,puma.rb} configcp ../uala-internal-tools/config/environments/* config/environmentscp --no-dereference ../uala-internal-tools/lib/hairdressr libcp --no-dereference ../uala-internal-tools/db/schema.rb dbcp --no-dereference ../uala-internal-tools/app/main_models appcp ../uala-internal-tools/bin/* binmkdir -p spec/supportcp ../uala-internal-tools/spec/{spec_helper.rb,rails_helper.rb} speccp ../uala-internal-tools/spec/support/factory_bot.rb spec/support/cp --no-dereference ../uala-internal-tools/spec/main_factories spec - Manually update some files. That's what I did for
store-integration:- Remove
.rubocop_todo.ymlreference from.rubocop.ymlas the app is new so it doesn't have existing RuboCop errors - Update
uala-backend.code-workspaceand.github/workflows/pull_request_title.ymlcopying sections from another existing app - Copy
Dockerfilefrom an existing sibling application and update it properly - Update
lefthook.ymlproperly
- Remove
- Fix RuboCop offenses related to generated files:
bundlebundle exec rubocop -A
- Customize
config/application.rbadding the following lines:# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.config.time_zone = "Rome"# Eager load `lib` pathconfig.eager_load_paths << Rails.root.join("lib") - Add
mount Uala::Core::Engine => '/'toconfig/routes.rb, to provide routes necessary for the infrastructure (f.e./ping) - Wire the new app into the GitHub Actions pipelines:
- Add the new project to
ci.yml'sci-lintandci-tests-coveragematrices. - Add a new per-app job block to each relevant
cd-*.yml(cd-staging.yml,cd-production.yml,cd-on-demand.yml), copying an existing app's block and updatingecr_repository_name,dockerfile_path,overlay_base_path, andoverlay_service_infix— see this for what these workflows do. - Scaffold the new app's overlay in
k8s-gitops-twpro. If it needs runtime secrets, list them intwpro-infra'sconfig/<env>.yaml, then give the overlay aSecretProviderClass, atwpro-appserviceaccount.yamland acsi-patch.yamlthat mounts the class — an unmounted class produces nothing forenvFromto read. See Deployment secrets flow. A new namespace also needs adding totofu/pod-identity/<cluster>/main.tf, or nothing in it can read a secret.
- Add the new project to