Skip to content

About

This CI/CD pipeline builds, and deploys a docker image of the random-actor repository into Elastic Beanstalk; as test environment, and then into EC2 instances, provisioned by an ASG and fronted by an ALB; as production environment.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

57 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

AWS CI/CD Pipeline with Terraform

This repository provisions a complete delivery path for the random-actor Flask application on AWS.

The final architecture is intentionally focused on one deployment model: Docker on EC2, delivered through CodePipeline and CodeDeploy.

tabebill/random-actor
        |
        v
   CodePipeline
        |
        v
    CodeBuild
  - builds Docker image
  - pushes image to ECR
  - packages CodeDeploy bundle
        |
        v
 Manual approval
        |
        v
    CodeDeploy
        |
        v
 EC2 Auto Scaling Group
        |
        v
 Application Load Balancer

The Flask app listens on port 5001 inside the container. During deployment, the container is started with an 80:5001 mapping so the Application Load Balancer can serve it over HTTP on port 80.

What this project creates

Terraform provisions:

  • a VPC with two public subnets
  • an Application Load Balancer, listener, and target group
  • an EC2 Auto Scaling Group with Docker and the CodeDeploy agent installed
  • an ECR repository for application images
  • CodeBuild, CodeDeploy, and CodePipeline resources
  • an S3 artifact bucket and DynamoDB lock table
  • the IAM roles and policies needed by the pipeline and EC2 instances
  • a CodeStar connection resource for GitHub integration

Deployment flow

  1. A change is pushed to the random-actor branch of tabebill/random-actor.
  2. CodePipeline pulls the application source through the GitHub connection.
  3. CodeBuild:
    • builds the Docker image,
    • pushes it to ECR,
    • creates a CodeDeploy revision bundle containing:
      • appspec.yml
      • image.env
      • deployment scripts
  4. A manual approval stage pauses the release.
  5. CodeDeploy deploys the approved image to the EC2 Auto Scaling Group.
  6. The Application Load Balancer routes traffic to the running containers.

Repository layout

.
├── .github/workflows/deploy.yml
├── terraform/
│   ├── main.tf
│   ├── locals.tf
│   ├── outputs.tf
│   └── modules/
│       ├── codepipeline/
│       ├── ec2-codedeploy/
│       ├── image-codebuild/
│       ├── tf-state/
│       └── vpc/

Prerequisites

Before applying the Terraform, you need:

  • an AWS account with permissions to create IAM, EC2, ALB, ECR, S3, DynamoDB, CodeBuild, CodeDeploy, CodePipeline, and CodeStar Connection resources
  • Terraform installed locally
  • AWS credentials configured locally, or AWS credentials added as GitHub Actions secrets:
    • AWS_ACCESS_KEY_ID
    • AWS_SECRET_ACCESS_KEY

Deploying the infrastructure

From the repository root:

cd terraform
terraform init
terraform plan
terraform apply

After the first apply:

  1. Open the AWS console.
  2. Find the newly created CodeStar connection.
  3. Complete the pending GitHub authorization flow.
  4. Make sure the connection can access tabebill/random-actor.

The CodeStar connection is created by Terraform, but AWS still requires the GitHub authorization handshake to be completed manually once.

GitHub Actions

The workflow in .github/workflows/deploy.yml runs Terraform when changes are pushed to this repository's cicd branch.

Useful outputs

After a successful apply, Terraform returns:

  • alb_dns_name — public DNS name of the load balancer
  • ecr_repository_url — ECR repository used for application images
  • codestar_connection_arn — GitHub connection ARN created for CodePipeline

Notes

  • The pipeline source is the application repository, not this Terraform repository.
  • Elastic Beanstalk is not part of the final design.
  • The deployment bundle is generated during the CodeBuild stage so the exact image that was built is the image CodeDeploy later rolls out.

About

This CI/CD pipeline builds, and deploys a docker image of the random-actor repository into Elastic Beanstalk; as test environment, and then into EC2 instances, provisioned by an ASG and fronted by an ALB; as production environment.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages