Skip to content

Commit c09aa64

Browse files
committed
feat: use dockerfile-maven-plugin for building Docker image.
Usage: - mvn package dockerfile:build for building WAR and an image - mvn dockerfile:push for pushing an image to Docker registry Fix #83 [ci skip]
1 parent ac4ca02 commit c09aa64

File tree

3 files changed

+41
-11
lines changed

3 files changed

+41
-11
lines changed

docker/README.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,17 @@ possible configurations, we support only those that are typically used:
77
In this mode, it also runs in-memory database H2. This is roughly the same as
88
executing `mvn spring-boot:run` command but inside a Docker container.
99

10-
* Create a WAR file that will be used for building an image:
10+
* Create a WAR file and build the image `phpcoder/mystamps:latest`:
1111
```console
12-
$ mvn package
13-
$ cd docker
14-
$ ln -fv ../target/mystamps.war mystamps.war
12+
$ mvn package dockerfile:build
1513
```
16-
By the way, don't forget to remove this hard link after using.
17-
* Build an image and run a container with `docker-compose`:
14+
* Run a container with `docker-compose`:
1815
```console
16+
$ cd docker
1917
$ docker-compose up -d
2018
```
21-
* The same but with a plain Docker:
19+
or with a plain Docker:
2220
```console
23-
$ docker build -t mystamps:latest .
24-
$ docker run -d -p 8080:8080 --cap-drop all mystamps:latest
21+
$ docker run -d -p 8080:8080 --cap-drop all phpcoder/mystamps:latest
2522
```
2623

docker/docker-compose.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ version: '3'
22

33
services:
44
web:
5-
build: ./
6-
image: mystamps:latest
5+
image: phpcoder/mystamps:latest
76
cap_drop:
87
- "ALL"
98
ports:

pom.xml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@
491491
<!-- Disable XML reports by default. Enabled manually by passing -DdisableXmlReport=false in CI environment -->
492492
<disableXmlReport>true</disableXmlReport>
493493

494+
<dockerfile.plugin.version>1.4.6</dockerfile.plugin.version>
494495
<enforcer.plugin.version>1.4.1</enforcer.plugin.version>
495496
<failsafe.plugin.version>2.22.0</failsafe.plugin.version>
496497
<fest.assert.version>2.0M8</fest.assert.version>
@@ -719,6 +720,17 @@
719720
</executions>
720721
</plugin>
721722

723+
<plugin>
724+
<groupId>com.spotify</groupId>
725+
<artifactId>dockerfile-maven-plugin</artifactId>
726+
<version>${dockerfile.plugin.version}</version>
727+
<configuration>
728+
<repository>phpcoder/mystamps</repository>
729+
<!-- TODO: set it to docker/ after https://github.com/spotify/dockerfile-maven/pull/89 will be merged -->
730+
<contextDirectory>target</contextDirectory>
731+
</configuration>
732+
</plugin>
733+
722734
<plugin>
723735
<groupId>org.apache.maven.plugins</groupId>
724736
<artifactId>maven-checkstyle-plugin</artifactId>
@@ -846,6 +858,28 @@
846858
<groupId>org.apache.maven.plugins</groupId>
847859
<artifactId>maven-resources-plugin</artifactId>
848860
<version>${resources.plugin.version}</version>
861+
<executions>
862+
<!-- TODO: remove this workaround after merging https://github.com/spotify/dockerfile-maven/pull/89 -->
863+
<execution>
864+
<id>copy-docker-resources</id>
865+
<goals>
866+
<goal>copy-resources</goal>
867+
</goals>
868+
<phase>prepare-package</phase>
869+
<configuration>
870+
<!-- copy docker/Dockerfile to target/ -->
871+
<outputDirectory>target</outputDirectory>
872+
<resources>
873+
<resource>
874+
<directory>${basedir}/docker</directory>
875+
<includes>
876+
<include>Dockerfile</include>
877+
</includes>
878+
</resource>
879+
</resources>
880+
</configuration>
881+
</execution>
882+
</executions>
849883
</plugin>
850884

851885
<plugin>

0 commit comments

Comments
 (0)