You may consider it heresy to use Docker like Vagrant however hear me out. This setup provides us a number of benefits:
- We treat Docker as a virtual machine which make it easier to reason about, you know there is only one Docker container in use for the application at all times
- By default we need to SSH into the Docker container with
make ssh
which then means subsequent command runs don't require Docker to initialise - We can stay logged into Docker so re-running tests is faster, and we can run specific tests, unlike
make test
- We no longer have to prefix commands in documentation with
bin/docker_run bundle exec rspec
instead we say make sure you are logged into the Docker container and then run commands as normal - It also means help on Stackoverflow can be followed more easily without needing to prefix things with
bin/docker_run
- PID issue no longer happens as you're always in the shell session that booted rails
- Less files in repo (no
Dockerfile
, nodev.sh
, nobin/docker_run
)
The biggest known issue is that if you restart Docker, you need to install dependencies and setup DB from scratch. This is the same whether you treat Docker as Vagrant or not, though.
In order to get your development environment up and running, simply follow these steps.
- Install Docker
- Boot up docker with
make up
- SSH into docker with
make ssh
- Install rails dependencies with
bundle install
- Setup database with
bundle exec rails db:setup
- Test it works by running the server
bundle exec rails s
If you need help, ask the original engineering team.
Below is a guide to common development tasks you'll probably need whilst working on this application.
Before running any of these commands, you need to make sure Docker is running with the following:
make up
If Docker is running but it doesn't seem to be working, you can follow the advice below.
make ssh
bundle exec rails s
To run all tests, you can do the following:
make ssh
bundle exec rspec
If you want to run a particular test:
make ssh
bundle exec rspec spec/path/to_my_spec.rb
Creating a migration and running it:
make ssh
bundle exec rails g migration CreateProducts name:string
bundle exec rails db:migrate
Recreating the database:
make ssh
bundle exec rails db:reset
To setup Docker for the first time:
make up
When things go wrong or you stop working on this application, you may want to tear down the Docker setup. You can use this command:
make down
Or if things have gone wrong and you want to start from scratch, you can restart the whole setup:
make restart
make ssh
bundle install
bundle exec rails db:setup