Code Monkey home page Code Monkey logo

ruby-deploy-kickstart's Introduction

Ruby (and Rails) Deployment Kickstart

A template for deploying Ruby and Rails applications, with automation support for Ansible, Docker and Vagrant. Copy this over to your project, and modify to fit.

Read the accompanying blog post for more details.

Structure

NOTE: The files will look overwhelming at first, because they contain Vagrant, Ansible and Docker. You don't need everything. If you don't want Docker, get rid of Docker-related files. Similarly, if you don't want Ansible or Vagrant, get rid of those files.

  • Core application files are: myapp.rb, myapp.ru, myjobs.rb
  • Core supporting files are: .env, Procfile, Gemfile*, provisioning/roles/myapp/files/.env
    • The default .env file is suitable for development mode
    • In production, it is overwritten with provisioning/roles/myapp/files/.env
  • Docker: .dockerignore, Dockerfile
  • Vagrant: Vagrantfile
  • Ansible: provisioning/*

Development

  • Install Vagrant and VirtualBox
    • Preferably, install vagrant-cachier, vagrant-exec and vagrant-faster plugins for a faster development experience
  • Run: vagrant up
  • Run: vagrant ssh > cd /vagrant > foreman start
    • Or if you have installed vagrant-exec, simply run vagrant exec foreman start
  • Go to localhost:3000, it will echo you a message with development configurations

Production using Ansible

Supports only Debian and Ubuntu for now

Testing:

  • Stop everything else: vagrant halt
  • Start the Prod VM: vagrant up prod
  • Go to localhost:3000, it will echo you the same message with production configuration

Actual Deployment:

  • Go to provisioning folder
  • Edit prod_inventory and update your production server name
  • Run: ansible-playbook -i prod_inventory -u <username> -vvv prod.yml

Production using Docker

Supports any OS that can run Docker, not limited to Debian/Ubuntu

Testing:

  • Stop everything else: vagrant halt
  • Start the Docker VM: vagrant up docker
  • Go to localhost:3000, it will echo you the same message with production configuration, except things are running using Docker now

Actual Deployment:

  • Check the Docker section in Vagrantfile for the build and run commands
  • A full discussion of Docker is beyond the scope of this, but the gist is:
    • Build the Docker image (can be done locally or on the server)
    • Push it to a registry (not needed if you built on the server)
    • Run it in the server
    • For exact commands, check the Docker section in Vagrantfile

In case of errors

  • Destroy the VMs: vagrant destroy
  • Start whatever you want up again

Using it in your project:

  • Add Foreman and rails_12factor to your Gemfile
  • Copy necessary files (provisioning, .env, Procfile, Vagrantfile, Dockerfile) from here to your project
  • Modify them to fit, especially:
    • Procfile commands
    • roles/myapp/
  • Encrypt production configuration (using git-crypt, ansible vault, or anything else)
    • provisioning/roles/myapp/files should be encrypted

ruby-deploy-kickstart's People

Contributors

brunoarueira avatar rdsubhas avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.