Skip to content

Commit 68f94a1

Browse files
committed
Project description and screenshots added.
1 parent 232f7f3 commit 68f94a1

File tree

15 files changed

+143
-0
lines changed

15 files changed

+143
-0
lines changed

README.md

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
# Automated Deployment Pipeline with GitHub Actions and AWS CodeDeploy
2+
3+
## Introduction
4+
This project sets up an automated deployment pipeline that integrates GitHub Actions and AWS CodeDeploy. The goal is to automate the deployment of a React application to AWS infrastructure, enabling a seamless continuous delivery pipeline. The application is automatically deployed to AWS resources, ensuring secure, scalable, and efficient delivery to production.
5+
6+
## Steps
7+
### Creating Required Resources using Cloud Formation Tempalates
8+
9+
This step involves using AWS CloudFormation templates to create the necessary AWS resources. These resources will host, secure, and deploy the React application.
10+
11+
- Amazon EC2 Linux Instances with CodeDeploy Agent
12+
13+
- Auto Scaling Group with Internet Application Load Balancer
14+
15+
- CodeDeploy Application and Deployment Group
16+
17+
- Amazon S3 Bucket
18+
19+
- IAM OIDC Identity Provider
20+
21+
- EC2 Instance Profile
22+
23+
- Service Role for CodeDeploy
24+
25+
- Security Groups for EC2 and ALB
26+
27+
28+
29+
![Image of CFT Console-1](images/1.png)
30+
31+
![Image of CFT Console-2](images/2.png)
32+
33+
![Image of CFT Console-3](images/3.png)
34+
35+
![Image of CFT Console-4](images/4.png)
36+
37+
Outputs which will be required for the project:
38+
39+
![Image of CFT Console-5](images/5.png)
40+
41+
42+
### Configuring Github Actions Secrets
43+
44+
GitHub Actions requires secret keys and configurations to securely interact with AWS services. You'll need to configure the following GitHub secrets:
45+
46+
- S3 Bucket Name: The name of the S3 bucket where build artifacts will be uploaded.
47+
48+
- IAM Role: The IAM role assumed by GitHub Actions to access AWS resources.
49+
50+
![Image of Github Actions Secrets](images/6.png)
51+
52+
53+
Do the same for IAMROLE_GITHUB.
54+
55+
56+
### Autohorizing Github and AWS Code Deploy
57+
58+
It is required to create a conneciton between AWS Code Deploy and Github.
59+
60+
Navigate to AWS Code Deploy -> Applications page
61+
62+
Click on create a new Deployment and for revision-type select My application is stored in Github and connect to Github.
63+
64+
![Image of Github Connection](images/7.png)
65+
66+
For more details follow the below link:
67+
https://docs.aws.amazon.com/codedeploy/latest/userguide/integrations-partners-github.html#behaviors-authentication
68+
69+
### Creating a Github Actions Workflow with Build and Deploy Steps
70+
71+
The GitHub Actions workflow automates the process of building and deploying the React application. It consists of two main steps:
72+
73+
Build Step:
74+
- Assume GitHub IAM Role: The GitHub Action assumes an IAM role with sufficient permissions to access AWS resources securely.
75+
76+
- Build the React Application: The action installs the dependencies and runs the build process using npm run build.
77+
78+
- Upload Build Artifacts to S3: After the build is complete, the resulting artifacts (e.g., dist/ folder) are zipped and uploaded to an S3 bucket to be used for deployment.
79+
80+
![Image of Build Step](images/11.png)
81+
82+
83+
Deploy Step:
84+
- Assume GitHub IAM Role: The deploy step also assumes the same IAM role to securely interact with AWS.
85+
86+
- Deploy using CodeDeploy: AWS CodeDeploy is triggered, and the application is deployed to the EC2 instances using the artifacts stored in S3.
87+
88+
![Image of Deploy Step](images/12.png)
89+
90+
### Creating the AppSpec File and Related Scripts
91+
92+
The AppSpec file (appspec.yml) defines the deployment process and specifies the location of the build folder as well as scripts for various deployment hooks.
93+
94+
This file is critical for AWS CodeDeploy to know which files to deploy, where to deploy them, and which hooks to run during the deployment lifecycle. It includes the following:
95+
96+
- Source and Destination Paths: Specifies the source folder (e.g., dist/ from the build) and the destination folder on the EC2 instances (e.g., /var/www/html).
97+
98+
- Hooks: Defines deployment hooks that allow for custom actions before, during, and after deployment. This includes:
99+
100+
- AfterInstall: Installs necessary software (e.g., Apache) and sets file permissions.
101+
102+
- ApplicationStart: Starts the application server (e.g., Apache HTTP Server).
103+
104+
Scripts:
105+
- after_install.sh: This script is executed after CodeDeploy copies the files to the target EC2 instances. It installs required software (e.g., httpd), changes ownership and permissions, and prepares the environment for the app.
106+
107+
- start_server.sh: This script starts the web server (e.g., Apache) that serves the React application.
108+
109+
### Triggering the workflow & Observing the Results
110+
111+
Once the pipeline runs, you can monitor the progress and status of the deployment directly through the GitHub Actions interface and AWS CodeDeploy Console. You will see logs related to the build process, deployment process, and any errors that may occur.
112+
113+
On the Code Deploy Console you should see 'Succeeded'.
114+
115+
![Image of Successfuly Deployment](images/12.png)
116+
117+
Access the application from the WebAppUrl from the Cloud Formation Template:
118+
119+
![Image of Build Step](images/12.5.png)
120+
121+
122+
![Image of Deplyoed Application](images/13.png)
123+
124+
## Explanation of Concepts
125+
126+
1. AWS Code Deploy
127+
128+
AWS CodeDeploy is a fully managed deployment service that automates software deployments to a variety of compute services, including Amazon EC2, AWS Lambda, and on-premises instances. In this project, CodeDeploy is used to deploy the React application to EC2 instances by fetching the build artifacts from S3.
129+
130+
Deployment Group: A set of EC2 instances managed by CodeDeploy, which will receive the deployment.
131+
132+
AppSpec File: Specifies the deployment instructions for CodeDeploy, including which files to deploy, where to deploy them, and which lifecycle hooks to run.
133+
134+
2. Github Actions
135+
136+
GitHub Actions is a powerful CI/CD platform that automates workflows in response to various events in your GitHub repository. In this project, GitHub Actions is used to automate the build and deployment pipeline. It allows us to:
137+
138+
Build the React Application: Run build commands (e.g., npm run build) and create the necessary artifacts for deployment.
139+
140+
141+
Upload Artifacts to S3: Automatically upload the build artifacts to an S3 bucket, making them available for deployment.
142+
143+
Trigger AWS CodeDeploy: Use AWS CLI commands within the GitHub Actions workflow to trigger CodeDeploy and deploy the artifacts to EC2 instances.

images/1.png

91.8 KB
Loading

images/10.png

35.6 KB
Loading

images/11.png

21.5 KB
Loading

images/12.5.png

11.1 KB
Loading

images/12.png

29.4 KB
Loading

images/13.png

28.3 KB
Loading

images/2.png

31.7 KB
Loading

images/3.png

50.6 KB
Loading

images/4.png

141 KB
Loading

0 commit comments

Comments
 (0)