Rails on EC2

Introduction

This is the table of contents for Rails on EC2 book to walk you through the steps needed to use HiveGrid to setup a server and deploy your Rails app on AWS.

Purpose of the Book:

This book is designed to guide web developers, particularly those with no prior DevOps experience, to deploy their Rails web applications quickly. By following step-by-step instructions, readers will learn how to utilize prebuilt images and customizable Terraform templates. The book simplifies the infrastructure tasks, allowing developers to go live with their applications by simply typing commands into a terminal. This approach minimizes the learning curve and focuses on practical application to go live quickly.

Target Audience:

The target audience for this book is web developers who are proficient in building Rails applications but are new to the deployment and management of these applications on servers. The book caters to those looking for a straightforward, practical guide to taking their web applications to production without needing to delve deeply into DevOps.

  • Technologies Overview: Brief overview of the key technologies involved: AWS, Ansible, Terraform, Packer, Ruby, Rails.

Chapter 1: Development Environment Setup

  • Installing Required Software and Tools
    • AWS CLI, Ansible, Packer, Terraform, and the Boto3 Python SDK
  • Configuring the AWS CLI
    • Authentication and configuring access credentials
    • Setting default region and output format
  • Development Best Practices
    • Organizing project directories
    • Version control integration

Chapter 2: Configuring AWS IAM Users

  • Creating IAM Users
    • Creating aws-admin with Administrator access
    • Creating aws-dev with limited access to EC2 and Secrets Manager
  • Setting IAM Policies
    • Assigning policies for each user
    • Using managed policies vs. custom policies
  • Best Practices for IAM Security
    • Multi-factor authentication (MFA)
    • Using IAM roles for EC2 instances

Chapter 3: Introduction to Ansible

  • Configuring Ansible
    • Installation and initial setup
  • Ansible Playbook Creation
    • Basics of playbook writing and execution
  • Ansible for Provisioning
    • Using Ansible as a provisioner in Packer and other automation scripts

Chapter 4: Building a Custom EC2 Image with Packer

  • Integrating Ansible with Packer
    • Configuring Ansible roles and playbooks for use with Packer
  • Building the First AMI
    • Creating and configuring Packer templates
    • Provisioning with Ansible and building the AMI

Chapter 5: Setting Up AWS Infrastructure with Terraform

  • Using Packer Images in Terraform
    • How to reference and deploy the custom AMI built with Packer
  • Creating Your AWS Environment
    • Configuring EC2 Instances, VPC, Security Groups
    • Applying Terraform configurations for resource provisioning

Chapter 6: Server Configuration with Ansible

  • Dependencies and Packages Installation
  • Server Environment Configuration
  • Ruby and Rails Installation and Configuration
  • Database Setup and Configuration
    • Automating PostgreSQL Installation
    • Database Security and Tuning

Chapter 7: Configuring Rails Stack on EC2

  • Puma Web Server Setup
    • Automating setup with Ansible
  • Caddy Reverse Proxy Setup
    • Automating installation and SSL configuration with Ansible
  • Redis Integration
    • Installing and configuring Redis for performance and security

Chapter 8: Rails Application Deployment

  • Application Deployment Preparation
    • Setting up the deployment environment
  • Cloning Application Repository
  • Database Setup and Migrations
  • Asset Precompilation
  • Application Startup

Chapter 9: Continuous Integration and Deployment (CI/CD)

  • Setting Up CI/CD Pipelines
    • Building pipelines for automated testing and deployment
  • Implementing Application Monitoring and Logging
    • Tools and strategies for effective logging and monitoring

Chapter 10: Monitoring and Maintenance (Day 2 Operations)

  • Monitoring and Logging Setup
    • Techniques and tools for server and application monitoring
  • Alerts and Notifications Configuration
    • Setting up alerts for system health and performance issues
  • Regular Maintenance Tasks
    • Scheduled tasks for ongoing application and system upkeep
    • Automating Database Backups