Skip to content

Commit 576fad9

Browse files
authored
Merge pull request #1079 from watson-developer-cloud/docker-testing
Refactor Docker config for testing
2 parents e5061f5 + 23f3168 commit 576fad9

File tree

6 files changed

+84
-1938
lines changed

6 files changed

+84
-1938
lines changed

.bumpversion.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ message = Update version numbers from {current_version} -> {new_version}
2828
[bumpversion:file:tone-analyzer/README.md]
2929

3030
[bumpversion:file:visual-recognition/README.md]
31+
32+
[bumpversion:file:docker/pom.xml]
3133
search = {current_version}
3234
replace = {new_version}
3335

docker/Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Import java base image (using maven to build project)
2+
FROM maven:3.6.1-jdk-11-slim
3+
4+
# Copy project files
5+
COPY pom.xml /app/pom.xml
6+
COPY src /app/src
7+
WORKDIR /app
8+
9+
# Build project
10+
RUN mvn compiler:compile -f "/app/pom.xml"
11+
12+
# Be sure to change the main class name if you use your own files!
13+
RUN mvn -e exec:java -Dexec.mainClass="com.ibm.DockerTest"

docker/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
## Using this library in Docker
2+
You can use the provided Dockerfile and POM to help test issues you have with the SDK.
3+
4+
1. Install Docker
5+
- Mac: <https://docs.docker.com/docker-for-mac/install/>
6+
- Windows: <https://docs.docker.com/docker-for-windows/install/>
7+
2. Add the dependencies and code you'd like to test
8+
- If you're testing a simple project, you can edit the `DockerTest.java` file directly. Everything's set up to pull in the lastest version of the `ibm-watson` package and run that file when building the image.
9+
- If you'd like to use your own files, feel free to add them. Just be sure to edit the execution line in the Dockerfile to run your main class:
10+
11+
```
12+
RUN mvn -e exec:java -Dexec.mainClass="com.ibm.<MAIN_CLASS>"
13+
```
14+
If you import a project with a different group ID, you'll need to change that in the provided `pom.xml` as well.
15+
16+
- For more information on dockerfile construction please visit <https://docs.docker.com/engine/reference/builder/>
17+
3. Build the Docker image
18+
- From the directory with the Dockerfile, run `docker build --tag=<your-tag> .`
19+
- You should be able to verify that everything worked properly based on the output!

docker/pom.xml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
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">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.ibm</groupId>
5+
<artifactId>java-sdk-docker-app</artifactId>
6+
<packaging>jar</packaging>
7+
<version>1.0-SNAPSHOT</version>
8+
<name>java-sdk-docker-app</name>
9+
<url>http://maven.apache.org</url>
10+
<dependencies>
11+
<dependency>
12+
<groupId>junit</groupId>
13+
<artifactId>junit</artifactId>
14+
<version>3.8.1</version>
15+
<scope>test</scope>
16+
</dependency>
17+
<dependency>
18+
<groupId>com.ibm.watson</groupId>
19+
<artifactId>ibm-watson</artifactId>
20+
<version>7.3.1</version>
21+
</dependency>
22+
</dependencies>
23+
<properties>
24+
<maven.compiler.source>7</maven.compiler.source>
25+
<maven.compiler.target>7</maven.compiler.target>
26+
</properties>
27+
<build>
28+
<plugins>
29+
<plugin>
30+
<groupId>org.codehaus.mojo</groupId>
31+
<artifactId>exec-maven-plugin</artifactId>
32+
<version>1.6.0</version>
33+
<executions>
34+
<execution>
35+
<goals>
36+
<goal>java</goal>
37+
</goals>
38+
</execution>
39+
</executions>
40+
</plugin>
41+
</plugins>
42+
</build>
43+
</project>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.ibm;
2+
3+
public class DockerTest {
4+
public static void main(String[] args) {
5+
System.out.println("Hello world!");
6+
}
7+
}

0 commit comments

Comments
 (0)