Project Guideline DevOps 101
Project Guideline DevOps 101
Project Guideline DevOps 101
Note : If you are looking for complete source code of this project,
then please look at the last page of this document.
Contact : projectdevops101@gmail.com
1|Page
Table of Contents
Section 1: Introduction
1.1 Goal : ......................................................... 3
1.2 Tools used: .................................................... 4
1.3 Tools required for you to deploy the project : ................. 4
1.4 Output : ....................................................... 4
Section 2: Deployment
2.1 Prerequisite ................................................... 5
2.2 Steps to follow : .............................................. 6
2.2.1 Copy the project. ............................................ 6
2.2.2 Create a keypair ............................................. 7
2.2.3 Adding tag in vpc ............................................ 8
2.2.4 Adding tag in subnet ......................................... 9
2.2.5 Adding IAM User : ........................................... 11
2.2.6 Adding IAM Role : ........................................... 13
2.2.7 update MY_UNIQUE_BUCKET ..................................... 16
2.2.8 Create a s3 bucket for logs ................................. 17
2.2.9 Commit and push the code to master branch ................... 19
Section 3: Output
3.1 Gitlab Pipeline. .............................................. 20
3.2 AWS EC2 : ..................................................... 20
3.3 Sample Website : .............................................. 21
2|Page
1.1 Goal :
We will will deploy the website on your EC2 machines with stages
such as DEV, TEST, ACCEPTANECE, PRODUCTION.
You can deploy the Website on DEV, TEST, ACCEPTANCE, PRODUCTION
environment with the help of a button in Gitlab UI.
3|Page
Docker image for implementing gitlab runner (Please find source code
in dockerfile under Runner folder in project). We use this image as
a gitlab runner. We have mentioned our gitlab runner under
.gitlab.ci file under CONTAINER_IMAGE value.
User_data.sh file under terraform -> dev-app will work as a userdata
for our ec2 instance, means when ec2 instance will get launched
user_data.sh file will install all required software’s to run the
website on ec2 machine. You can see the user_data.sh file logs by
right clicking on ec2 instance -> Instance settings -> Get system
logs.
1.4 Output :
The below Devops pipeline will get created in your (free tier)own
gitlab account. You will be deploy sample site of centos on your ec2
(AWS free tier machine) instance in your own AWS account.
4|Page
1) DevOps pipeline in Gitlab account to deploy website on your
AWS account.
Section 2 : Deployment
2.1 Prerequisite
5|Page
2) AWS Account (Free tier)
Create a Amazon Web services account.
Please create a new account (https://aws.amazon.com/console/)with
new mail Id to avoid conflicts if you already have one.
6|Page
2.2.2 Create a keypair
7|Page
2.2.3 Adding tag in vpc
8|Page
Note : Do not include “” in tags.
9|Page
Key : Zone
Value : data
Now select any other subnet from remaining two subnets and
Add the following tag.
Tag in subnet.
Key : Zone
Value : trusted
10 | P a g e
2.2.5 Adding IAM User :
Once you create the IAM user at the end it will show a Download option of
your aws_access_key_id and aws_secret_access_key
credentials file. Please download this file and save at a safe
location.
11 | P a g e
12 | P a g e
2.2.6 Adding IAM Role :
Create role awsrunner and give below permission.
Please keep the role name as awsrunner only else code will not work.
Replace the role arn and aws access and secret key in code.
13 | P a g e
14 | P a g e
15 | P a g e
2.2.7 update MY_UNIQUE_BUCKET
Update MY_UNIQUE_BUCKET in state_pipeline_state.sh.
Go to Intellije where you have imported the project and now open the
file under scripts -> setup_pipeline_state.sh
In file setup_pipeline_state.sh change the value of variable
MY_UNIQUE_BUCKT to your name.
Why are we doing this step?
Because every single s3 bucket in AWS accounts is unique. We can not
create same bucket names in different accounts as well. So to
differentiate between the same buckets we are attaching a variable
to bucket name. Remove the text devops-101 and put your name over
there.
For e.g. your name is john, then change the line in file
setup_pipeline_state.sh as below.
export MY_UNIQUE_BUCKET=john
This way we are differentiating between all same names for the s3 buckets.
bucket = "dev-app-tf-state-dev-devops-101"
kms_key_id = "alias/dev-app-tf-state-dev-devops-101"
bucket = "dev-app-tf-state-dev-john"
kms_key_id = "alias/dev-app-tf-state-dev-john"
Make sure in both the files you use same and exact name. Else code will not
work.
16 | P a g e
2.2.8 Create a s3 bucket for logs
17 | P a g e
Attach the below policy for your bucket.
{
"Version": "2012-10-17",
"Id": "AWSConsole-AccessLogs-Policy-1572879529428",
"Statement": [
{
"Sid": "AWSConsoleStmt-1572879529428",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::156460612806:root"
},
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::dev-app-tf-state-dev-devops-
101-logs/prefix/AWSLogs/<Change_AC_id_here>/*"
}
]
}
18 | P a g e
2.2.9 Commit and push the code to master branch
Now follow the instructions written under Push an existing folder
19 | P a g e
Section 3 : Output
3.1 : Gitlab Pipeline.
Now go to your gitlab account -> Projects -> Your Project Name ->
CI / CD -> Pipelines -> Click on the pipelines.
In stages you will see the logs. (Refer image below)
20 | P a g e
that you will see a description -> Under description you will see
field Public DNS (IPv4)-> Copy the value
In the attached folder named DevOps-101, you can find the sample
Code of the project.
If you are looking for the complete source code of the below is
the cost sheet.
Complete DevOps 101 Project
- Including one hour Skype support if project is not working.
21 | P a g e
4.3 Questions or Feedback:
If you have any Questions or feedback/suggestions, then feel
22 | P a g e