Capstone Project - Banking and Finance Project-updated
Capstone Project - Banking and Finance Project-updated
Capstone Project - Banking and Finance Project-updated
# apt-get update
# apt-get install awscli -y
# aws configure
Give the valid access key
Give the valid secret key
- Press enter, no need to give any region and format
option.
}
resource "aws_vpc" "my-vpc" {
cidr_block = "10.0.0.0/16"
tags = {
Name = "my-vpc"
}
route_table_id = aws_route_table.my-route-table.id
destination_cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.gw.id
}
variable "sg_ports" {
type = list(number)
default = [8080,80,22,443]
}
resource "aws_security_group" "my-sg" {
name = "sg_rule"
vpc_id = aws_vpc.my-vpc.id
dynamic "ingress" {
for_each = var.sg_ports
iterator = port
content{
from_port = port.value
to_port = port.value
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
}
egress {
from_port =0
to_port =0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_instance" "myec2" {
ami = "ami-0166fe664262f664c"
instance_type = "t2.medium"
key_name = "web-key"
subnet_id = aws_subnet.subnet-1.id
security_groups = [aws_security_group.my-sg.id]
tags = {
Name = "Terrafrom-EC2"
}
provisioner "remote-exec" {
connection {
type = "ssh"
user = "ubuntu"
private_key =
tls_private_key.mykey.private_key_pem
host = self.public_ip
}
inline = [
"sudo apt update",
"sudo apt install software-properties-common",
"sudo add-apt-repository --yes --update
ppa:ansible/ansible",
"sudo apt install ansible -y"
]
}
}
- Now lets run the code to verify the infrastructure.
# terraform inti
pipeline{
agent any
tools{
maven 'mymvn'
}
stages{
stage('Clone repo')
{
steps{
git 'https://github.com/saransh-vijayvargiya/banking-
finance-Project1.git'
}
}
stage('Test Code')
{
steps{
sh 'mvn test'
}
}
stage('Build Code')
{
steps{
sh 'mvn package'
}
}
}
}
- Build is now success.
Step 4: Containerize and implement microservice
architecture
- We will write a dockerfile and save it in the github
repo
stage('Build Image')
{
steps{
sh 'docker build -t banking-finance-Project1 .'
}
}
- Now build the code.
# wget
https://github.com/prometheus/prometheus/release
s/download/v3.0.0/prometheus-3.0.0.linux-
amd64.tar.gz
[Service]
User=prometheus
Group=prometheus
Type=simple
ExecStart=/usr/local/bin/prometheus \
--config.file /etc/prometheus/prometheus.yml \
--storage.tsdb.path /var/lib/prometheus/ \
--web.console.templates=/etc/prometheus/consoles \
--
web.console.libraries=/etc/prometheus/console_libra
ries
[Install]
WantedBy=multi-user.target
- Reload systemd:
#sudo systemctl daemon-reload
[Service]
User=node_exporter
Group=node_exporter
Type=simple
ExecStart=/usr/local/bin/node_exporter
[Install]
WantedBy=multi-user.target
scrape_interval: 5s
static_configs:
- targets:
['<Server_IP_of_Node_Exporter_Machine>:9100']
- After changes any configuration file we need to
restart our prometheus
#sudo systemctl restart prometheus.service
Output:
1. In order to make ansible configuration in the
Jenkins.
2. Goto Dashboard > Manage Jenkins > install plugins
> Install the Ansible Plugin
agent any
tools{
maven 'mymvn'
}
stages{
stage('Clone Repo')
{
steps{
git 'https://github.com/saransh-
vijayvargiya/banking-finance-Project1.git'
}
}
stage('Test Code')
{
steps{
sh 'mvn test'
}
}
stage('Build Code')
{
steps{
sh 'mvn package'
}
}
stage('Build Image')
{
steps{
sh 'docker build -t myproject1:1.0 .'
}
}
withCredentials([string(credentialsId:
'DOCKER_HUB_PASWD', variable:
'DOCKER_HUB_PASWD')])
{
sh 'docker login -u saranshvijayvargiya -p
${DOCKER_HUB_PASWD} '
}
sh 'docker tag myproject1:1.0
saranshvijayvargiya/myproject1:latest '
sh 'docker push
saranshvijayvargiya/myproject1:latest'
}
}
stage('Run Ansible Playbook') {
steps {
script {
// Install Ansible if it's not already
installed (skip if already installed)
sh '''
sudo apt-get update
sudo apt-get install -y ansible
'''
}
}
Now save and click on build.