Code Monkey home page Code Monkey logo

brikis98 / infrastructure-as-code-talk Goto Github PK

View Code? Open in Web Editor NEW
563.0 28.0 166.0 752 KB

Sample code for the talk "Infrastructure-as-code: running microservices on AWS with Docker, ECS, and Terraform"

Home Page: http://www.ybrikman.com/writing/2016/03/31/infrastructure-as-code-microservices-aws-docker-terraform-ecs/

Ruby 38.00% JavaScript 1.20% CSS 1.25% HTML 9.08% HCL 49.07% Shell 1.41%
terraform docker aws microservices talk samples ecs

infrastructure-as-code-talk's Introduction

Infrastructure as Code Talk

This repo contains the sample code for the talk Infrastructure-as-code: running microservices on AWS with Docker, Terraform, and ECS. It includes a couple sample Dockerized microservices and the Terraform code to deploy them on AWS:

Architecture

Note: This repo is for demonstration purposes only and should NOT be used to run anything important. For production-ready version of this code and many other types of infrastructure, check out Gruntwork.

Quick start

Running the microservices locally

To run the rails-frontend and sinatra-backend on your local dev box:

  1. Install Docker.
  2. docker-compose up
  3. Test sinatra-backend by going to http://localhost:4567.
  4. Test the rails-frontend (and its connectivity to the sinatra-backend) by going to http://localhost:3000.

The docker-compose.yml file mounts rails-frontend and sinatra-backend folders as volumes in each Docker image, so any changes you make to the apps on your host OS will automatically be reflected in the running Docker container. This lets you do iterative "make-a-change-and-refresh" style development.

Deploying the microservices in AWS

To deploy the microservices to your AWS account, see the terraform-configurations README.

Using your own Docker images

By default, docker-compose.yml and the terraform-configurations are using the gruntwork/rails-frontend and gruntwork/sinatra-backend Docker images. These are images I pushed to the Gruntwork Docker Hub account to make it easy for you to try this repo quickly. Obviously, in the real world, you'll want to use your own images instead.

Follow Docker's documentation to create your own Docker images and fill in the new image id and tag in:

  1. docker-compose.yml: the image attribute for rails_frontend or sinatra_backend.
  2. terraform-configurations/terraform.tfvars: the rails_frontend_image and rails_frontend_version or sinatra_backend_image and sinatra_backend_version variables.

Overview of the repo

Here's an overview of what's in this repo:

  1. An example sinatra-backend microservice that just returns the text "Hello, World". This app includes a Dockerfile to package it as a Docker container.

  2. An example rails-frontend microservice that makes an HTTP call to the sinatra-backend and renders the result as HTML. This app includes a Dockerfile to package it as a Docker container.

  3. A docker-compose.yml file to deploy both Docker containers so you can see how the two microservices work together in the development environment. To allow the services to talk to each other, we are using Docker Links as a simple "service discovery" mechanism.

  4. Terraform configurations to deploy both Docker containers on Amazon's EC2 Container Service (ECS) so you can see how the two microservices work together in the production environment. To allow the services to talk to each other, we deploy an Elastic Load Balancer (ELB) in front of each service and use Terraform to pass the ELB URLs between services. We are using the same environment variables as Docker Links, so this acts as a simple "service discovery" mechanism that works in both dev and prod.

More info

For more info, check out the talk Infrastructure-as-code: running microservices on AWS with Docker, Terraform, and ECS, including the video and slides. For a deeper look at Terraform, check out the book Terraform: Up & Running.

infrastructure-as-code-talk's People

Contributors

alexwal avatar brikis98 avatar jonatanblue avatar josh-padnick avatar pgilad avatar utf18 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

infrastructure-as-code-talk's Issues

aws_launch_configuration.ecs_instance: missing dependency: data.aws_ami

I followed the instructions for the terraform-template in the README.

However, I'm getting this error when i run terraform plan:

Error configuring: 5 error(s) occurred:

* aws_launch_configuration.ecs_instance: missing dependency: data.aws_ami
* aws_iam_role.ecs_instance: missing dependency: data.aws_iam_policy_document
* aws_iam_role_policy.ecs_cluster_permissions: missing dependency: data.aws_iam_policy_document
* aws_iam_role.ecs_service_role: missing dependency: data.aws_iam_policy_document
* aws_iam_role_policy.ecs_service_policy: missing dependency: data.aws_iam_policy_document

is there anything else that needs to be done to get this running out of the box?

Error while deploying from terraform-templates

Hello,

I have the following error

Error applying plan:

error(s) occurred:

  • aws_launch_configuration.ecs_instance: Error creating launch configuration: ValidationError: AMI cannot be described
    status code: 400, request id: 6dbc0e68-2a6e-11a6-bc65-4121653e6d1a

My bad ...the fix was easy -> I had to add the correct AMI ID on the vars.tf file

Connect to a Service without an ELB?

Brilliant Example!

Sorry I'm really new to this stuff so please close if this doesn't quite make sense; I have a load of misc services in my docker-compose file like redis and freegeoip server and I'd like to add them as tasks - how do I connect to them directly without and ELB... Is there a hostname variable I can use for a service?

Thanks again this has really clarified lots of things for me!

EDIT: I just listened to your excellent talk again and sadly you say each service needs an ALB :-/

issue when running the default code

Hello,

I adapted your code and tried with yours and i still have a issue i don't understand.
The site is not working and i have an issue in the EC2 container management system.
In the ecs cluster, The desired count is what i configured, but the running count and the pending count are at 0. In the autoscaling tab, I have this message : "Scalable Target No Auto Scaling resources configured for this service. Click the update button to configure Auto Scaling for tasks"

Also, when looking at the event tab for the service, there is a message "service rails-frontend was unable to place a task because no container instance met all of its requirements. Reason: No Container Instances were found in your cluster. For more information, see the Troubleshooting section."

Do you have any idea how this issue can be solved ?

Thanks,
Grm

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.