Simple Rails 5.2 application to demonstrate using Docker for production deployment. The application is a very simple kind of CMS (content management system) allowing to manage posts. Beside the boring CRUD functionality it has some non-default features.
- Auto refresh via ActionCable: If a displayed post 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 post content (with suggestions)
- Autocompletion with corejs-typeahead
- PDF export with wkhtmltopdf and the WickedPDF gem
- Editing HTML content with the WYSIWYG JavaScript editor Trix
- Uploading images directly to S3 with the Shrine gem and jQuery-File-Upload
- Background jobs with ActiveJob and the Sidekiq gem (to handle full text indexing, image processing and ActionCable broadcasting)
- Cron scheduling with Sidekiq-Cron to handle daily data updates from Wikipedia
- Permalinks using the FriendlyId gem
- Infinitive scrolling (using the Kaminari gem and some JavaScript)
- User authentication with the Clearance gem
- Sending HTML e-mails with Premailer and the Really Simple Responsive HTML Email Template
- User visit and click tracking with Ahoy gem
- Admin dashboards with Blazer gem
- Controller specific JavaScript embedded into the asset pipeline
- Bundle JavaScript libraries with Yarn
This repo demonstrates my way of building Rails applications. The techniques used to build the app should not be considered as "best practice", maybe there are better ways to build. Any feedback would be appreciated.
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. The image is based on ledermann/base, which in turn is based on the official Ruby image and just adds Nginx, Node.js and Yarn.
- 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 system tests containing JavaScript
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
Wait some minutes while the database will be prepared. Then,
navigate your browser to http://[DOCKER_HOST]:[DOCKER_PORT]
.
Sign in to the admin account:
- Username:
[email protected]
- Password:
secret
Enjoy!
On every push, the test suite (including RuboCop checks) is run in public on Travis CI and in private on Gitlab CI.
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:
The app container is ready to host with nginx proxy and letsencrypt-nginx-proxy-companion. See docker-cloud.yml for example setup.