Skip to content

Commit

Permalink
files added
Browse files Browse the repository at this point in the history
  • Loading branch information
saad946 committed Oct 7, 2023
0 parents commit 6729dbd
Show file tree
Hide file tree
Showing 22 changed files with 1,171 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This is a basic workflow to help you get started with Actions

name: CI

# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches: [ main ]
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

# Runs a single command using the runners shell
- name: Run a one-line script
run: echo Hello, world!

# Runs a set of commands using the runners shell
- name: Run a multi-line script
run: |
echo Add other actions to build,
echo test, and deploy your project
- name: java version
run: java -version
- name: maven version
run: mvn --version
- name: python version
run: python --version
- name: docker version
run: docker -v
- name: terrafrom version
run: terraform --version

33 changes: 33 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/
73 changes: 73 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
pipeline{

agent any

stages {

stage('Git Checkout'){

steps{

script{

git branch: 'main', url: 'https://github.com/vikash-kumar01/mrdevops_javaapplication.git'
}
}
}
stage('UNIT testing'){

steps{

script{

sh 'mvn test'
}
}
}
stage('Integration testing'){

steps{

script{

sh 'mvn verify -DskipUnitTests'
}
}
}
stage('Maven build'){

steps{

script{

sh 'mvn clean install'
}
}
}
stage('Static code analysis'){

steps{

script{

withSonarQubeEnv(credentialsId: 'sonar-api') {

sh 'mvn clean package sonar:sonar'
}
}

}
}
stage('Quality Gate Status'){

steps{

script{

waitForQualityGate abortPipeline: false, credentialsId: 'sonar-api'
}
}
}
}

}
20 changes: 20 additions & 0 deletions Packer-Hasicorp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# packer-crash-course-by-sandip

#Installations:
https://developer.hashicorp.com/packer/downloads?product_intent=packer

# Commands
To init:
packer init <packer template file>
e.g. packer init main.pkr.hcl

To validate packer template:
packer validate <packer template file>
e.g. packer validate main.pkr.hcl

to start image build:
packer build <packer template file>
e.g. packer build main.pkr.hcl

to pass aws vartiaable as params:
packer -var "aws_access_key=$AWS_ACCESS_KEY" -var "aws_secret_key=$AWS_SECRET_KEY"
Empty file.
64 changes: 64 additions & 0 deletions Packer-Hasicorp/jenkins.pkr.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Variables
# variable "aws_access_key" {
# type = string
# }

# variable "aws_secret_key" {
# type = string
# }

locals {
timestamp = regex_replace(timestamp(), "[- TZ:]", "")
}

# Sources (Builders)
source "amazon-ebs" "demo" {
# access_key = var.aws_access_key
# secret_key = var.aws_secret_key
region = "ap-southeast-1"
source_ami = "ami-0df7a207adb9748c7"
instance_type = "t2.large"
temporary_key_pair_type = "ed25519"
ssh_username = "ubuntu"
ami_name = "packer-jenkins-ami-${local.timestamp}"
}

# Builds
build {
sources = [
"source.amazon-ebs.demo",
]

# Provisioners
provisioner "shell" {
inline = [
"sleep 30",
"sudo apt update -y",
"sudo apt upgrade -y",
"sudo apt install openjdk-17-jre -y",
"curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee /usr/share/keyrings/jenkins-keyring.asc > /dev/null",
"echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian-stable binary/ | sudo tee /etc/apt/sources.list.d/jenkins.list > /dev/null",
"sudo apt-get update -y",
"sudo apt-get install jenkins -y",
"sudo apt update -y",
"sudo apt-get install -y ca-certificates curl gnupg",
"sudo install -m 0755 -d /etc/apt/keyrings",
"curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg",
"sudo chmod a+r /etc/apt/keyrings/docker.gpg",
"echo \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo $VERSION_CODENAME) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null",
"sudo apt-get update -y",
"sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin",
"sudo chmod 777 /var/run/docker.sock",
"sudo systemctl start docker",

]
}

# Post-processors
post-processor "manifest" {
output = "manifest.json"
strip_path = true
}
}


50 changes: 50 additions & 0 deletions Packer-Hasicorp/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"builds": [
{
"name": "demo",
"builder_type": "amazon-ebs",
"build_time": 1696270108,
"files": null,
"artifact_id": "ap-southeast-1:ami-01ec76463f70ddab8",
"packer_run_uuid": "f13781a1-7b5e-ac62-3632-c8806a76cfca",
"custom_data": null
},
{
"name": "demo",
"builder_type": "amazon-ebs",
"build_time": 1696436660,
"files": null,
"artifact_id": "ap-southeast-1:ami-0b84c5b716eb1280b",
"packer_run_uuid": "e7e94d82-46a1-fe6e-d02a-08f1525535d3",
"custom_data": null
},
{
"name": "demo",
"builder_type": "amazon-ebs",
"build_time": 1696437577,
"files": null,
"artifact_id": "ap-southeast-1:ami-052f3012262f9a198",
"packer_run_uuid": "f0a0b4cc-feb7-3fe6-0520-dd2cd4ae4c92",
"custom_data": null
},
{
"name": "demo",
"builder_type": "amazon-ebs",
"build_time": 1696441556,
"files": null,
"artifact_id": "ap-southeast-1:ami-0f1679a573e6ee1cb",
"packer_run_uuid": "a32915e3-e0b2-a224-faf3-618865bb4a33",
"custom_data": null
},
{
"name": "demo",
"builder_type": "amazon-ebs",
"build_time": 1696446675,
"files": null,
"artifact_id": "ap-southeast-1:ami-01ca473c0805160e8",
"packer_run_uuid": "240bfb60-2d06-0148-be36-357c4504c768",
"custom_data": null
}
],
"last_run_uuid": "240bfb60-2d06-0148-be36-357c4504c768"
}
83 changes: 83 additions & 0 deletions Packer-Hasicorp/multi-cloud.pkr.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Variables
variable "aws_access_key" {
type = string
}

variable "aws_secret_key" {
type = string
}

variable "gcp_project_id" {
type = string
}

variable "gcp_account_file" {
type = string
}

locals {
timestamp = regex_replace(timestamp(), "[- TZ:]", "")
}

# Sources (Builders)

# Amazon EBS builder
source "amazon-ebs" "demo" {
access_key = var.aws_access_key
secret_key = var.aws_secret_key
region = "us-west-2"
source_ami = "ami-0c55b159cbfafe1f0"
instance_type = "t2.micro"
ssh_username = "ubuntu"
ami_name = "packer-nodejs-demo-ami-${local.timestamp}"
}

# Google Compute Engine builder
source "googlecompute" "demo" {
project_id = var.gcp_project_id
account_file = var.gcp_account_file
source_image_family = "ubuntu-2004-lts"
zone = "us-west1-a"
instance_name = "packer-nodejs-demo"
ssh_username = "ubuntu"
image_name = "packer-nodejs-demo-image-${local.timestamp}"
}

# Builds
build {
sources = [
"source.amazon-ebs.demo",
"source.googlecompute.demo",
]

# Provisioners
provisioner "shell" {
inline = [
"sleep 30",
"sudo apt-get update",
"sudo apt-get upgrade -y",
"curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash -",
"sudo apt-get install -y nodejs",
]
}

provisioner "file" {
source = "app/"
destination = "/tmp/app"
}

provisioner "shell" {
inline = [
"sudo mv /tmp/app /var/www/app",
"cd /var/www/app",
"npm install",
"sudo systemctl enable --now app.service",
]
}

# Post-processors
post-processor "manifest" {
output = "manifest.json"
strip_path = true
}
}
Loading

0 comments on commit 6729dbd

Please sign in to comment.