Commit bbe05b0d authored by Ishtiaq Ahmed's avatar Ishtiaq Ahmed

Initial commit

parents
.idea/*
target
\ No newline at end of file
FROM openjdk:8-jre-alpine
EXPOSE 8080
COPY ./target/java-maven-app-1.1.0-SNAPSHOT.jar /usr/app/
WORKDIR /usr/app
ENTRYPOINT ["java", "-jar", "java-maven-app-1.1.0-SNAPSHOT.jar"]
pipeline {
agent any
environment {
PROJECT_ID = 'secret-lambda-365807'
CLUSTER_NAME = 'cicd-task'
LOCATION = 'us-central1-c'
CREDENTIALS_ID = 'k8s-cicd'
}
tools {
maven 'Maven'
}
stages {
stage("git clone") {
steps {
script {
echo "cloning my app"
sh "rm -rf *"
git branch: 'main', url: 'https://gitlab.com/mshussainn/cicdtask.git'
}
}
}
stage("build jar") {
steps {
script {
echo "building application"
sh 'mvn clean package'
sh 'mvn package'
}
}
}
stage("build docker") {
steps {
script {
echo "building application"
withCredentials([usernamePassword(credentialsId: 'docker-hub-creds', passwordVariable: 'PASS', usernameVariable: 'USER')]) {
sh "sed -i 's/VERSION/${env.BUILD_ID}/g' docker-build.sh"
sh 'chmod 777 docker-build.sh'
sh './docker-build.sh'
// sh 'docker build -t my-app:1.0 .'
// sh 'docker tag my-app:1.0 mshussain/my-app:1.0'
// sh 'echo $PASS | docker login -u $USER --password-stdin'
// sh 'docker push mshussain/my-app:1.0'
}
}
}
}
stage("Deploy") {
steps {
sh "sed -i 's/VERSION/${env.BUILD_ID}/g' dep.yaml"
step([$class: 'KubernetesEngineBuilder', \
projectId: env.PROJECT_ID, \
clusterName: env.CLUSTER_NAME, \
location: env.LOCATION, \
manifestPattern: 'dep.yaml', \
credentialsId: env.CREDENTIALS_ID, \
verifyDeployments: true])
}
}
}
}
\ No newline at end of file
# nisum-cicd-task
apiVersion: apps/v1
kind: Deployment
metadata:
name: cicd-task
spec:
replicas: 1
selector:
matchLabels:
app: cicd-task
template:
metadata:
labels:
app: cicd-task
spec:
containers:
- name: cicd-task
image: mshussain/my-app:VERSION
ports:
- containerPort: 8080
env:
- name: PORT
value: "8080"
---
apiVersion: v1
kind: Service
metadata:
name: cicd-task
spec:
type: LoadBalancer
selector:
app: cicd-task
ports:
- port: 80
targetPort: 8080
\ No newline at end of file
#!/bin/sh
docker build -t my-app:VERSION .
docker tag my-app:VERSION mshussain/my-app:VERSION
echo $PASS | docker login -u $USER --password-stdin
docker push mshussain/my-app:VERSION
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>java-maven-app</artifactId>
<version>1.1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.3.5.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- to handle any Java version mismatch, add the following configuration for maven-compiler-plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.3.4.RELEASE</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>6.4</version>
</dependency>
</dependencies>
</project>
def buildJar() {
echo "building the application..."
sh 'mvn package'
}
def buildImage() {
echo "building the docker image..."
withCredentials([usernamePassword(credentialsId: 'docker-hub-repo', passwordVariable: 'PASS', usernameVariable: 'USER')]) {
sh 'docker build -t nanajanashia/demo-app:jma-2.0 .'
sh "echo $PASS | docker login -u $USER --password-stdin"
sh 'docker push nanajanashia/demo-app:jma-2.0'
}
}
def deployApp() {
echo 'deploying the application...'
}
return this
\ No newline at end of file
package com.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.PostConstruct;
@SpringBootApplication
public class Application {
public static void main(String[] args)
{
SpringApplication.run(Application.class, args);
}
@PostConstruct
public void init()
{
Logger log = LoggerFactory.getLogger(Application.class);
log.info("Java app started");
}
public String getStatus() {
return "OK";
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>MyApp</title>
</head>
<body>
<h1>kia hall hain ?? </h1>
<!-- add image here <img src="" width="" /> -->
</body>
</html>
This is test
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment