widergy / rails-api-bootstrap

A Ruby on Rails API-only base project with Widergy standard defaults

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rails Api Bootstrap

CircleCI

Kickoff for Rails API applications.

API Documentation

[replace]

Running local server

1- Installing basic dependencies:

  • If you are using Ubuntu:
  sudo apt update
  sudo apt install build-essential libpq-dev nodejs libssl-dev libreadline-dev zlib1g-dev redis-server
  • If you are using MacOS:
  brew install postgresql
  brew install redis

2- Installing Ruby

  • Clone the repository by running git clone https://github.com/widergy/rails-api-bootstrap.git
  • Go to the project root by running cd rails-api-bootstrap
  • Download and install Rbenv. Read the How rbenv hooks into your shell section and the rbenv init - output carefully. You may need to do step 1 of that section manually.
  • Download and install Ruby-Build.
  • Install the appropriate Ruby version by running rbenv install [version] where version is the one located in .ruby-version

3- Installing Rails gems

  • Inside your project's directory install Bundler.
  gem install bundler --no-document
  rbenv rehash
  • Install all the gems included in the project.
  bundle -j 20

4- Database Setup

  • Install postgres in your local machine:

    • If you are using Ubuntu:
      sudo apt install postgresql
  • Create the database role:

    • If you are using Ubuntu:

      Run in terminal:

        sudo -u postgres psql
        CREATE ROLE "rails-api-bootstrap" LOGIN CREATEDB PASSWORD 'rails-api-bootstrap';
    • If you are using MacOS:

      Run in terminal:

        psql -U postgres
        CREATE ROLE "rails-api-bootstrap" LOGIN CREATEDB PASSWORD 'rails-api-bootstrap';
  • Log out from postgres

  • Check if you have to get a .env file, and if you have to, copy it to the root.

  • Create the development database. Run in terminal:

  bundle exec rake db:create db:migrate

5- Application Setup

  • Run ./script/bootstrap app_name where app_name is your application name.

Your server is ready to run. You can do this by executing bundle exec rails server inside the project's directory and going to http://localhost:3000.

Your app is ready. Happy coding!

PS: If you don't want to have to use bundle exec for rails commands, then run in terminal:

  sudo gem install rails

If you want to access to the rails console you can just execute rails console inside the project's directory. Alternatively you can use the pry gem instead. First you need to install it:

  gem install pry pry-doc

And then execute pry -r ./config/environment instead of rails console.

Running tests & linters

  • For running the test suite:

    • The first time assure to have redis up. Run in terminal:
      redis-server
    • Run in terminal:
      bundle exec rspec
  • For running code style analyzer:

  bundle exec rubocop app spec

Git pre push hook

You can modify the pre-push.sh script to run different scripts before you git push (e.g Rspec, Linters). Then you need to run the following:

  chmod +x script/pre-push.sh
  sudo ln -s ../../script/pre-push.sh .git/hooks/pre-push

You can skip the hook by adding --no-verify to your git push.

Running with Docker

Read more here

Deploy Guide

Read more here

Rollbar Configuration

Rollbar is used for exception errors report. To complete this configuration setup the following environment variables in your server

  • ROLLBAR_ACCESS_TOKEN

with the credentials located in the rollbar application.

If you have several servers with the same environment name you may want to difference them in Rollbar. For this set the ROLLBAR_ENVIRONMENT environment variable with your environment name.

Health Check

Health check is a gem which enables an endpoint to check the status of the instance where this is running. It is configured for checking sidekiq, redis status, migrations and the database among others checks. The checks can be customized inside the configuration file.

Brakeman

To run the static analyzer for security vulnerabilities run:

  bundle exec brakeman -z -i config/brakeman.ignore

Dotenv

We use dotenv to set up our environment variables in combination with secrets.yml.

For example, you could have the following secrets.yml:

production: &production
  foo: <%= ENV['FOO'] %>
  bar: <%= ENV['BAR'] %>

and a .env file in the project root that looks like this:

FOO=1
BAR=2

When the application loads up, Rails.application.secrets.foo will equal ENV['FOO'], making the environment variables reachable across the Rails app. The .env will be ignored by git so it won't be pushed into the repository, thus keeping tokens and passwords safe.

PGHero Authentication

Set the following variables in your server.

  PGHERO_USERNAME=username
  PGHERO_PASSWORD=password

And you can access the PGHero information by entering /pghero.

Documentation

You can find more documentation in the docs folder. The available docs are:

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Run rspec tests (bundle exec rspec spec -fd)
  5. Run rubocop lint (bundle exec rubocop app spec -R)
  6. Push your branch (git push origin my-new-feature)
  7. Create a new Pull Request

About

This project is written by Widergy.

Widergy

About

A Ruby on Rails API-only base project with Widergy standard defaults


Languages

Language:Ruby 93.8%Language:Shell 3.0%Language:HTML 2.8%Language:SCSS 0.3%Language:JavaScript 0.1%