Skip to content

Commit 8b2ef3d

Browse files
committed
minimal docker app #560
1 parent ba501dc commit 8b2ef3d

File tree

3 files changed

+121
-31
lines changed

3 files changed

+121
-31
lines changed

md/doc/deployment/deployment.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ It works for ```logback.xml``` too, if ```logback.[env].xml``` is present, then
8888

8989
{{capsule.md}}
9090

91+
{{docker.md}}
92+
9193
{{public-dir.md}}
9294

9395
# war?

md/docker.md

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,43 +6,46 @@ Docker is the world’s leading software containerization platform. You can easi
66

77
You need [docker](https://docs.docker.com/engine/installation/) installed on the building machine.
88

9-
Add the following to the pom.xml under plugins:
10-
11-
```xml
12-
<plugin>
13-
<groupId>com.spotify</groupId>
14-
<artifactId>docker-maven-plugin</artifactId>
15-
<version>0.4.13</version>
16-
<configuration>
17-
<imageName>my-jooby-image</imageName>
18-
<baseImage>openjdk:jre-alpine</baseImage>
19-
<entryPoint>["java", "-jar", "/${project.build.finalName}.jar"]</entryPoint>
20-
<exposes>
21-
<expose>8080</expose>
22-
</exposes>
23-
<resources>
24-
<resource>
25-
<targetPath>/</targetPath>
26-
<directory>${project.build.directory}</directory>
27-
<include>${project.build.finalName}.jar</include>
28-
</resource>
29-
</resources>
30-
</configuration>
31-
</plugin>
32-
```
33-
34-
In order to create the **docker image** go to your project home, open a terminal and run:
9+
Maven users have two options: one for a building a [fat jar](/doc/deployment/#fat-jar) and one for building a [stork](/doc/deployment/#stork) distribution.
10+
11+
Gradle users might want to choose one of the available [plugins](https://plugins.gradle.org/search?term=docker).
12+
13+
### fat jar
14+
15+
* Write a `src/etc/docker.activator` file. File contents doesn't matter, the file presence activates a Maven profile.
16+
17+
* Open a terminal and run:
18+
19+
```bash
20+
mvn clean package docker:build
21+
```
22+
23+
* Once it finish, the docker image will be build and tagged as `${project.artifactId}`.
24+
25+
* You can now run the image with:
3526

3627
```bash
37-
mvn clean docker:build
28+
docker run -p 80:8080 ${project.artifactId}
3829
```
3930

40-
Once it finish, the docker image will be build and tagged as ```my-jooby-image```.
31+
The Maven profile trigger the [spotify/docker-maven-plugin](https://github.com/spotify/docker-maven-plugin) which generates a `docker` file. Please checkout the [doc](https://github.com/spotify/docker-maven-plugin) for more datails.
32+
33+
### stork
34+
35+
* Write a `src/etc/docker.stork.activator` file. File contents doesn't matter, the file presence activates a Maven profile.
36+
37+
* Open a terminal and run:
4138

42-
## run / start
39+
```bash
40+
mvn clean package docker:build
41+
```
4342

44-
You can now run the image with:
43+
* Once it finish, the docker image will be build and tagged as `${project.artifactId}`.
44+
45+
* You can now run the image with:
4546

4647
```bash
47-
docker run -p 80:8080 my-jobby-image
48+
docker run -it -p 80:8080 ${project.artifactId}
4849
```
50+
51+
The Maven profile trigger the [spotify/docker-maven-plugin](https://github.com/spotify/docker-maven-plugin) which generates a `docker` file. Please checkout the [doc](https://github.com/spotify/docker-maven-plugin) for more datails.

pom.xml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2136,6 +2136,90 @@
21362136
</build>
21372137
</profile>
21382138

2139+
<!-- docker -->
2140+
<profile>
2141+
<id>docker.jar</id>
2142+
<activation>
2143+
<file>
2144+
<exists>${basedir}${file.separator}src${file.separator}etc${file.separator}docker.activator</exists>
2145+
</file>
2146+
</activation>
2147+
<properties>
2148+
<docker.expose>8080</docker.expose>
2149+
<docker.targetPath>/</docker.targetPath>
2150+
<docker.directory>${project.build.directory}</docker.directory>
2151+
<docker.include>${project.build.finalName}.jar</docker.include>
2152+
</properties>
2153+
<build>
2154+
<plugins>
2155+
<plugin>
2156+
<groupId>com.spotify</groupId>
2157+
<artifactId>docker-maven-plugin</artifactId>
2158+
<version>${docker-maven-plugin.version}</version>
2159+
<configuration>
2160+
<imageName>${project.artifactId}</imageName>
2161+
<baseImage>openjdk:jre-alpine</baseImage>
2162+
<entryPoint>["java", "-jar", "/${project.build.finalName}.jar"]</entryPoint>
2163+
<exposes>
2164+
<expose>${docker.expose}</expose>
2165+
</exposes>
2166+
<resources>
2167+
<resource>
2168+
<targetPath>${docker.targetPath}</targetPath>
2169+
<directory>${docker.directory}</directory>
2170+
<include>${docker.include}</include>
2171+
</resource>
2172+
</resources>
2173+
</configuration>
2174+
</plugin>
2175+
</plugins>
2176+
</build>
2177+
</profile>
2178+
2179+
<profile>
2180+
<id>docker.stork</id>
2181+
<activation>
2182+
<file>
2183+
<exists>${basedir}${file.separator}src${file.separator}etc${file.separator}docker.stork.activator</exists>
2184+
</file>
2185+
</activation>
2186+
<properties>
2187+
<docker.expose>8080</docker.expose>
2188+
<docker.targetPath>./</docker.targetPath>
2189+
<docker.workdir>/opt/${project.artifactId}</docker.workdir>
2190+
<docker.directory>${project.build.directory}</docker.directory>
2191+
<docker.include>${project.build.finalName}.stork.zip</docker.include>
2192+
</properties>
2193+
<build>
2194+
<plugins>
2195+
<plugin>
2196+
<groupId>com.spotify</groupId>
2197+
<artifactId>docker-maven-plugin</artifactId>
2198+
<version>${docker-maven-plugin.version}</version>
2199+
<configuration>
2200+
<imageName>${project.artifactId}</imageName>
2201+
<baseImage>openjdk:jre-alpine</baseImage>
2202+
<entryPoint>["bin/${project.artifactId}", "--run"]</entryPoint>
2203+
<workdir>${docker.workdir}</workdir>
2204+
<exposes>
2205+
<expose>${docker.expose}</expose>
2206+
</exposes>
2207+
<runs>
2208+
<run>unzip ${project.build.finalName}.stork.zip</run>
2209+
</runs>
2210+
<resources>
2211+
<resource>
2212+
<targetPath>${docker.targetPath}</targetPath>
2213+
<directory>${docker.directory}</directory>
2214+
<include>${docker.include}</include>
2215+
</resource>
2216+
</resources>
2217+
</configuration>
2218+
</plugin>
2219+
</plugins>
2220+
</build>
2221+
</profile>
2222+
21392223
<!-- checkstyle -->
21402224
<profile>
21412225
<id>checkstyle</id>
@@ -2666,6 +2750,7 @@ org.eclipse.jdt.apt.processorOptions/defaultOverwrite=true
26662750
<build-helper-maven-plugin.version>1.9.1</build-helper-maven-plugin.version>
26672751
<fizzed-stork-maven-plugin.version>1.2.3</fizzed-stork-maven-plugin.version>
26682752
<capsule-maven-plugin.version>1.0.4</capsule-maven-plugin.version>
2753+
<docker-maven-plugin.version>0.4.13</docker-maven-plugin.version>
26692754

26702755
<jooby.version>${project.version}</jooby.version>
26712756
<jooby-maven-plugin.version>${jooby.version}</jooby-maven-plugin.version>

0 commit comments

Comments
 (0)