Branch
This Ruby on Rails app supports Branch Furniture in their endeavours. Currently, it's being run as an embedded Shopify app.
Guidelines to Write Sustainable Code
To ensure we're building a sustainable Ruby on Rails application, we will leverage a set of guidelines. They function as a common direction for each Ruby developer working on Warrendy.
- We adhere to the principles of REST.
- We use resourceful routing mostly (e.g.
resource :pageorresources :products) and non-resourceful routingget|post|put|patchonly by exception. - We don't use service objects, instead we use data models.
- All data models live under the
app/modelsfolder. Both PORO's and Active Record models. - We name our data models properly. Any resource ending at
er(likeManager) is considered a code design smell and should most definitely be named differently. - We respect feedback from
rubocop(especially onMetrics/AbcSizetype of feedback) and use it to improve our code. Only by exception, do we dismiss Rubocop's feedback.
To ensure a common code style across the entire team, we're using rubocop (and a few additional libraries) to ensure we're writing proper code. After setting up Warrendy, you will be able to check your code by running rubocop.
bin/rubocop -c .rubocop.yml
Dependencies
- Ruby (
> 3.4.x) - PostgreSQL (
> 16.x) - NodeJS (
> 20.14.x)
Quick start (local development)
To run Branch locally, you can clone this repository and follow these steps:
- Ensure you've got Ruby and SQLite installed locally.
rbenv install # It's recommended to use rbenv for managing local Ruby versions nodenv install # It's recommended to use nodenv for managing local NodeJS versions brew install postgresql # It's recommended to use Homebrew on Mac to install database dependencies
- Install
puma-dev
Through puma-dev, we're able to run the app locally over HTTPS. Running the app locally over HTTPS is a requirement to be able to run the Shopify App as an embedded app in the Shopify Admin.
brew install puma/puma/puma-dev sudo puma-dev -setup puma-dev -install
- Run the setup script
- Run Branch locally
While the Rails application uses importmaps to manage its JavaScript dependencies, we're also using NPM to manage the JavaScript dependencies for the development of the Shopify Extensions.
To be able to run the application as an embedded Shopify App, use the following command:
NOTE: The Shopify App is already installed in our development store. Use the development store for local development.
Deployment
The Rails App Deployment
The Ruby on Rails app is hosted on Branch's GCP instance and deployed through Kamal on a VM. You can find the GCP project here.
The deployment of the Ruby on Rails app is done manually. To deploy, ensure you have installed Google's CLI. See instructions. After installing the Google CLI, ensure that you have added your SSH key to the project.
$ gcloud compute os-login ssh-keys add \
--key-file=~/.ssh/google_compute_engine \
--project=shopify \
--account=branchfurniture-etlNow, you're able to deploy the Ruby on Rails app.
$ git checkout main $ bin/kamal deploy
The Shopify App Deployment
We're managing the Shopify App configuration through the Shopify CLI NPM package. You can use this package to create new deployments for the app configuration as well.
npm run shopify app deploy # To deploy a change to local app npm run shopify app deploy -- -c shopify.app.production.toml # To deploy a change to the production app