Implementing CI_CD_pipeline_in_AWS
Implementing CI_CD_pipeline_in_AWS
1. GitHub
GitHub is a cloud-based platform that provides version control and
collaboration features for developers. It is built around Git, a distributed
version control system, and offers tools to manage, review, and share code.
Features
(i) Version Control
o GitHub uses Git to track changes in your code over time.
o Allows developers to roll back changes, merge updates, and
maintain a history of their work.
(ii) Collaboration
o Teams can work together on projects using branches and pull
requests.
o Facilitates code reviews, discussions, and feedback through
comments.
(iii) Repository Hosting
o Stores code repositories in the cloud, making them accessible from
anywhere.
o Supports public repositories (open-source projects) and private
repositories (restricted access).
(iv) Integration with DevOps Tools
o Works with CI/CD tools like GitHub Actions, Jenkins, Travis CI, and
AWS CodePipeline for automated workflows.
(v) GitHub Actions
o Automates workflows like testing, building, and deploying code.
o Allows you to create custom workflows directly within GitHub.
(vi) Project Management
o Includes features like Kanban boards, milestones, and issues to
track progress.
o Helps teams stay organized and plan their work efficiently.
(vii) Open Source Community
o Hosts a vast number of open-source projects, making it a hub for
collaboration and innovation.
o Enables developers to contribute to and learn from global
communities.
2. AWS CodeBuild
• AWS CodeBuild is a fully managed continuous integration (CI) service
provided by AWS.
• It compiles source code, runs tests, and produces software packages ready for
deployment.
• Pay-as-you-go pricing model: You are charged by the minute for the compute
resources used during the build process.
o Example:
▪ Assume you run a build that takes 10 minutes on a small build
instance (e.g., build.general1.small), which costs $0.005 per
build minute.
▪ Cost for this build = 10 minutes × $0.005 = $0.05.
▪ If a larger instance is used, the per-minute rate increases,
reflecting the additional compute resources.
buildspec.yml
• A buildspec.yml file is a YAML-formatted file containing build commands and
related settings used by CodeBuild to run a build.
• It is essential for defining build instructions, which CodeBuild interprets to
execute the CI/CD pipeline.
Structure of buildspec.yml
1. versions
Specifies the version of the build specification that CodeBuild should use.
2. phases
Defines the stages of a build. Each phase can include multiple commands
executed sequentially.
Phases in CodeBuild:
(i) install: Set up dependencies or tools required for the build.
for eg
install:
commands:
- npm install
- apt-get update && apt-get install -y zip
(ii) pre_build: Run preliminary tasks, such as downloading dependencies or
preparing the environment.
for eg
pre_build:
commands:
- echo Preparing build environment
- pip install -r requirements.txt
(iii) post_build: Perform cleanup, deployment, or notification tasks after the
main build.
for eg
post_build:
commands:
- echo Build complete
- aws s3 cp target/my-app.jar s3://my-bucket/
3. artifacts
Specifies the files and directories to save or export after the build is complete.
for eg
artifacts:
files: - "**/*"
base-directory: build/output
4. environment_variables
Defines environment variables used during the build process.
Environment variables can store sensitive information or configuration values.
for eg
env:
variables:
ENV: production
API_KEY: abc123
Important Notes
(i) The buildspec.yml file:
o Must be named buildspec.yml by convention if placed at the root of
your source directory.
o Alternatively, you can specify its path in the CodeBuild project settings.
(ii) Advantages of CodeBuild:
o Scalable: Automatically scales to match the size of your build.
o Integrates with AWS services: Seamlessly integrates with CodePipeline,
S3, and IAM.
o Customizable environment: You can use a predefined build
environment or create your own Docker image for specific needs.
(iii) Common Mistakes:
o Forgetting to specify a version or an incorrect version number in the
buildspec file.
o Missing phases like install or build, causing build failures.
3. AWS CodeDeploy
AWS CodeDeploy is a fully managed deployment service that automates the process
of deploying code to various environments, such as:
• Amazon EC2 instances
• AWS Lambda functions
Features
1. Automated Deployments
o Ensures consistent and reliable software updates.
o Helps maintain application uptime during deployments.
2. Avoids Downtime
o Designed to deploy applications without disrupting live users
(depending on deployment strategy).
3. Rollback Support
o Automatically reverts to the previous version if an error or issue is
detected during deployment.
o Ensures that your application remains stable.
AppSpec.yml
This is a YAML file that defines your deployment configuration and is central to how
CodeDeploy operates:
• Purpose: Specifies the commands to run at each deployment phase.
• Usage: Used by the system during the deployment process to manage lifecycle
events.
• Lifecycle Events: Helps manage deployment as a series of steps, such as pre-
deployment, deployment, and post-deployment tasks.
4. AWS CodePipeline
AWS CodePipeline is a service designed to automate the entire process of building,
testing, and deploying applications, ensuring faster and more reliable delivery.
Features
1. Supports Continuous Deployment
o Combines Continuous Integration (CI) and Continuous Deployment (CD)
for efficient and reliable updates.
o Ensures that infrastructure changes and code updates are tested and
deployed seamlessly.
2. Automated Workflow
o Automatically builds, tests, and deploys code whenever changes are
made.
o Reduces manual intervention, speeding up the release process.
3. Integration with AWS Services
o Works well with services like:
▪ CodeCommit (version control)
▪ S3 (storing build artifacts)
▪ CodeDeploy (deploying updates)
▪ Elastic Beanstalk (managing environments)
4. User-Friendly Creation
o Pipelines can be created using:
▪ Graphical User Interface (GUI) for simplicity.
▪ Command Line Interface (CLI) for flexibility and scripting.