Skip to content
Permalink
Browse files

Dockerize the application

  • Loading branch information...
schrieveslaach committed Jul 29, 2019
1 parent 7e23485 commit fcbf08370ee5de5c4049d593c63bf3d8201da998
@@ -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 clean 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.31.0</version>

<dependencies>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>run-java-sh</artifactId>
<version>1.3.4</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,12 @@
FROM frolvlad/alpine-java:jre8-slim
ENV DOCKERIZE_VERSION v0.6.1
RUN apk add --no-cache openssl \
&& wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& tar -C /usr/local/bin -xzvf dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& rm dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz

COPY maven/run-java.sh /app/run-java.sh
COPY maven/${project.build.finalName}.jar /app/worblehat.jar

CMD ["dockerize", "-wait", "tcp://worblehat-db:3306", "/app/run-java.sh", "run"]
EXPOSE 8080
@@ -0,0 +1,18 @@
<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>${project.build.directory}/${project.build.finalName}.jar</source>
<outputDirectory></outputDirectory>
</file>
<file>
<source>${project.build.directory}/docker-extra/run-java/run-java.sh</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
@@ -17,6 +17,5 @@ info.version=@pom.version@
info.stage=test
logging.file=/tmp/@pom.artifactId@.log
liquibase.change-log=classpath:master.xml
liquibase.drop-first=true
spring.jpa.hibernate.ddl-auto=validate
spring.thymeleaf.cache=false

0 comments on commit fcbf083

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