matic-insurance.rails-container
rails-container-app
This role is used to download, set up, and run a Docker container for a Rails application. It also runs migrations before starting the app.
Requirements
Our tests are based on Ubuntu 14.04.
This role uses Ansible's Docker module, so the requirements are the same.
Role Variables
Here’s a list of required variables with default values:
# Docker image and tag to use
app_docker_image: 'alpine'
app_docker_image_tag: 'latest'
# Name of the running container
app_container_name: 'rails'
# Ports to expose from the container
app_ports_mapping: []
# Command to run in Docker
app_command: 'bundle exec rails s'
# Environment variables for the app
app_environment_vars: {}
# Configuration files to deploy and mount in the container
app_configuration_files: {}
If you are using a private Docker repository, please provide your Docker credentials:
# Docker credentials for private images
app_docker_login: 'login'
app_docker_password: 'password'
app_docker_email: 'email'
These variables are optional and can be changed if needed:
# Environment for Rails app
app_environment: production
# Local folder with configuration files
app_files_local_folder: './files'
# Force pull the Docker image
app_force_image_pull: true
# Docker container restart policy
app_container_restart_policy: always
# Command for database migration
app_migration_command: 'bundle exec rake db:migrate'
# Memory limit for the container
container_memory_limit: 1g
Dependencies
There are no dependencies.
Example Playbook
A simple example playbook could look like this:
- hosts: webservers
roles:
- role: rails-container-app
app_docker_image: 'maticinsurance/rails-app'
app_docker_tag: 'latest'
app_ports_mapping: ['3000:3000']
This playbook will pull the image maticinsurance/rails-app:latest
, run the migrations with bundle exec rake db:migrate
, and start the Rails app with bundle exec rails s
.
If you want to add extra environment variables:
- hosts: webservers
roles:
- role: rails-container-app
app_command: 'bundle exec sidekiq'
app_environment_vars:
REDIS_URL: redis://redis.host:6379
DATABASE_URL: postgress://db.host:5432
This will run Sidekiq and add Redis and Postgres environment variables.
If you want to deploy custom files to the application:
- hosts: webservers
roles:
- role: rails-container-app
app_files_local_folder: './files/webserver'
app_configuration_files:
settings.yaml: /app/config/settings.local.yaml
apns_cert.pem: certs/apns.pem
This will read files from your local machine using the key as the path after app_files_local_folder
and mount them to the Docker image using the value as the path. For example, ./files/webserver/settings.yaml
will be mounted as /app/config/settings.local.yaml:ro
.
License
MIT
Author Information
Matic is a communication platform that connects lenders and borrowers for new home loans. Borrowers can track their loan process and know what steps to take to complete it.
Download, configure and run rails app container
ansible-galaxy install matic-insurance.rails-container