CI/CD pipeline on AWS (Part - 4) CodePipeline

CI/CD pipeline on AWS (Part - 4) CodePipeline

Day 53 of 90daysofdevops

ยท

4 min read

What is CodePipeline?

  • CodePipeline builds, tests, and deploys your code every time there is a code change, based on the release process models you define. Think of it as a CI/CD Pipeline service. It allows you to automate the release process for your applications by defining a series of stages and actions.

  • CodePipeline integrates with other AWS services, such as CodeCommit, CodeBuild, and CodeDeploy, as well as third-party tools, to enable end-to-end software delivery pipelines.

Key features of AWS CodePipeline

  1. Pipeline Definition: You can define a series of stages and actions to orchestrate the release process for your application.

  2. Integration with AWS Services: CodePipeline integrates with various AWS services, including source code repositories (CodeCommit, GitHub, etc.), build services (CodeBuild), deployment services (CodeDeploy, Elastic Beanstalk, etc.), and testing services (AWS Device Farm, etc.).

  3. Extensibility: You can extend CodePipeline's capabilities by integrating with third-party tools and services using custom actions or AWS Lambda functions.

  4. Visual Workflow: CodePipeline provides a visual representation of your release process, making it easy to understand and troubleshoot your pipelines.

  5. Artifact Management: CodePipeline handles the management and versioning of artifacts (e.g., source code, build artifacts) throughout the pipeline.

  6. Security and Permissions: CodePipeline integrates with AWS Identity and Access Management (IAM) to manage user permissions and access controls for pipeline actions.


Task-01 :

  • Create a Deployment group of Ec2 Instance.

  • Create a CodePipeline that gets the code from CodeCommit, Builds the code using CodeBuild and deploys it to a Deployment Group.


Create a Deployment group of Ec2 Instance.

  • In CodeDeploy, go to Applications and click on 'Create application'.

  • The application is successfully created.

  • Create a service role for enabling communication between code deployment and other AWS services.

    Go to the IAM service and create 'code-deploy-service-role' with permissions.

    "AmazoneEC2FullAccess", "AmazoneS3FullAccess", "AWSCodeDeployRole", "AmazoneEC2RoleforAWSCodeDeploy", "AWSCodeDeployFullAccess", "AmazonEC2RoleforAWSCodeDeployLimited".

  • Create an Ubuntu EC2 instance:

  • Create a deployment group:

  • Add a deployment group name and choose 'Service role'.

  • Add instance name.

  • A deployment group is created.

  • Install the CodeDeploy agent in the EC2 insatnce:

    You can install the CodeDeploy agent by running the following script on your EC2 instance:

        #!/bin/bash 
        # This installs the CodeDeploy agent and its prerequisites on Ubuntu 22.04.  
        sudo apt-get update 
        sudo apt-get install ruby-full ruby-webrick wget -y 
        cd /tmp 
        wget https://aws-codedeploy-us-east-1.s3.us-east-1.amazonaws.com/releases/codedeploy-agent_1.3.2-1902_all.deb 
        mkdir codedeploy-agent_1.3.2-1902_ubuntu22 
        dpkg-deb -R codedeploy-agent_1.3.2-1902_all.deb codedeploy-agent_1.3.2-1902_ubuntu22 
        sed 's/Depends:.*/Depends:ruby3.0/' -i ./codedeploy-agent_1.3.2-1902_ubuntu22/DEBIAN/control 
        dpkg-deb -b codedeploy-agent_1.3.2-1902_ubuntu22/ 
        sudo dpkg -i codedeploy-agent_1.3.2-1902_ubuntu22.deb 
        systemctl list-units --type=service | grep codedeploy 
        sudo service codedeploy-agent status
    

  • Install the Code agent using the bash command.

  • We can verify the status of Code Agent is active or not.


Create a CodePipeline that gets the code from CodeCommit, Builds the code using CodeBuild and deploys it to a Deployment Group.

  • Go to the CodePipeline console. Click "Create pipeline."

  • Provide a name for your pipeline. And select on "Create a new Service Role".

  • Under "Source provider," choose "AWS CodeCommit."

    Select the repository and branch you want to deploy then click "Next."

  • Under "Build provider," choose "AWS CodeBuild."

    Select the build project name and then click on "Next."

  • Under "Deploy provider," choose "AWS CodeDeploy."

    Select the deployment group you created earlier and click on "Next."

  • Review the pipeline details and click "Create pipeline."

  • The pipeline will automatically trigger a build and deploy the new code to the EC2 instance.

  • Successfully created a CodePipeline that automates the deployment process.

  • Browse your instance public-IP address, you can see the final output of index.html


Thank You,

I want to express my deepest gratitude to each and every one of you who has taken the time to read, engage, and support my journey.

Feel free to reach out to me if any corrections or add-ons are required on blogs. Your feedback is always welcome & appreciated.

~ Abhisek Moharana ๐Ÿ™‚

ย