├── .gitignore ├── Dockerfile ├── JavaWebApplication.yaml ├── JenkinsPiplelineScriptDockerSwarm_Private_Repo ├── Jenkinsfile ├── JenkinsfileDockerSwarm ├── helmchart ├── .helmignore ├── Chart.yaml ├── templates │ ├── NOTES.txt │ ├── _helpers.tpl │ ├── deployment.yaml │ ├── hpa.yaml │ ├── ingress.yaml │ ├── service.yaml │ ├── serviceaccount.yaml │ └── tests │ │ └── test-connection.yaml └── values.yaml ├── index.yaml ├── pom.xml └── src └── main ├── java └── com │ └── rst │ └── helloworld │ ├── service │ └── HelloWorldService.java │ └── web │ └── WelcomeController.java ├── resources └── logback.xml └── webapp ├── WEB-INF ├── spring-core-config.xml ├── spring-mvc-config.xml ├── views │ └── jsp │ │ └── index.jsp └── web.xml └── resources └── core ├── css ├── bootstrap.min.css └── hello.css └── js ├── bootstrap.min.js └── hello.js /.gitignore: -------------------------------------------------------------------------------- 1 | # Operating System Files 2 | 3 | *.DS_Store 4 | Thumbs.db 5 | *.sw? 6 | .#* 7 | *# 8 | *~ 9 | *.sublime-* 10 | 11 | # Build Artifacts 12 | 13 | **/.gradle/ 14 | **/build/ 15 | **/target/ 16 | **/bin/ 17 | **/dependency-reduced-pom.xml 18 | 19 | # Eclipse Project Files 20 | .metadata 21 | .metadata/ 22 | **/.classpath 23 | **/.project 24 | **/.settings/ 25 | 26 | # IntelliJ IDEA Files 27 | 28 | **/*.iml 29 | **/*.ipr 30 | **/*.iws 31 | **/*.idea 32 | 33 | README.html 34 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM tomcat:8.5-jdk8 2 | COPY target/java-web-app*.war /usr/local/tomcat/webapps/java-web-app.war -------------------------------------------------------------------------------- /JavaWebApplication.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: webpage-deployment 5 | namespace: production 6 | spec: 7 | replicas: 2 8 | revisionHistoryLimit: 5 9 | selector: 10 | matchLabels: 11 | application: webpage 12 | strategy: 13 | type: RollingUpdate 14 | rollingUpdate: 15 | maxSurge: 1 16 | maxUnavailable: 1 17 | minReadySeconds: 30 18 | template: 19 | metadata: 20 | name: webpage-pod 21 | labels: 22 | application: webpage 23 | spec: 24 | containers: 25 | - name: webpage-container 26 | image: mithuntechnologies/java-web-application:1 27 | imagePullPolicy: Always 28 | ports: 29 | - containerPort: 8080 30 | --- 31 | apiVersion: v1 32 | kind: Service 33 | metadata: 34 | name: webpage-service 35 | namespace: production 36 | spec: 37 | type: NodePort 38 | selector: 39 | application: webpage 40 | ports: 41 | - port: 80 42 | targetPort: 8080 -------------------------------------------------------------------------------- /JenkinsPiplelineScriptDockerSwarm_Private_Repo: -------------------------------------------------------------------------------- 1 | node{ 2 | 3 | def buildNumber = BUILD_NUMBER 4 | 5 | stage("Git CheckOut"){ 6 | git url: 'https://github.com/MithunTechnologiesDevOps/java-web-app-docker.git',branch: 'master' 7 | } 8 | 9 | stage(" Maven Clean Package"){ 10 | def mavenHome = tool name: "Maven-3.6.2", type: "maven" 11 | def mavenCMD = "${mavenHome}/bin/mvn" 12 | sh "${mavenCMD} clean package" 13 | } 14 | 15 | stage("Build Dokcer Image") { 16 | sh "docker build -t 172.31.1.204:8083/java-web-app:${buildNumber} ." 17 | } 18 | 19 | 20 | stage("Docker Push"){ 21 | 22 | withCredentials([string(credentialsId: 'Docker_Repo_Pwd', variable: 'Docker_Repo_Pwd')]) { 23 | sh "docker login -u admin -p ${Docker_Repo_Pwd} 172.31.1.204:8083" 24 | } 25 | 26 | sh "docker push 172.31.1.204:8083/java-web-app:${buildNumber}" 27 | } 28 | 29 | stage("Deploy to docker swarm cluster"){ 30 | sshagent(['Docker_Swarm_Manager_Dev']) { 31 | sh 'ssh -o StrictHostKeyChecking=no ubuntu@172.31.10.56 docker service rm javawebapp || true' 32 | withCredentials([string(credentialsId: 'Docker_Repo_Pwd', variable: 'Docker_Repo_Pwd')]) { 33 | 34 | sh "ssh -o StrictHostKeyChecking=no ubuntu@172.31.10.56 docker login -u admin -p ${Docker_Repo_Pwd} 172.31.1.204:8083" 35 | } 36 | sh "ssh ubuntu@172.31.10.56 docker service create --name javawebapp -p 7070:8080 --replicas 2 --with-registry-auth 172.31.1.204:8083/java-web-app:${buildNumber}" 37 | } 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /Jenkinsfile: -------------------------------------------------------------------------------- 1 | node{ 2 | 3 | stage('SCM Checkout'){ 4 | git url: 'https://github.com/MithunTechnologiesDevOps/java-web-app-docker.git',branch: 'master' 5 | } 6 | 7 | stage(" Maven Clean Package"){ 8 | def mavenHome = tool name: "Maven-3.5.6", type: "maven" 9 | def mavenCMD = "${mavenHome}/bin/mvn" 10 | sh "${mavenCMD} clean package" 11 | 12 | } 13 | 14 | 15 | stage('Build Docker Image'){ 16 | sh 'docker build -t dockerhandson/java-web-app .' 17 | } 18 | 19 | stage('Push Docker Image'){ 20 | withCredentials([string(credentialsId: 'Docker_Hub_Pwd', variable: 'Docker_Hub_Pwd')]) { 21 | sh "docker login -u dockerhandson -p ${Docker_Hub_Pwd}" 22 | } 23 | sh 'docker push dockerhandson/java-web-app' 24 | } 25 | 26 | stage('Run Docker Image In Dev Server'){ 27 | 28 | def dockerRun = ' docker run -d -p 8080:8080 --name java-web-app dockerhandson/java-web-app' 29 | 30 | sshagent(['DOCKER_SERVER']) { 31 | sh 'ssh -o StrictHostKeyChecking=no ubuntu@172.31.20.72 docker stop java-web-app || true' 32 | sh 'ssh ubuntu@172.31.20.72 docker rm java-web-app || true' 33 | sh 'ssh ubuntu@172.31.20.72 docker rmi -f $(docker images -q) || true' 34 | sh "ssh ubuntu@172.31.20.72 ${dockerRun}" 35 | } 36 | 37 | } 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /JenkinsfileDockerSwarm: -------------------------------------------------------------------------------- 1 | node{ 2 | def buildNumber = BUILD_NUMBER 3 | stage("Git CheckOut"){ 4 | git url: 'https://github.com/MithunTechnologiesDevOps/java-web-app-docker.git',branch: 'master' 5 | } 6 | 7 | stage(" Maven Clean Package"){ 8 | def mavenHome = tool name: "Maven-3.6.1", type: "maven" 9 | def mavenCMD = "${mavenHome}/bin/mvn" 10 | sh "${mavenCMD} clean package" 11 | } 12 | 13 | stage("Build Dokcer Image") { 14 | sh "docker build -t dockerhandson/java-web-app:${buildNumber} ." 15 | } 16 | 17 | stage("Docker Push"){ 18 | withCredentials([string(credentialsId: 'Docker_Hub_Pwd', variable: 'Docker_Hub_Pwd')]) { 19 | sh "docker login -u dockerhandson -p ${Docker_Hub_Pwd}" 20 | } 21 | sh "docker push dockerhandson/java-web-app:${buildNumber}" 22 | 23 | } 24 | 25 | // Remove local image in Jenkins Server 26 | stage("Remove Local Image"){ 27 | sh "docker rmi -f dockerhandson/java-web-app:${buildNumber}" 28 | } 29 | 30 | stage("Deploy to docker swarm cluster"){ 31 | sshagent(['Docker_Swarm_Manager_Dev']) { 32 | sh 'ssh -o StrictHostKeyChecking=no ubuntu@172.31.47.232 docker service rm javawebapp || true' 33 | sh "ssh ubuntu@172.31.47.232 docker service create --name javawebapp -p 8080:8080 --replicas 2 dockerhandson/java-web-app:${buildNumber}" 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /helmchart/.helmignore: -------------------------------------------------------------------------------- 1 | # Patterns to ignore when building packages. 2 | # This supports shell glob matching, relative path matching, and 3 | # negation (prefixed with !). Only one pattern per line. 4 | .DS_Store 5 | # Common VCS dirs 6 | .git/ 7 | .gitignore 8 | .bzr/ 9 | .bzrignore 10 | .hg/ 11 | .hgignore 12 | .svn/ 13 | # Common backup files 14 | *.swp 15 | *.bak 16 | *.tmp 17 | *.orig 18 | *~ 19 | # Various IDEs 20 | .project 21 | .idea/ 22 | *.tmproj 23 | .vscode/ 24 | -------------------------------------------------------------------------------- /helmchart/Chart.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v2 2 | name: javawebapp 3 | description: A Helm chart for Mithun tech JavaWeb Application 4 | 5 | # A chart can be either an 'application' or a 'library' chart. 6 | # 7 | # Application charts are a collection of templates that can be packaged into versioned archives 8 | # to be deployed. 9 | # 10 | # Library charts provide useful utilities or functions for the chart developer. They're included as 11 | # a dependency of application charts to inject those utilities and functions into the rendering 12 | # pipeline. Library charts do not define any templates and therefore cannot be deployed. 13 | type: application 14 | 15 | # This is the chart version. This version number should be incremented each time you make changes 16 | # to the chart and its templates, including the app version. 17 | # Versions are expected to follow Semantic Versioning (https://semver.org/) 18 | version: 0.1.0 19 | 20 | # This is the version number of the application being deployed. This version number should be 21 | # incremented each time you make changes to the application. Versions are not expected to 22 | # follow Semantic Versioning. They should reflect the version the application is using. 23 | appVersion: 1.16.0 24 | -------------------------------------------------------------------------------- /helmchart/templates/NOTES.txt: -------------------------------------------------------------------------------- 1 | 1. Get the application URL by running these commands: 2 | {{- if .Values.ingress.enabled }} 3 | {{- range $host := .Values.ingress.hosts }} 4 | {{- range .paths }} 5 | http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }} 6 | {{- end }} 7 | {{- end }} 8 | {{- else if contains "NodePort" .Values.service.type }} 9 | export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "javawebapp.fullname" . }}) 10 | export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") 11 | echo http://$NODE_IP:$NODE_PORT 12 | {{- else if contains "LoadBalancer" .Values.service.type }} 13 | NOTE: It may take a few minutes for the LoadBalancer IP to be available. 14 | You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "javawebapp.fullname" . }}' 15 | export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "javawebapp.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") 16 | echo http://$SERVICE_IP:{{ .Values.service.port }} 17 | {{- else if contains "ClusterIP" .Values.service.type }} 18 | export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "javawebapp.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") 19 | export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") 20 | echo "Visit http://127.0.0.1:8080 to use your application" 21 | kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT 22 | {{- end }} 23 | -------------------------------------------------------------------------------- /helmchart/templates/_helpers.tpl: -------------------------------------------------------------------------------- 1 | {{/* 2 | Expand the name of the chart. 3 | */}} 4 | {{- define "javawebapp.name" -}} 5 | {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} 6 | {{- end }} 7 | 8 | {{/* 9 | Create a default fully qualified app name. 10 | We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). 11 | If release name contains chart name it will be used as a full name. 12 | */}} 13 | {{- define "javawebapp.fullname" -}} 14 | {{- if .Values.fullnameOverride }} 15 | {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} 16 | {{- else }} 17 | {{- $name := default .Chart.Name .Values.nameOverride }} 18 | {{- if contains $name .Release.Name }} 19 | {{- .Release.Name | trunc 63 | trimSuffix "-" }} 20 | {{- else }} 21 | {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} 22 | {{- end }} 23 | {{- end }} 24 | {{- end }} 25 | 26 | {{/* 27 | Create chart name and version as used by the chart label. 28 | */}} 29 | {{- define "javawebapp.chart" -}} 30 | {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} 31 | {{- end }} 32 | 33 | {{/* 34 | Common labels 35 | */}} 36 | {{- define "javawebapp.labels" -}} 37 | helm.sh/chart: {{ include "javawebapp.chart" . }} 38 | {{ include "javawebapp.selectorLabels" . }} 39 | {{- if .Chart.AppVersion }} 40 | app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} 41 | {{- end }} 42 | app.kubernetes.io/managed-by: {{ .Release.Service }} 43 | {{- end }} 44 | 45 | {{/* 46 | Selector labels 47 | */}} 48 | {{- define "javawebapp.selectorLabels" -}} 49 | app.kubernetes.io/name: {{ include "javawebapp.name" . }} 50 | app.kubernetes.io/instance: {{ .Release.Name }} 51 | {{- end }} 52 | 53 | {{/* 54 | Create the name of the service account to use 55 | */}} 56 | {{- define "javawebapp.serviceAccountName" -}} 57 | {{- if .Values.serviceAccount.create }} 58 | {{- default (include "javawebapp.fullname" .) .Values.serviceAccount.name }} 59 | {{- else }} 60 | {{- default "default" .Values.serviceAccount.name }} 61 | {{- end }} 62 | {{- end }} 63 | -------------------------------------------------------------------------------- /helmchart/templates/deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: {{ include "javawebapp.fullname" . }} 5 | labels: 6 | {{- include "javawebapp.labels" . | nindent 4 }} 7 | spec: 8 | {{- if not .Values.autoscaling.enabled }} 9 | replicas: {{ .Values.replicaCount }} 10 | {{- end }} 11 | selector: 12 | matchLabels: 13 | {{- include "javawebapp.selectorLabels" . | nindent 6 }} 14 | template: 15 | metadata: 16 | {{- with .Values.podAnnotations }} 17 | annotations: 18 | {{- toYaml . | nindent 8 }} 19 | {{- end }} 20 | labels: 21 | {{- include "javawebapp.selectorLabels" . | nindent 8 }} 22 | spec: 23 | {{- with .Values.imagePullSecrets }} 24 | imagePullSecrets: 25 | {{- toYaml . | nindent 8 }} 26 | {{- end }} 27 | serviceAccountName: {{ include "javawebapp.serviceAccountName" . }} 28 | securityContext: 29 | {{- toYaml .Values.podSecurityContext | nindent 8 }} 30 | containers: 31 | - name: {{ .Chart.Name }} 32 | securityContext: 33 | {{- toYaml .Values.securityContext | nindent 12 }} 34 | image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" 35 | imagePullPolicy: {{ .Values.image.pullPolicy }} 36 | ports: 37 | - name: http 38 | containerPort: {{ .Values.containerPort }} 39 | protocol: TCP 40 | livenessProbe: 41 | httpGet: 42 | path: / 43 | port: http 44 | readinessProbe: 45 | httpGet: 46 | path: / 47 | port: http 48 | resources: 49 | {{- toYaml .Values.resources | nindent 12 }} 50 | {{- with .Values.nodeSelector }} 51 | nodeSelector: 52 | {{- toYaml . | nindent 8 }} 53 | {{- end }} 54 | {{- with .Values.affinity }} 55 | affinity: 56 | {{- toYaml . | nindent 8 }} 57 | {{- end }} 58 | {{- with .Values.tolerations }} 59 | tolerations: 60 | {{- toYaml . | nindent 8 }} 61 | {{- end }} 62 | -------------------------------------------------------------------------------- /helmchart/templates/hpa.yaml: -------------------------------------------------------------------------------- 1 | {{- if .Values.autoscaling.enabled }} 2 | apiVersion: autoscaling/v2beta1 3 | kind: HorizontalPodAutoscaler 4 | metadata: 5 | name: {{ include "javawebapp.fullname" . }} 6 | labels: 7 | {{- include "javawebapp.labels" . | nindent 4 }} 8 | spec: 9 | scaleTargetRef: 10 | apiVersion: apps/v1 11 | kind: Deployment 12 | name: {{ include "javawebapp.fullname" . }} 13 | minReplicas: {{ .Values.autoscaling.minReplicas }} 14 | maxReplicas: {{ .Values.autoscaling.maxReplicas }} 15 | metrics: 16 | {{- if .Values.autoscaling.targetCPUUtilizationPercentage }} 17 | - type: Resource 18 | resource: 19 | name: cpu 20 | targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} 21 | {{- end }} 22 | {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }} 23 | - type: Resource 24 | resource: 25 | name: memory 26 | targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} 27 | {{- end }} 28 | {{- end }} 29 | -------------------------------------------------------------------------------- /helmchart/templates/ingress.yaml: -------------------------------------------------------------------------------- 1 | {{- if .Values.ingress.enabled -}} 2 | {{- $fullName := include "javawebapp.fullname" . -}} 3 | {{- $svcPort := .Values.service.port -}} 4 | {{- if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} 5 | apiVersion: networking.k8s.io/v1beta1 6 | {{- else -}} 7 | apiVersion: extensions/v1beta1 8 | {{- end }} 9 | kind: Ingress 10 | metadata: 11 | name: {{ $fullName }} 12 | labels: 13 | {{- include "javawebapp.labels" . | nindent 4 }} 14 | {{- with .Values.ingress.annotations }} 15 | annotations: 16 | {{- toYaml . | nindent 4 }} 17 | {{- end }} 18 | spec: 19 | {{- if .Values.ingress.tls }} 20 | tls: 21 | {{- range .Values.ingress.tls }} 22 | - hosts: 23 | {{- range .hosts }} 24 | - {{ . | quote }} 25 | {{- end }} 26 | secretName: {{ .secretName }} 27 | {{- end }} 28 | {{- end }} 29 | rules: 30 | {{- range .Values.ingress.hosts }} 31 | - host: {{ .host | quote }} 32 | http: 33 | paths: 34 | {{- range .paths }} 35 | - path: {{ .path }} 36 | backend: 37 | serviceName: {{ $fullName }} 38 | servicePort: {{ $svcPort }} 39 | {{- end }} 40 | {{- end }} 41 | {{- end }} 42 | -------------------------------------------------------------------------------- /helmchart/templates/service.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: {{ include "javawebapp.fullname" . }} 5 | labels: 6 | {{- include "javawebapp.labels" . | nindent 4 }} 7 | spec: 8 | type: {{ .Values.service.type }} 9 | ports: 10 | - port: {{ .Values.service.port }} 11 | targetPort: http 12 | protocol: TCP 13 | name: http 14 | selector: 15 | {{- include "javawebapp.selectorLabels" . | nindent 4 }} 16 | -------------------------------------------------------------------------------- /helmchart/templates/serviceaccount.yaml: -------------------------------------------------------------------------------- 1 | {{- if .Values.serviceAccount.create -}} 2 | apiVersion: v1 3 | kind: ServiceAccount 4 | metadata: 5 | name: {{ include "javawebapp.serviceAccountName" . }} 6 | labels: 7 | {{- include "javawebapp.labels" . | nindent 4 }} 8 | {{- with .Values.serviceAccount.annotations }} 9 | annotations: 10 | {{- toYaml . | nindent 4 }} 11 | {{- end }} 12 | {{- end }} 13 | -------------------------------------------------------------------------------- /helmchart/templates/tests/test-connection.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Pod 3 | metadata: 4 | name: "{{ include "javawebapp.fullname" . }}-test-connection" 5 | labels: 6 | {{- include "javawebapp.labels" . | nindent 4 }} 7 | annotations: 8 | "helm.sh/hook": test 9 | spec: 10 | containers: 11 | - name: wget 12 | image: busybox 13 | command: ['wget'] 14 | args: ['{{ include "javawebapp.fullname" . }}:{{ .Values.service.port }}'] 15 | restartPolicy: Never 16 | -------------------------------------------------------------------------------- /helmchart/values.yaml: -------------------------------------------------------------------------------- 1 | # Default values for javawebapp. 2 | # This is a YAML-formatted file. 3 | # Declare variables to be passed into your templates. 4 | 5 | replicaCount: 1 6 | 7 | containerPort: 8080 8 | 9 | image: 10 | repository: dockerhandson/java-web-app 11 | pullPolicy: IfNotPresent 12 | # Overrides the image tag whose default is the chart appVersion. 13 | tag: "latest" 14 | 15 | imagePullSecrets: [] 16 | nameOverride: "" 17 | fullnameOverride: "" 18 | 19 | serviceAccount: 20 | # Specifies whether a service account should be created 21 | create: true 22 | # Annotations to add to the service account 23 | annotations: {} 24 | # The name of the service account to use. 25 | # If not set and create is true, a name is generated using the fullname template 26 | name: "" 27 | 28 | podAnnotations: {} 29 | 30 | podSecurityContext: {} 31 | # fsGroup: 2000 32 | 33 | securityContext: {} 34 | # capabilities: 35 | # drop: 36 | # - ALL 37 | # readOnlyRootFilesystem: true 38 | # runAsNonRoot: true 39 | # runAsUser: 1000 40 | 41 | service: 42 | type: ClusterIP 43 | port: 80 44 | 45 | ingress: 46 | enabled: false 47 | annotations: {} 48 | # kubernetes.io/ingress.class: nginx 49 | # kubernetes.io/tls-acme: "true" 50 | hosts: 51 | - host: chart-example.local 52 | paths: [] 53 | tls: [] 54 | # - secretName: chart-example-tls 55 | # hosts: 56 | # - chart-example.local 57 | 58 | resources: {} 59 | # We usually recommend not to specify default resources and to leave this as a conscious 60 | # choice for the user. This also increases chances charts run on environments with little 61 | # resources, such as Minikube. If you do want to specify resources, uncomment the following 62 | # lines, adjust them as necessary, and remove the curly braces after 'resources:'. 63 | # limits: 64 | # cpu: 100m 65 | # memory: 128Mi 66 | # requests: 67 | # cpu: 100m 68 | # memory: 128Mi 69 | 70 | autoscaling: 71 | enabled: true 72 | minReplicas: 1 73 | maxReplicas: 100 74 | targetCPUUtilizationPercentage: 80 75 | # targetMemoryUtilizationPercentage: 80 76 | 77 | nodeSelector: {} 78 | 79 | tolerations: [] 80 | 81 | affinity: {} 82 | -------------------------------------------------------------------------------- /index.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | entries: 3 | javawebapp: 4 | - apiVersion: v2 5 | appVersion: latest 6 | created: "2020-12-02T01:06:54.465065358Z" 7 | description: A Helm chart of Mithun tech no for Kubernetes 8 | digest: 17a123dcb6baf659d538691a17bd29510eb36e3a81fd949ecfed4fcafb4804de 9 | name: javawebapp 10 | type: application 11 | urls: 12 | - https://mithuntechnologiesdevops.github.io/java-web-app-docker/javawebapp-0.1.0.tgz 13 | version: 0.1.0 14 | generated: "2020-12-02T01:06:54.463723282Z" -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.mt 6 | java-web-app 7 | war 8 | 1.0 9 | 10 | Maven Web Application 11 | http://mithuntechnologies.com 12 | 13 | Maven Web Project 14 | 15 | 16 | Mithun Technologies 17 | http://mithuntechnologies.com/ 18 | 19 | 20 | 21 | 22 | 23 | 5.0.7.RELEASE 24 | 4.12 25 | 1.2.17 26 | UTF-8 27 | UTF-8 28 | 29 | 30 | 31 | 32 | 33 | 34 | junit 35 | junit 36 | ${junit.version} 37 | test 38 | 39 | 40 | 41 | org.springframework 42 | spring-test 43 | 3.2.3.RELEASE 44 | test 45 | 46 | 47 | 48 | org.mockito 49 | mockito-core 50 | 1.9.5 51 | test 52 | 53 | 54 | 55 | 56 | 57 | org.springframework 58 | spring-core 59 | ${spring.version} 60 | 61 | 62 | org.springframework 63 | spring-web 64 | ${spring.version} 65 | 66 | 67 | org.springframework 68 | spring-webmvc 69 | ${spring.version} 70 | 71 | 72 | org.springframework 73 | spring-context 74 | ${spring.version} 75 | 76 | 77 | 78 | 79 | 80 | javax.servlet 81 | javax.servlet-api 82 | 3.1.0 83 | provided 84 | 85 | 86 | 87 | javax.servlet 88 | jstl 89 | 1.2 90 | 91 | 92 | 93 | 94 | ch.qos.logback 95 | logback-classic 96 | 1.2.3 97 | 98 | 99 | 100 | 101 | 113 | 114 | 115 | 116 | 117 | org.apache.maven.plugins 118 | maven-war-plugin 119 | 3.3.2 120 | 121 | 122 | org.apache.maven.plugins 123 | maven-compiler-plugin 124 | 2.5.1 125 | true 126 | 127 | 1.8 128 | 1.8 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | -------------------------------------------------------------------------------- /src/main/java/com/rst/helloworld/service/HelloWorldService.java: -------------------------------------------------------------------------------- 1 | package com.rst.helloworld.service; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.stereotype.Service; 6 | import org.springframework.util.StringUtils; 7 | 8 | @Service 9 | public class HelloWorldService { 10 | 11 | private static final Logger logger = LoggerFactory.getLogger(HelloWorldService.class); 12 | 13 | public String getDesc() { 14 | 15 | logger.debug("getDesc() is executed!"); 16 | 17 | return "Git, GitHub, Maven, CICD, Jenkins, Docker, Kubernetes, Terraform, ArgoCD and Amazon Web Services"; 18 | 19 | } 20 | 21 | public String getTitle(String name) { 22 | 23 | logger.debug("getTitle() is executed! $name : {}", name); 24 | 25 | if(StringUtils.isEmpty(name)){ 26 | return "Hello from Mithun Technologies"; 27 | }else{ 28 | return "Hello " + name; 29 | } 30 | 31 | } 32 | } -------------------------------------------------------------------------------- /src/main/java/com/rst/helloworld/web/WelcomeController.java: -------------------------------------------------------------------------------- 1 | package com.rst.helloworld.web; 2 | 3 | import java.util.Map; 4 | 5 | import com.rst.helloworld.service.HelloWorldService; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Controller; 10 | import org.springframework.web.bind.annotation.PathVariable; 11 | import org.springframework.web.bind.annotation.RequestMapping; 12 | import org.springframework.web.bind.annotation.RequestMethod; 13 | import org.springframework.web.servlet.ModelAndView; 14 | 15 | @Controller 16 | public class WelcomeController { 17 | 18 | private final Logger logger = LoggerFactory.getLogger(WelcomeController.class); 19 | private final HelloWorldService helloWorldService; 20 | 21 | @Autowired 22 | public WelcomeController(HelloWorldService helloWorldService) { 23 | this.helloWorldService = helloWorldService; 24 | } 25 | 26 | @RequestMapping(value = "/", method = RequestMethod.GET) 27 | public String index(Map model) { 28 | 29 | logger.debug("index() is executed!"); 30 | 31 | model.put("title", helloWorldService.getTitle("")); 32 | model.put("msg", helloWorldService.getDesc()); 33 | 34 | return "index"; 35 | } 36 | 37 | @RequestMapping(value = "/hello/{name:.+}", method = RequestMethod.GET) 38 | public ModelAndView hello(@PathVariable("name") String name) { 39 | 40 | logger.debug("hello() is executed - $name {}", name); 41 | 42 | ModelAndView model = new ModelAndView(); 43 | model.setViewName("index"); 44 | 45 | model.addObject("title", helloWorldService.getTitle(name)); 46 | model.addObject("msg", helloWorldService.getDesc()); 47 | 48 | return model; 49 | 50 | } 51 | 52 | } -------------------------------------------------------------------------------- /src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/spring-core-config.xml: -------------------------------------------------------------------------------- 1 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/spring-mvc-config.xml: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/views/jsp/index.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> 2 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 3 | 4 | 5 | 6 | Maven + Spring MVC 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | Project 18 | 19 | 20 | 21 | 22 | 23 | 24 | ${title} 25 | 26 | 27 | Hello ${msg} 28 | 29 | 30 | 31 | Welcome Welcome! 32 | 33 | 34 | Learn more 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | Welcome to Mithun Technologies Private Limited, Bengaluru, Karnataka, India 44 | Contact @ +91 9980923216 45 | 46 | 47 | 48 | 49 | 50 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 |
26 | 27 | Hello ${msg} 28 | 29 | 30 | 31 | Welcome Welcome! 32 | 33 |
34 | Learn more 35 |