Last updated on 16th July 2024
Before you begin make sure your model is added inside org.models package
, and registered inside the main class. You should also confirm being able to run locally before deploying.
The first step is to make a few changes to your pom.xml (if not pulling from the quickstart repo). Make sure you add the jodatime and junit versions to your properties section.
pom.xml
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<jodatime.version>2.10.1</jodatime.version>
<junit.version>5.3.2</junit.version>
</properties>
You will then want to add the jodatime and junit dependencies to the section starting with '
pom.xml
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>${jodatime.version}</version>
</dependency>
Finally you will add the plugins for assembling and dockerize-ing the project.
pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>allinone</shadedClassifierName>
<artifactSet>
<includes>
<include>*:*</include>
</includes>
</artifactSet>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>reference.conf</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<main-Class>Main</main-Class>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>1.0.0</version>
<configuration>
<imageName>simudyne-maven-docker</imageName>
<baseImage>simudyne/scala-sbt:2.11.12.1.0.4</baseImage>
<entryPoint>["java", "-jar", "/${project.build.finalName}-allinone.jar"]</entryPoint>
<!-- copy the service's jar file from target into the root directory of the image -->
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}-allinone.jar</include>
</resource>
<resource>
<targetPath>/root</targetPath>
<directory>.</directory>
<include>licenseKey</include>
</resource>
<resource>
<targetPath>/</targetPath>
<directory>.</directory>
<include>simudyneSDK.properties</include>
</resource>
</resources>
</configuration>
</plugin>
You will now push the docker image you have created to the Docker hub. You will want to replace the following things.
An example of this would be simudyne/simu-repo:demos
sudo docker tag [build] [account]/[repo-name]:[tag]
sudo docker push [account]/[repo-name]
You should be able to navigate to the Docker hub and confirm your image has been updated.
You must first log into the VM or server which you are deploying on. Please make sure the appropriate firewall and ports are made available based on either your public or intranet settings.
Pull the image using the details you specified above.
sudo docker pull [account]/[repo-name]:[tag]
You will likely already be running a container if not please skip to the next step. However, if you are you need to stop the existing container.
sudo docker ps #to identify the container ID
sudo docker stop <containerID>
You will then look for the exact image name, and then run it with the following configuration options.
An example of this would be 'docker run -p 80:80 f3c0fa608b22 0.0.0.0 80'
sudo docker images # to have a look at the available images and get ImageID
sudo docker run -p <port>:<port> <ImageID> <ip> <port>
Once completed you should be able to go to the IP or DNS address of the server you've deployed on (mind the port) and see the console as you would locally.