Kickoff for Rails API applications.
[replace]
- 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
- 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]
whereversion
is the one located in .ruby-version
- 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
-
Install postgres in your local machine:
- If you are using Ubuntu:
sudo apt install postgresql
- If you are using MacOS: install Postgres.app
-
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
- 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
.
-
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
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
.
Read more here
Read more here
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 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.
To run the static analyzer for security vulnerabilities run:
bundle exec brakeman -z -i config/brakeman.ignore
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.
Set the following variables in your server.
PGHERO_USERNAME=username
PGHERO_PASSWORD=password
And you can access the PGHero information by entering /pghero
.
You can find more documentation in the docs folder. The available docs are:
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Run rspec tests (
bundle exec rspec spec -fd
) - Run rubocop lint (
bundle exec rubocop app spec -R
) - Push your branch (
git push origin my-new-feature
) - Create a new Pull Request
This project is written by Widergy.