Skip to content

Commit 370316f

Browse files
authored
Merge pull request #50 from D3ryk/dockerization
Dockerization via fabric8 plugin
2 parents 0f0ca6a + 91aed37 commit 370316f

File tree

7 files changed

+165
-1
lines changed

7 files changed

+165
-1
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ application.properties
2727
test_repository/
2828
/pom.xml.releaseBackup
2929
/release.properties
30-
logs/
30+
logs/
31+
boxes/

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ $ ./mvnw spring-boot:run
1818

1919
By default, http server will start on port *8083*.
2020

21+
## Docker
22+
23+
```
24+
$ ./mvnw clean package docker:build docker:start
25+
```
26+
or
27+
```
28+
$ ./mvnw clean package docker:build docker:run
29+
```
30+
31+
By default, container expose port *8083* with running app. Files with boxes needs to be stored in ./boxes dir.
2132
#### Build status (travis-ci)
2233

2334
devel [![Build Status](https://travis-ci.org/sparkoo/boxitory.svg?branch=devel)](https://travis-ci.org/sparkoo/boxitory)

pom.xml

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@
6464
<maven-release-plugin.version>2.5.3</maven-release-plugin.version>
6565
<cobertura-maven-plugin.version>2.7</cobertura-maven-plugin.version>
6666
<maven-surefire-plugin.version>2.22.1</maven-surefire-plugin.version>
67+
<docker-maven-plugin.version>0.28.0</docker-maven-plugin.version>
68+
<app.boxes.home>./boxes</app.boxes.home>
69+
<app.logs>./logs</app.logs>
70+
<app.properties.path>./src/main/resources/application.properties</app.properties.path>
6771
</properties>
6872

6973
<dependencies>
@@ -159,6 +163,97 @@
159163
</execution>
160164
</executions>
161165
</plugin>
166+
<plugin>
167+
<groupId>org.codehaus.mojo</groupId>
168+
<artifactId>properties-maven-plugin</artifactId>
169+
<version>1.0.0</version>
170+
<executions>
171+
<execution>
172+
<phase>initialize</phase>
173+
<goals>
174+
<goal>read-project-properties</goal>
175+
</goals>
176+
<configuration>
177+
<files>
178+
<file>${app.properties.path}</file>
179+
</files>
180+
</configuration>
181+
</execution>
182+
</executions>
183+
</plugin>
184+
<plugin>
185+
<groupId>io.fabric8</groupId>
186+
<artifactId>docker-maven-plugin</artifactId>
187+
<version>${docker-maven-plugin.version}</version>
188+
189+
<configuration>
190+
<dockerHost>unix:///var/run/docker.sock</dockerHost>
191+
192+
<verbose>true</verbose>
193+
<images>
194+
<image>
195+
<name>boxitory</name>
196+
<build>
197+
<dockerFileDir>${project.basedir}/target/dockerfile/</dockerFileDir>
198+
199+
<!--copies artficact to docker build dir in target-->
200+
<assembly>
201+
<mode>dir</mode>
202+
<descriptor>${project.basedir}/src/main/resources/assembly/release.xml</descriptor>
203+
</assembly>
204+
<tags>
205+
<tag>latest</tag>
206+
<tag>${project.version}</tag>
207+
</tags>
208+
</build>
209+
<run>
210+
<ports>
211+
<!--suppress UnresolvedMavenProperty -->
212+
<!--application.properties variable-->
213+
<port>${server.port}:${server.port}</port>
214+
</ports>
215+
<volumes>
216+
<bind>
217+
<!--suppress UnresolvedMavenProperty -->
218+
<volume>${app.boxes.home}:${box.container.home}</volume>
219+
<!--suppress UnresolvedMavenProperty -->
220+
<volume>${app.properties.path}:${box.container.home}/application.properties</volume>
221+
<!--suppress UnresolvedMavenProperty -->
222+
<volume>${app.logs}:${box.container.home}/logs</volume>
223+
</bind>
224+
</volumes>
225+
</run>
226+
</image>
227+
</images>
228+
</configuration>
229+
</plugin>
230+
<plugin>
231+
<groupId>org.codehaus.gmavenplus</groupId>
232+
<artifactId>gmavenplus-plugin</artifactId>
233+
<version>1.5</version>
234+
<executions>
235+
<execution>
236+
<phase>prepare-package</phase>
237+
<goals>
238+
<goal>execute</goal>
239+
</goals>
240+
</execution>
241+
</executions>
242+
<configuration>
243+
<scripts>
244+
<script>file:///${project.basedir}/src/main/scripts/BuildDockerfile.groovy</script>
245+
</scripts>
246+
</configuration>
247+
<dependencies>
248+
<dependency>
249+
<groupId>org.codehaus.groovy</groupId>
250+
<artifactId>groovy-all</artifactId>
251+
<!-- any version of Groovy \>= 1.5.0 should work here -->
252+
<version>2.4.8</version>
253+
<scope>runtime</scope>
254+
</dependency>
255+
</dependencies>
256+
</plugin>
162257
</plugins>
163258
</build>
164259
</project>

src/main/resources/DockerfileTemplate

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM openjdk:8
2+
3+
ADD maven/${fileName}.jar ${fileName}.jar
4+
RUN touch /${fileName}
5+
6+
WORKDIR ${workdir}
7+
ADD maven/application.properties ${workdir}
8+
ADD maven/logs/ ${workdir}
9+
10+
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/${fileName}.jar"]

src/main/resources/application.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@
99
server.port=8083
1010

1111
# Absolute or relative path to box repository root.
12+
# If you are running boxitory via docker plugin don't change this and put your boxes into /boxes directory
1213
box.home=.
1314

15+
# Absolute path to home of boxitory inside of container.
16+
box.container.home=/home/boxitory
17+
1418
# Prefix that is exploited on HTTP API and is prepended before box absolute path in url.
1519
# Typically it's protocol + hostname (e.g. 'sftp://username@hostname:' )
1620
box.host_prefix=
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0
3+
http://maven.apache.org/xsd/assembly-2.0.0.xsd">
4+
<formats>
5+
<format>jar</format>
6+
</formats>
7+
8+
<files>
9+
<file>
10+
<source>target/${project.build.finalName}.jar</source>
11+
<outputDirectory>/</outputDirectory>
12+
</file>
13+
<file>
14+
<source>${project.basedir}/src/main/resources/application.properties</source>
15+
<outputDirectory>/</outputDirectory>
16+
</file>
17+
<file>
18+
<source>${project.basedir}/logs/</source>
19+
<outputDirectory>/</outputDirectory>
20+
</file>
21+
</files>
22+
</assembly>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Properties props = new Properties()
2+
File propsFile = new File("${project.basedir}/src/main/resources/application.properties")
3+
props.load(propsFile.newDataInputStream())
4+
5+
String template = new File("${project.basedir}/src/main/resources/DockerfileTemplate".toString()).getText()
6+
7+
def dockerFileText = new groovy.text.SimpleTemplateEngine().createTemplate(template)
8+
.make([
9+
fileName: project.build.finalName,
10+
workdir: props.getProperty("box.container.home")
11+
])
12+
13+
println "writing dir " + "${project.basedir}/target/dockerfile"
14+
new File("${project.basedir}/target/dockerfile/".toString()).mkdirs()
15+
16+
println "writing file"
17+
File dockerFile = new File("${project.basedir}/target/dockerfile/Dockerfile".toString())
18+
19+
dockerFile.withWriter('UTF-8') { writer ->
20+
writer.write(dockerFileText)
21+
}

0 commit comments

Comments
 (0)