Terraform and Jenkins scripts to setup AWS Elastic Beanstalk with dockerized load-balanced NodeJS app.
- Build a Docker image with Node APP;
- Publish a Docker image on Docker Registry;
- Create a Clound Computing environment on Amazon Web Server;
- Store Elastic Beanstalk environment informations on AWS S3;
- Setup the AWS Elastic Beanstalk Application with NodeJS, Elastic Loadbalancer to forward HTTP
https://github.com/psgabriel/terraform_beanstalk_container_node_test
https://github.com/nodejs/nodejs.org.git
❗ General requirements:
- Host with Linux Operational System;
- Internet Access;
- Wget, Git, Docker, Docker-compose, Terraform and Jenkins installed;
- Intermediate knowledge on System Integrations, Cloud Computing, Application Deployment and basic understanding about Continous Integration.
Item | Resource | Chain Resource |
---|---|---|
Docker Image Build | node_stg:latest | |
Docker Image Publish | psgabriel/node_stg | |
AWS static resources | VPC, IAM | Security Group, Subnet, Internet Gateway, Route |
AWS dinamic resources | Beanstalk, S3 | Autoscaling and Loadbalancer Policies |
- Instance Type: t2.micro
- AWS Region: us-east-1
- Type: Loadbalanced
- Autoscalling Instances: min 2
- Autoscalling Instances: max 4
- Autoscalling Threshold: NetworkIn > 18000000 bytes / 5min
- Solution Stack: 64bit Amazon Linux 2018.03 v2.12.14 running Docker 18.06.1-ce
- Deployment Policies: Health, Immutable or Rolling
Without automation or Continous Integration
- Clone Node JS App Source from https://github.com/nodejs/nodejs.org.git
- Use the Dockerfile from this project
- Dockerfile Content:
- Build a new Docker image
In this example it was used the Docker Hub repository, but you can choose AWS or Azure Registry, Artifactory, Nexus, etc.
Note that the CNAME is set with the Web Server Beanstalk URL from Node APP environment
Automatic process to build, publish and deploy AWS resources with Jenkins.
- From a previous Jenkins instalation, create a new pipeline item based on https://github.com/psgabriel/terraform_beanstalk_container_node_test repository. Set the Jenkinsfile on Script Path field.
- Checkout SCM - Jenkinsfile read
- Get App - Get NodeAPP Source
- Docker Image Build - Prepare dockerized image
- Docker Hub Publish - Upload Docker image to Dockerhub
- Terraform Init - Terraform initilization
- Terraform Plan - Prepare detailed AWS information about Beanstalk
- AWS Resource buil - Beanstalk Contruction
- AWS Destroy - Beanstalk delete, if necessary
- Post Actions - Slack notification for Successed or Failed jobs
- The Beanstalk Environment URL will be sent to Slack channel.
CNAME: node-stg-blue.6xrmtp9nxv.us-east-1.elasticbeanstalk.com
- Linux SO - https://www.linux.org/
- Github - http://github.com
- NodeJS - https://nodejs.org/en/
- Docker - https://www.docker.com/
- AWS - https://aws.amazon.com
- AWS CLI - https://aws.amazon.com/cli/
- Terraform - https://www.terraform.io/
- Jenkins - https://jenkins.io/