Skip to content
Permalink
Browse files

Dockerize the application

  • Loading branch information...
schrieveslaach committed Jul 29, 2019
1 parent 7e23485 commit ffe66cb3a9cc20ee6910c77534b9a81632c785ea
@@ -26,10 +26,11 @@ docker run --detach \
--publish 3306:3306 \
mysql:5.6.25
```
3. Run the application. In the directory `worblehat-web`:
* Either run `mvn spring-boot:run`
* Or start as plain Java main class: `de.codecentric.Application`
4. Access the application at <http://localhost:8080/worblehat/>
3. Build the Docker image to run the application
* `mvn cleain install`
* `mvn docker:build -f worblehat-web`
* `docker run --name worblehat -d -p 8080:8080 --link worblehat-db worblehat/web`
4. Access the application at <http://localhost:8080/>

## Running acceptance tests

17 pom.xml
@@ -52,6 +52,23 @@
</repositories>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.30.0</version>

<dependencies>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>run-java-sh</artifactId>
<version>1.2.2</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@@ -82,6 +82,26 @@
<target>${java.version}</target>
</configuration>
</plugin>

<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>

<configuration>
<images>
<image>
<name>worblehat/web</name>
<build>
<contextDir>${project.basedir}/src/main/docker</contextDir>
<assembly>
<descriptor>${project.basedir}/src/main/docker/assembly.xml</descriptor>
<mode>dir</mode>
</assembly>
</build>
</image>
</images>
</configuration>
</plugin>
</plugins>
</build>

@@ -0,0 +1,3 @@
FROM sidereal/jre8
COPY maven/worblehat-web-1.1.0-SNAPSHOT.jar /app/worblehat.jar
CMD ["java", "-jar", "/app/worblehat.jar"]
@@ -0,0 +1,14 @@
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0
http://maven.apache.org/xsd/assembly-2.0.0.xsd">
<formats>
<format>jar</format>
</formats>

<files>
<file>
<source>target/${project.build.finalName}.jar</source>
<outputDirectory>/</outputDirectory>
</file>
</files>
</assembly>
@@ -10,17 +10,7 @@
public class Worblehat {

public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
ConfigurableApplicationContext applicationContext = SpringApplication.run(Worblehat.class, args);

// this code is basically to (a) demonstrate how to stop a Spring application and (b)
// get rid of the SonarQube warning to close the context properly
System.out.println("Enter 'stop' to stop Worblehat.");
String line = "";
do {
line = scan.nextLine();
} while (!line.equals("stop"));
applicationContext.close();
SpringApplication.run(Worblehat.class, args);
}

}
@@ -1,8 +1,8 @@
# Spring WebApp Config
server.context-path=/worblehat
server.context-path=/

# Database Config
spring.datasource.url=jdbc:mysql://localhost:3306/worblehat_test
spring.datasource.url=jdbc:mysql://worblehat-db:3306/worblehat_test
spring.datasource.username=worblehat
spring.datasource.password=worblehat
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

0 comments on commit ffe66cb

Please sign in to comment.
You can’t perform that action at this time.