CI/CD stands for Continuous Integration and Continuous Deployment. It is a process that automates the building, testing, and deployment of software. This helps to ensure that software is always in a releasable state and that any changes made to the code are quickly and reliably deployed to production.
A CI/CD pipeline typically consists of the following steps:
- Source control: The code is stored in a source control repository, such as GitHub or GitLab.
- Build: The code is built into a deployable artifact, such as a Docker image or a JAR file.
- Test: The artifact is tested to ensure that it works as expected.
- Deploy: The artifact is deployed to a production environment.
By automating these steps, CI/CD can help to improve the quality and reliability of software. It can also help to speed up the development process by reducing the amount of manual work required.
Here is a simple example of a CI/CD pipeline principle:
- A developer makes a change to the code in a source control repository.
- A CI/CD tool, such as GitHub Actions, automatically builds the code and runs tests.
- If the tests pass, the CI/CD tool deploys the code to a staging environment.
- A QA engineer tests the code in the staging environment.
- If the QA engineer approves the code, the CI/CD tool deploys the code to production.
Tech Used
- GitHub: A widely used web platform for version control and collaboration, enabling seamless code management and team collaboration.
- Amazon S3: A scalable cloud storage service by AWS, allowing you to store and retrieve data, host websites, and manage files securely.
- AWS CodeCommit: A managed source control service that provides secure and scalable hosting for private Git repositories.
- AWS CodeBuild: A fully managed CI/CD service that compiles, tests, and packages code, automating the build process and ensuring code quality.
- AWS CodePipeline: An automated CI/CD service that orchestrates and visualizes the software delivery process, seamlessly integrating various stages.
- AWS CodeDeploy: An automated deployment service that simplifies code releases to various computing environments, ensuring consistent and reliable updates.
Step 01. Create S3 bucket to store build files
Before you start hosting your static website, you’ll need to make an S3 bucket. Here’s what you do:
- Go to the AWS Management Console and open the Amazon S3 section at this link: https://console.aws.amazon.com/s3/
- Click on “Create bucket”
- Give your bucket a unique name
- Choose the place (Region) where you want the bucket to be
- In the part that talks about stopping the public from seeing your stuff, uncheck the box that says “Block all public access”
- Keep the rest of the settings as they are, and make the bucket by clicking “Create”
Step 2. Using S3 Bucket for Hosting
- Click on the bucket you made, then go to the “Properties” part
- Scroll down and click “edit” where it says “Static website hosting”
- Pick the “Enable” choice for Static website hosting
- Put in the names of your index.html and error.html files
- Keep the other stuff that’s already there and press “Save changes” to finish.
Step 3. Grant public read access to the bucket (Important)
To make your S3 bucket accessible and prepare for the next step, follow these instructions:
- Open your S3 bucket settings and find the “Permissions” section.
- Look for “Bucket Policy” and click on it.
- In the “Bucket Policy” section, you’ll see an option called “Policy Generator.” This tool helps you create a policy that defines who can access your bucket and how. Here’s what you do:
- Inside the “Policy Generator,” find the specific action called “GetObject.” This action is about getting files from your bucket.
- Create a policy by selecting this action and generating a code for it. You will see that AWS will autogenerate some code for you. This process is very important, therefore make sure to perform this activity with high precision, else your bucket won’t be able to be consumed by other AWS applications or services
- Now, go back to the Permissions tab, and paste below code code into the policy section.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Statement1",
"Effect": "Allow",
"Principal": "*",
"Action": [
"s3:GetObject",
"s3:PutObject",
"s3:PutObjectAcl",
"s3:DeleteObject",
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::serverless-react-1/*",
"arn:aws:s3:::serverless-react-1"
]
}
]
}
If you’re following along with a project, make sure to change a part of the code (ARN) to match the name of your bucket.
And don’t forget to add “/*” after your bucket name, this will set up every file available in the bucket for public access
7. Click on Save button available on the console
As you can see from the image above, the bucket created is having public visibility now
Step 4. Using AWS CodePipeline with GitHub
- Go to the AWS console and search for CodePipeline.
- Click on Create Pipeline and give your pipeline a name. Then, click Next.
3. To connect CodePipeline to GitHub, follow these steps:
- Open the Developer Tools console at https://console.aws.amazon.com/codesuite/settings/connections.
- Under “Select a provider,” choose “GitHub.”
- Click “Connect to GitHub” and follow the instructions.
4. Once GitHub is connected, go back to CodePipeline and do the following:
- Under “Source provider,” choose “GitHub (Version 2).”
- In the dropdown menu, select the GitHub connection that you just created.
- Select the name of the repository that holds your project’s source code.
- Select the branch name that you want to use for the pipeline.
- Click Next.
5. For building, choose AWS CodeBuild and click Create Project. Follow the instructions given on the page to create a CodeBuild project.
6. In the Deploy section, select the deployment target. This could be an Amazon EC2 instance, an Amazon ECS service, or an Amazon S3 bucket.
Click Create to create the CI/CD pipeline.
Once the CI/CD pipeline is created, it will automatically trigger a build whenever there are changes to the source code in your GitHub repository. The build artifacts will then be deployed to the deployment target (S3 Bucket) that you have specified.
Step 5. AWS CodeBuild
AWS CodeBuild is a powerful tool that takes care of building and testing software smoothly. It works like a silent partner, managing all the technical details so developers can focus on writing great code. It easily connects with popular code storage places like GitHub, making teamwork a breeze. No matter how big your project gets, CodeBuild can handle it — like a dependable teammate that steps up when needed. And it keeps clear records of what it’s doing, helping you understand and fix any issues.
In essence, AWS CodeBuild is your reliable companion in the coding world, ensuring your software is built and tested flawlessly.
- Enter all the required information on this page in accordance with the S3 bucket that we created before
2. Click on ‘Create Build’ project button and then navigate to AWS Pipeline page
Step 6. CodeDeploy
In the deployment step, opt for your S3 bucket, just as illustrated in the image provided
Review the information provided
Click on ‘Create Pipeline’
After a while you will see the above message on the screen, make sure the pipeline runs successfully for all the steps created above
Visit the Deployed Website
To proceed, begin by opening a new tab in your web browser and navigate to the AWS S3 section.
Once there, find your designated S3 bucket and click on its name to access its settings. Within the bucket, locate and click on the ‘Properties’ option. As you scroll down the page, you’ll come across the ‘Static website hosting’ section.
Here, you’ll find a link labeled as the Bucket website endpoint. This link acts as a virtual pathway to your hosted content, providing a seamless way to explore your online creation, and you can click on that link to access your webpage
You can test your CI CD pipeline by making changes to your code files and committing them to GitHub repository
In conclusion, we’ve embarked on a comprehensive journey to establish a robust CI/CD pipeline using the powerful tools provided by AWS. By seamlessly integrating GitHub, AWS CodeBuild, AWS CodePipeline, and Amazon S3, we’ve harnessed the ability to automate and streamline every stage of our software development process