Skip to content

Commit

Permalink
step-11/docker
Browse files Browse the repository at this point in the history
Use docker to simulate different machines
  • Loading branch information
ligangty authored and tristantarrant committed Jun 22, 2020
1 parent dd3c994 commit 78678c3
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,11 @@ To see the changes between any two lessons use the git diff command.
- Run `mvn clean package` to rebuild the application
- Run `mvn exec:exec` to execute the application. In case you're running a clustered step, run this from
multiple terminals, where each instance will represent a node
- Run `mvn clean package docker:build` to build docker image, and then run `docker run infinispan-embedded-tutorial/infinispan-embedded-tutorial` in 2 different terminals to simulate multiple nodes of distributed cache

## Application Directory Layout

docker/ -->
src/ -->
main/ -->
java/ -->
Expand Down
14 changes: 14 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM jboss/base-jdk:8

USER root
RUN yum install -y iproute
ADD launch.sh /usr/bin/launch.sh
RUN chmod +x /usr/bin/launch.sh
RUN mkdir -p /opt/infinispan-embedded-tutorial/
RUN chown jboss:jboss /opt/infinispan-embedded-tutorial/

USER jboss
ADD infinispan-embedded-tutorial-1.0.0-SNAPSHOT-jar-with-dependencies.jar /opt/infinispan-embedded-tutorial/infinispan-embedded-tutorial.jar

ENTRYPOINT /usr/bin/launch.sh

7 changes: 7 additions & 0 deletions docker/launch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

IPADDR=$(ip a s | sed -ne '/127.0.0.1/!{s/^[ \t]*inet[ \t]*\([0-9.]\+\)\/.*$/\1/p}')
echo $IPADDR

/usr/bin/java -Djava.net.preferIPv4Stack=true -Djgroups.bind_addr=$IPADDR -jar /opt/infinispan-embedded-tutorial/infinispan-embedded-tutorial.jar

46 changes: 44 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,28 @@
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>org.infinispan.tutorial.embedded.WeatherApp</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
Expand All @@ -72,8 +94,28 @@
<argument>org.infinispan.tutorial.embedded.WeatherApp</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>1.2.0</version>
<configuration>
<skipDockerBuild>false</skipDockerBuild>
<imageName>infinispan-embedded-tutorial/${project.artifactId}</imageName>
<imageTags>
<imageTag>${project.version}</imageTag>
</imageTags>
<dockerDirectory>${project.basedir}/docker</dockerDirectory>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}-jar-with-dependencies.jar</include>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>
</project>

0 comments on commit 78678c3

Please sign in to comment.