Skip to content

Jenkins server on EC2 instance with Ansible and Packer provisioned by Terraform

Notifications You must be signed in to change notification settings

hoaraujerome/devops_cicd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DEVOPS Project: Jenkins As Code with CI/CD pipeline from scratch

Goal

Deploy a containerized API into a staging environment in a public cloud automatically whenever new commits are integrated into the main branch.

Stack:

  • Cloud Platform: AWS
  • Code Hosting Platform: GitHub
  • CI/CD Tool: Jenkins with Jenkins Pipeline
  • Infrastructure Management Tool: Terraform
  • Configuration Management Tool: Ansible
  • Image Management Tool: Packer
  • Container Build Tool: Docker
  • API: Express.js
  • Staging Environment for Jenkins: EC2 instance
  • Staging Environment for API: ECS Fargate with ALB and application auto-scaling

Overview: Overview

Part 1: Jenkins server on AWS EC2 instance

a) Create a Jenkins machine image With Packer and Ansible

Packer

Image Content

  • Amazon Linux 2 AMI (HVM)
  • Ansible
  • Terraform
  • Jenkins with plugins ("GIT", "Pipeline", and "Pipeline: AWS Steps") + AWS Credentials + 1 Jenkins Job for the API
  • Docker
  • AWS CLI

Prerequisites

  • AWS CLI profile named devops_cicd (see "profile" in the packer configuration). Permission needed: EC2.
  • If the user devops_cicd has no default vpc, set a VPC and subnet IDs manually in the packer configuration.

Usage

./packer/build.sh <jenkins_user_aws_access_key_id> <jenkins_user_aws_secret_access_key>

Note: the access key will be replaced by an IAM role soon

b) Deploy a Jenkins server on AWS with Terraform

Terraform

Prerequisites

Usage

./terraform/run.sh staging init
./terraform/run.sh staging deploy

Part 2: Containerized API deployment with Jenkins Pipeline

See the repository devops_demoapp.