Commit 6aca87e2 authored by Elias Englmeier's avatar Elias Englmeier
Browse files

new dockerfile

parent c9f924e4
FROM openjdk:8
RUN mkdir /srv/java-docker-example
COPY classification-1.0-SNAPSHOT.jar /srv/classification-1.0-SNAPSHOT.jar
COPY config.yml /srv/java-docker-example/
# https://github.com/docker-library/docs/tree/master/mysql#no-connections-until-mysql-init-completes
# https://github.com/jwilder/dockerize
ENV DOCKERIZE_VERSION v0.3.0
RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& tar -C /usr/local/bin -xzvf dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& rm dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz
# wait for mysql to pass a healthcheck before starting the dropwizard service
# it can't handle the database being down when the app starts up
CMD dockerize -wait tcp://db:3306 -timeout 100s /usr/bin/java -jar /srv/java-docker-example/classification-1.0-SNAPSHOT.jar server /srv/java-docker-example/config.yml
EXPOSE 9000 9001
......@@ -33,5 +33,5 @@ database:
user: root
# the password
password: root
# the JDBC URL; the database is called DWGettingStarted
url: jdbc:mysql://localhost:3306/tmms
\ No newline at end of file
# the JDBC URL; the database is called tmms
url: jdbc:mysql://${DB_IP:-localhost}/tmms
\ No newline at end of file
version: '2'
services:
db:
image: library/mysql:5.5.54
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=tmms
- MYSQL_USER=root
- MYSQL_PASSWORD=root
ports:
- "3306:3306"
app:
environment:
- DB_IP=db
image: app
ports:
- "9000:9000"
- "9001:9001"
\ No newline at end of file
......@@ -15,11 +15,6 @@
<name>classificationservice</name>
<properties>
<docker.host.address>192.168.99.100</docker.host.address>
<classification.port>9000</classification.port>
<classification.port.admin>9001</classification.port.admin>
<docker.registry.name></docker.registry.name>
<docker.repository.name>fortissodim/textclassificationmicroservice</docker.repository.name>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<dropwizard.version>1.3.0</dropwizard.version>
......@@ -159,113 +154,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jolokia</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.13.3</version>
<executions>
<execution>
<id>start</id>
<phase>pre-integration-test</phase>
<goals>
<goal>build</goal>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
<execution>
<id>push-to-docker-registry</id>
<phase>deploy</phase>
<goals>
<goal>push</goal>
</goals>
</execution>
</executions>
<configuration>
<images>
<image>
<alias>${project.artifactId}</alias>
<name>${docker.repository.name}:${project.version}</name>
<build>
<from>java:8-jre</from>
<maintainer>fortissodim</maintainer>
<assembly>
<descriptor>docker-assembly.xml</descriptor>
</assembly>
<ports>
<port>9000</port>
<port>9001</port>
</ports>
</build>
<run>
<namingStrategy>alias</namingStrategy>
<ports>
<port>${classification.port}:9000</port>
<port>${classification.port.admin}:9001</port>
</ports>
<volumes>
<bind>
<volume>${user.home}/logs:/logs</volume>
</bind>
</volumes>
<wait>
<url>http://${docker.host.address}:${classification.port}</url>
<time>10000</time>
</wait>
<log>
<prefix>${project.artifactId}</prefix>
<color>cyan</color>
</log>
</run>
</image>
</images>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<phase>integration-test</phase>
<includes>
<include>**/*.java</include>
</includes>
<groups>org.tmms.classification.resources.IntegrationTest</groups>
<systemPropertyVariables>
<service.url>http://${docker.host.address}:${classification.port}/</service.url>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<excludedGroups>org.tmms.classification.resources.IntegrationTest</excludedGroups>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
......
logging:
level: INFO
appenders:
- type: console
threshold: ALL
timeZone: UTC
target: stdout
logFormat: "%-6level [%d{HH:mm:ss.SSS}] [%t] %logger{5} - %X{code} %msg %n"
- type: file
currentLogFilename: /logs/tmms.log
threshold: ALL
archive: true
archivedLogFilenamePattern: /logs/tmms-%d.log
archivedFileCount: 5
timeZone: UTC
logFormat: "%-6level [%d{HH:mm:ss.SSS}] [%t] %logger{5} - %X{code} %msg %n"
template: response, %s!
defaultName: Stranger
defaultEmptyResponse: No Data Received
server:
applicationConnectors:
- type: http
port: 9000
adminConnectors:
- type: http
port: 9001
# Database settings.
database:
# the name of the JDBC driver
driverClass: com.mysql.jdbc.Driver
# the username
user: root
# the password
password: root
# the JDBC URL; the database is called tmms
url: jdbc:mysql://192.168.99.100/tmms
package org.tmms.classification.resources;
import static org.junit.Assert.*;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@Category(IntegrationTest.class)
public class DockerTests {
@Test
public void testConnection() throws IOException {
String baseUrl = System.getProperty("service.url");
URL serviceUrl = new URL(baseUrl);
HttpURLConnection connection = (HttpURLConnection) serviceUrl.openConnection();
int responseCode = connection.getResponseCode();
assertEquals(200, responseCode);
}
}
package org.tmms.classification.resources;
import java.lang.annotation.*;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface IntegrationTest {}
Supports Markdown
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