A basic Rails application to keep track of contact with friends and family, and suggest catching up with people who are at risk of falling out of touch.
This is pre-alpha, and does not require versioning.
This repository acts as a base for developing Rails applications using Docker. It uses docker-compose to set up and run a Postgres database in a separate container, running alongside the Rails application container. The production environment will require further setup before it can start functioning.
The current versions of various dependencies are:
- postgres - Docker image for the database
- Ruby:3.0 - Docker image that the application builds on
- postgresql-client latest via apt-get
- Nodejs 14.x latest via https://deb.nodesource.com/setup_14.x
- NPM latest via https://www.npmjs.com/install.sh
- yarn latest via NPM
- Rails 6.1.3
- Ruby gems as defined in the Gemfile.lock (which is included in the repo!)
The Dockerfile, docker-compose, and Rails application files are all in the repo root. A Rails app has already been generated and is present in the repository, to save time on the manual setup steps detailed at the end of this README.
There are two methods of bringing up a development instance of the Docker setup.
A .devcontainer folder has been added, with settings that appear to work for bringing up a dev environment. To use this, open the root folder in VSCode, ensuring that various necessary extensions are installed. They need further tweaking so that we don't need to get a CLI and manually run rake db:setup, then bundle exec rails s -p 3000 -b '0.0.0.0' to get a server at localhost:3000.
- First ensure that Docker is installed on your system, along with docker-compose
Rundocker-compose buildto set up the Rails and Postgres Docker instances- Run
docker-compose upto start a development instance - Your shell should show the usual Rails and Postgres command line outputs and should not give you a command line
- Create the test and dev databases from another shell window with
docker-compose run web rake db:setup - Navigate to localhost:3000 and you should see a
Yay! You're on Railswelcome screen
After creating a scaffold for the first time, it may be necessary to:
- Set default: extract_css: true, development: dev_server: hmr: true in webpacker.yml
- Run
docker-compose run --rm web bundle exec rake webpacker:installto get webpack working
By uncommenting some lines in the docker-compose.yml, you can also enable an Adminer instance to examine your databases.
Pending development tasks are tracked using the GitHub project and issue trackers.
Useful for recreating or updating:
- To start, use the following files from this repo
.dockerignore .gitignore docker-compose.yml Dockerfile entrypoint.sh
- Create a
./Gemfilewith just the following linessource 'https://rubygems.org' gem 'rails', '~>6.1.0'
- Use
touch Gemfile.lockto create an empty lockfile, needed for the Docker build to work correctly - Create the rails app with
docker-compose run --no-deps web rails new . --force --database=postgresql --skip-test - Use
sudo chown -R $USER:$USER .to fix user ownership of the created files - Set up database connection in
./config/database.ymldefault: &default adapter: postgresql encoding: unicode host: db username: postgres password: password pool: 5
- Add the following code to
./Gemfileto install RSpec-Rails. You can do this either withdocker-compose run --no-deps bundle add rspec-rails --version "~> 4.0.2" --group "development, test"which also runs bundle install, or with the manual addition below# Run against the latest stable release group :development, :test do gem 'rspec-rails', '~> 4.0.2' end
- Then use
docker-compose buildto install RSpec-Rails, followed bydocker-compose run --no-deps web rails generate rspec:installto set up RSpec test generation - Use
sudo chown -R $USER:$USER .again to fix ownership of the remaining created files - Finally, run
docker-compose upto run the two Docker instances, and in another shell rundocker-compose run web rake db:setupto set up the test and development databases in the PostgreSQL instance, run migrations, and seed content
This was based on https://docs.docker.com/compose/rails/ but required several changes to get working on the current Ruby and Rails versions, as NodeJS / NPM / Yarn did not install correctly.