tsipiniuk / docker-rails

Dockerized example Rails application using Yarn, ActionCable, Elasticsearch and Sidekiq

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Docker-Rails

Build Status Dependency Status Greenkeeper badge

Simple Rails 5.1 application to demonstrate using Docker for production deployment. The application is a very simple kind of CMS (content management system) allowing to manage pages. Beside the boring CRUD functionality it demonstrates the following features:

  • Auto refresh via ActionCable: If a displayed page gets changed by another user/instance, it refreshes automatically using the publish/subscribe pattern
  • Full text search via Elasticsearch and the Searchkick gem to find page content
  • Background jobs with ActiveJob and the Sidekiq gem (to handle full text indexing)
  • PDF export with wkhtmltopdf and the PDFKit gem
  • Infinitive scrolling (using the Kaminari gem and some Javascript)
  • Controller specific Javascript embedded into the asset pipeline
  • Bundle Javascript libraries with Yarn

The techniques used to build this app should not be considered as "best practice", maybe there are better ways to build. It demonstrates my way of building Rails applications. Any feedback would be appreciated.

Multi container architecture

The application is divided into 7 different containers:

  • app: Main part. It contains the Rails code to handle web requests (with the help of Nginx and the Puma gem). See the Dockerfile for details.
  • worker: Background processing. It contains the same Rails code, but only runs Sidekiq
  • db: PostgreSQL database
  • elasticsearch: Full text search engine
  • memcached: Memory caching system (used from within the app via the Dalli gem)
  • redis: In-memory key/value store (used by Sidekiq and ActionCable)
  • backup: Regularly backups the database as a dump via CRON to an Amazon S3 bucket

For running tests using RSpec, there are two additional containers:

  • test: Application code prepared for running tests
  • selenium: Standalone Chrome for executing feature specs containing Javascript

The image for the application container is based on ledermann/base, which in turn is based on the official Ruby image and adds Nginx, Node.js and Yarn.

Check it out!

To start up the application in your Docker environment:

git clone https://github.com/ledermann/docker-rails.git
cd docker-rails
cp .env.example .env
docker-compose up --build

Navigate your browser to http://[DOCKER_HOST]:[DOCKER_PORT].

Deployment

On every push, the (very small) test suite is run in public on TravisCi and in private on GitlabCI.

On every push, a new Docker image is built on Docker Hub. Via its auto-deploy feature it can be deployed to your own cloud server.

On every start of the app container, the database will be migrated (or, if not exists, created with some seeds)

If you are already a Docker Cloud user, you can deploy the whole stack with one click:

Deploy to Docker Cloud

Domain setup and SSL encryption with Let's Encrypt

The app container is ready to host with nginx proxy and letsencrypt-nginx-proxy-companion. See docker-cloud.yml for example setup.

About

Dockerized example Rails application using Yarn, ActionCable, Elasticsearch and Sidekiq


Languages

Language:Ruby 78.8%Language:HTML 12.9%Language:CoffeeScript 3.4%Language:Nginx 1.9%Language:JavaScript 1.5%Language:Shell 1.1%Language:CSS 0.4%