These instructions are designed for setting up The Rails Port using Docker. This will allow you to install the application and all its dependencies in Docker images and then run them in containers, almost with a single command. You will need to install Docker and docker-compose on your development machine:
To build local Docker images run from the root directory of the repository:
docker build --no-cache -f docker/dev.Dockerfile .
If this is your first time running or you have removed cache this will take some time to complete. Once the Docker images have finished building you can launch the images as containers.
To launch the app run:
docker-compose up -d
This will launch one Docker container for each 'service' specified in docker-compose.yml
and run them in the background. There are two options for inspecting the logs of these running containers:
- You can tail logs of a running container with a command like this:
docker-compose logs -f
ordocker-compose logs -f web
ordocker-compose logs -f db
. - Instead of running the containers in the background with the
-d
flag, you can launch the containers in the foreground withdocker-compose up
. The downside of this is that the logs of all the 'services' defined indocker-compose.yml
will be intermingled. If you don't want this you can mix and match - for example, you can run the database in background withdocker-compose up -d db
and then run the Rails app in the foreground viadocker-compose up web
.
Run the Rails database migrations:
docker-compose run --no-deps --rm web bin/rails db:migrate
Run the test suite by running:
docker-compose run -e "RAILS_ENV=test" --no-deps --rm web bash -c "bin/rails db:create db:migrate"
docker-compose run -e "RAILS_ENV=test" --no-deps --rm web bash -c "bin/rspec"
If you want to get into a web container and run specific commands you can fire up a throwaway container to run bash in via:
docker-compose run --rm web bash
Alternatively, if you want to use the already-running web
container then you can exec
into it via:
docker-compose exec web bash
Similarly, if you want to exec
in the db container use:
docker-compose exec db bash
If you don't already have them :
- Install ruby 2.7.3
rbenv install 2.7.3 && rbenv global 2.7.3
- Install NodeJS (version 12, you may use nvm if you have several versions)
- Install yarn
npm i -g yarn
Install Redis and PostgreSQL:
- Using your favorite package manager (e.g.
brew install redis && brew install postgresql
on macOS). - Using docker-compose (see "Docker" section below).
Setup the project's dependencies :
bin/setup
bin/lefthook install
This installs bundler, runs yarn and setup the database.
Create the .env
file:
echo "LOCKBOX_MASTER_KEY=0000000000000000000000000000000000000000000000000000000000000000" > .env
- Run the migrations :
bin/rails db:migrate RAILS_ENV=development
- Run the db services according to your installation
bin/rails s
If you need Sidekiq background workers or Webpacker development server, you can
start them all using overmind
overmind s
In a rails console with rails c
user = User.find_by(email: <your_email>)
user.add_role(:admin)
# user.add_role(:super_admin) # for super admin
In order for the pipeline to be successful, you must ensure that you respect the linting made using
You can either install lefthook who automate multiple commands:
bin/lefthook install
Or manually:
bin/standardrb --fix
bin/yarn prettier --write .
Both these commands fix errors if possible. They will print errors if they can't.
In rubymine, please follow this procedure to add the formatter / linter directly in the editor tabs: https://www.jetbrains.com/help/ruby/rubocop.html#prerequisites
To launch the tests locally, run:
bin/rspec
# On macOS you can open Code Coverage results with:
# open coverage/index.html
If you want to debug System Tests in the browser, add the following Ruby line
as a debugger in your spec/system/...
file:
page.driver.debug(binding)
Then launch the test with:
INSPECTOR=true bin/rspec spec/system/THE_FILE_spec.rb
It should automatically open Chrome and allow you to inspect the DOM,
queries, etc. You can next
and continue
in the Terminal as if you had a
binding.pry
debugging session.