My First CI\/CD Pipeline Project: Automating Laravel Deployment on AWS with Jenkins

Project Overview

The project involved setting up my first Continuous Integration and Continuous Deployment (CI/CD) pipeline for a Laravel application using Jenkins on an AWS EC2 instance. The goal was to automate the testing, building, and deployment process to ensure a smooth and efficient workflow for development and production releases.

Project Objectives

  • Automate the Build Process: Ensure that every code commit triggers an automated build process, including running unit tests and linting code.

  • Streamline Deployment: Automatically deploy the application to a staging environment after successful builds, and to production with minimal manual intervention.

  • Ensure Code Quality: Integrate static code analysis and security checks into the CI/CD pipeline to maintain high code quality.

  • Scalability and Reliability: Utilize AWS EC2 to ensure the infrastructure is scalable and reliable.

Technologies and Services Used

  • Laravel: PHP framework used for the application.

  • Jenkins: Automation server used to set up the CI/CD pipeline.

  • AWS EC2: Cloud platform used to host Jenkins and the application.

  • Git: Version control system for source code management.

  • Docker: Used for containerizing the application.

  • Nginx: Web server used in the deployment process.

  • MySQL: Database used by the Laravel application.

Responsibilities

  • Conducted an in-depth assessment of the existing on-premises infrastructure to determine cloud readiness.

  • Designed a scalable and secure architecture using AWS Well-Architected Framework principles.

  • Migrated databases to RDS and DynamoDB using AWS Database Migration Service (DMS), ensuring minimal downtime and data integrity.

  • Configured monitoring and logging using CloudWatch and CloudTrail to ensure compliance and operational visibility.

  • Applied IAM policies and Security Groups to enforce least privilege access and network security.

  • Utilized AWS S3 for cost-effective storage and implemented lifecycle policies for data management.

  • Set up CloudFront for improved security and content delivery performance.

  • Conducted training sessions for the internal team on AWS best practices and cost management strategies.

Project Outcomes

  • Automated Testing and Deployment: Every code commit automatically triggers the Jenkins pipeline, which builds the application, runs tests, and deploys it to a staging environment.

  • Improved Code Quality: Automated tests and static code analysis ensure that only high-quality code is merged and deployed.

  • Efficient Release Management: The CI/CD pipeline has streamlined the release process, making it faster and more reliable.

  • Enhanced Team Productivity: Automation of repetitive tasks has freed up developers to focus on feature development and innovation.

Jenkins Pipeline Example

Here’s an example myJenkinsfile for the CI/CD pipeline

pipeline {

agent any

environment {

AWS_CREDENTIALS = credentials('aws-credentials')

EC2_INSTANCE = 'ec2-instance-ip'

}

stages {

stage('Clone Repository') {

steps {

git 'https://github.com/my-repo/laravel-project.git'

}

}

stage('Install Dependencies') {

steps {

sh 'composer install'

}

}

stage('Run Tests') {

steps {

sh 'php artisan test'

}

}

stage('Deploy to EC2 Instance') {

steps {

sshagent(credentials: ['your-ssh-credentials-id']) {

sh '''

ssh -o StrictHostKeyChecking=no ec2-user@${EC2_INSTANCE} 'cd /path/to/my/laravel/project && \

git pull origin master && \

composer install && \

php artisan migrate --force && \

sudo service apache2 restart'

'''

}

}

}

}

post {

success {

echo 'Deployment successful!'

}

failure {

echo 'Deployment failed.'

}

}

}

Explanation:

  • AWS_CREDENTIALS: Stores the credentials used by Jenkins to access AWS services securely.

  • EC2_INSTANCE: Specifies the IP address or hostname of your EC2 instance.

  • Deployment Stage: Uses SSH to securely access the EC2 instance and execute deployment commands directly on the instance.

  • SSH Command:ssh -o StrictHostKeyChecking=no ec2-user@${EC2_INSTANCE}: SSH into your EC2 instance. 1. cd /path/to/your/laravel/project: Change directory to where your Laravel project is located on the EC2 instance. 2. git pull origin master: Pull the latest changes from your Git repository. 3. composer install: Install PHP dependencies using Composer. 4. php artisan migrate --force: Run database migrations. 5. sudo service apache2 restart: Restart the Apache web server to apply changes.

Latest Projects

Things I do

CLOUD

Amazon Web Services

AZURE Cloud

Google Cloud Platform

IBM Cloud

DevOps Tools

Jenkins

Ansible for software provisioning

Packer for automated machine images

AWS CodePipeline

AWS CodeDeploy

Azure Pipelines

Chef

Github Actions

GitLab CI/CD

CircleCI

Microservices

Kubernetes

Docker

AWS ECS

AWS EKS

AKS

Azure Container Apps

Monitoring and Alerting

Telegraf

Prometheus

Grafana

Pagerduty

Infrastructure as Code

CloudFormation

Terraform

AWS CDK (Python & Typescript)

Operating System

Most of Linux Server Distributions

Window Server 2019/2022

Databases

MySQL

MariaDB

MongoDB

PostgreSQL

MSSQL

Scripting

Shell Scripting

Python

YAML

PowerShell

My Certifications

EMAIL: RAJ412214@GMAIL.COM

Let's Talk

Book a call to talk regarding the current vacancy at your organization.