forked from MithunTechnologiesDevOps/java-web-app-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit bf590a0
Showing
38 changed files
with
709 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
i### Gradle template | ||
.gradle/ | ||
build/ | ||
|
||
### Java template | ||
*.class | ||
.settings | ||
.classpath | ||
.project | ||
|
||
# Package Files # | ||
*.war | ||
*.ear | ||
|
||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||
hs_err_pid* | ||
### JetBrains template | ||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio | ||
|
||
## File-based project format: | ||
*.ipr | ||
*.iws | ||
*.iml | ||
|
||
## Directory-based project format: | ||
.idea/ | ||
|
||
## Plugin-specific files: | ||
|
||
# IntelliJ | ||
/out/ | ||
|
||
.app-src/tmp/ | ||
bower_components/ | ||
dist/ | ||
node_modules/ | ||
.tmp/ | ||
*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM tomcat:8.0.20-jre8 | ||
# Dummy text to test | ||
COPY target/java-web-app*.war /usr/local/tomcat/webapps/java-web-app.war |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
node{ | ||
|
||
stage('SCM Checkout'){ | ||
git url: 'https://github.com/devopstrainingbanglore/gradle-web-app.git',branch: 'master' | ||
} | ||
|
||
stage(" Maven Clean Package"){ | ||
def mavenHome = tool name: "Maven-3.5.6", type: "maven" | ||
def mavenCMD = "${mavenHome}/bin/mvn" | ||
sh "${mavenCMD} clean package" | ||
|
||
} | ||
|
||
|
||
stage('Build Docker Image'){ | ||
sh 'docker build -t dockerhandson/java-web-app .' | ||
} | ||
|
||
stage('Push Docker Image'){ | ||
withCredentials([string(credentialsId: 'Docker_Hub_Pwd', variable: 'Docker_Hub_Pwd')]) { | ||
sh "docker login -u dockerhandson -p ${Docker_Hub_Pwd}" | ||
} | ||
sh 'docker push dockerhandson/java-web-app' | ||
} | ||
|
||
stage('Run Docker Image In Dev Server'){ | ||
|
||
def dockerRun = ' docker run -d -p 8080:8080 --name java-web-app dockerhandson/java-web-app' | ||
|
||
sshagent(['DOCKER_SERVER']) { | ||
sh 'ssh -o StrictHostKeyChecking=no [email protected] docker stop java-web-app || true' | ||
sh 'ssh [email protected] docker rm java-web-app || true' | ||
sh 'ssh [email protected] docker rmi -f $(docker images -q) || true' | ||
sh "ssh [email protected] ${dockerRun}" | ||
} | ||
|
||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
<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/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.mt</groupId> | ||
<artifactId>java-web-app</artifactId> | ||
<packaging>war</packaging> | ||
<version>1.0</version> | ||
|
||
<name>Maven Web Application</name> | ||
<url>http://mithuntechnologies.com</url> | ||
|
||
<description>Maven Web Project</description> | ||
|
||
<organization> | ||
<name>Mithun Technologies</name> | ||
<url>http://mithuntechnologies.com/</url> | ||
</organization> | ||
|
||
<properties> | ||
<!-- versions --> | ||
|
||
<spring.version>5.0.2.RELEASE</spring.version> | ||
<junit.version>4.12</junit.version> | ||
<log4j.version>1.2.17</log4j.version> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
|
||
<!-- test dependencies --> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>${junit.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-test</artifactId> | ||
<version>3.2.3.RELEASE</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-core</artifactId> | ||
<version>1.9.5</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<!-- compile dependencies --> | ||
|
||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-core</artifactId> | ||
<version>${spring.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-web</artifactId> | ||
<version>${spring.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-webmvc</artifactId> | ||
<version>${spring.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-context</artifactId> | ||
<version>${spring.version}</version> | ||
</dependency> | ||
|
||
<!-- provided dependencies --> | ||
|
||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>javax.servlet-api</artifactId> | ||
<version>3.1.0</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>jstl</artifactId> | ||
<version>1.2</version> | ||
</dependency> | ||
|
||
<!-- https://mvnrepository.com/artifact/ch.qos.logback/logback-classic --> | ||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
<version>1.2.3</version> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<!-- <distributionManagement> | ||
<repository> | ||
<id>nexus</id> | ||
<name>Mithun Technologies Releases Nexus Repository</name> | ||
<url>http://13.235.8.113:8081/repository/flipkart-release/</url> | ||
</repository> | ||
<snapshotRepository> | ||
<id>nexus</id> | ||
<name>Mithun Technologies Snapshot Nexus Repository </name> | ||
<url>http://13.235.8.113:8081/repository/flipkart-snapshot/</url> | ||
</snapshotRepository> | ||
</distributionManagement> --> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>2.5.1</version> | ||
<inherited>true</inherited> | ||
<configuration> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
|
||
</project> |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/rst/helloworld/service/HelloWorldService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.rst.helloworld.service; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.util.StringUtils; | ||
|
||
@Service | ||
public class HelloWorldService { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(HelloWorldService.class); | ||
|
||
public String getDesc() { | ||
|
||
logger.debug("getDesc() is executed!"); | ||
|
||
return "Maven + Spring MVC + Jenkins + Docker Hello World Example"; | ||
|
||
} | ||
|
||
public String getTitle(String name) { | ||
|
||
logger.debug("getTitle() is executed! $name : {}", name); | ||
|
||
if(StringUtils.isEmpty(name)){ | ||
return "Hello World"; | ||
}else{ | ||
return "Hello " + name; | ||
} | ||
|
||
} | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
src/main/java/com/rst/helloworld/web/WelcomeController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.rst.helloworld.web; | ||
|
||
import java.util.Map; | ||
|
||
import com.rst.helloworld.service.HelloWorldService; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.servlet.ModelAndView; | ||
|
||
@Controller | ||
public class WelcomeController { | ||
|
||
private final Logger logger = LoggerFactory.getLogger(WelcomeController.class); | ||
private final HelloWorldService helloWorldService; | ||
|
||
@Autowired | ||
public WelcomeController(HelloWorldService helloWorldService) { | ||
this.helloWorldService = helloWorldService; | ||
} | ||
|
||
@RequestMapping(value = "/", method = RequestMethod.GET) | ||
public String index(Map<String, Object> model) { | ||
|
||
logger.debug("index() is executed!"); | ||
|
||
model.put("title", helloWorldService.getTitle("")); | ||
model.put("msg", helloWorldService.getDesc()); | ||
|
||
return "index"; | ||
} | ||
|
||
@RequestMapping(value = "/hello/{name:.+}", method = RequestMethod.GET) | ||
public ModelAndView hello(@PathVariable("name") String name) { | ||
|
||
logger.debug("hello() is executed - $name {}", name); | ||
|
||
ModelAndView model = new ModelAndView(); | ||
model.setViewName("index"); | ||
|
||
model.addObject("title", helloWorldService.getTitle(name)); | ||
model.addObject("msg", helloWorldService.getDesc()); | ||
|
||
return model; | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<configuration> | ||
|
||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<layout class="ch.qos.logback.classic.PatternLayout"> | ||
|
||
<Pattern> | ||
%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n | ||
</Pattern> | ||
|
||
</layout> | ||
</appender> | ||
|
||
<logger name="org.springframework" level="debug" additivity="false"> | ||
<appender-ref ref="STDOUT" /> | ||
</logger> | ||
|
||
<logger name="com.rst.helloworld" level="debug" additivity="false"> | ||
<appender-ref ref="STDOUT" /> | ||
</logger> | ||
|
||
<root level="debug"> | ||
<appender-ref ref="STDOUT" /> | ||
</root> | ||
|
||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:context="http://www.springframework.org/schema/context" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:mvc="http://www.springframework.org/schema/mvc" | ||
xsi:schemaLocation=" | ||
http://www.springframework.org/schema/beans | ||
http://www.springframework.org/schema/beans/spring-beans.xsd | ||
http://www.springframework.org/schema/context | ||
http://www.springframework.org/schema/context/spring-context.xsd "> | ||
|
||
<context:component-scan base-package="com.rst.helloworld.service" /> | ||
|
||
</beans> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:context="http://www.springframework.org/schema/context" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:mvc="http://www.springframework.org/schema/mvc" | ||
xsi:schemaLocation=" | ||
http://www.springframework.org/schema/beans | ||
http://www.springframework.org/schema/beans/spring-beans.xsd | ||
http://www.springframework.org/schema/mvc | ||
http://www.springframework.org/schema/mvc/spring-mvc.xsd | ||
http://www.springframework.org/schema/context | ||
http://www.springframework.org/schema/context/spring-context.xsd "> | ||
|
||
<context:component-scan base-package="com.rst.helloworld.web" /> | ||
|
||
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> | ||
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> | ||
<property name="prefix" value="/WEB-INF/views/jsp/" /> | ||
<property name="suffix" value=".jsp" /> | ||
</bean> | ||
|
||
<mvc:resources mapping="/resources/**" location="/resources/" /> | ||
|
||
<mvc:annotation-driven /> | ||
|
||
</beans> |
Oops, something went wrong.