How to configure a verticle with config file using the vertx/vertx3 docker file

1,046 views
Skip to first unread message

Tim Fox

unread,
Jun 16, 2016, 5:23:13 AM6/16/16
to vert.x
Hi,

I'm trying to adapt the docker f8 example to build a docker image that runs the verticle with a -conf some/path/to/conf.json on the command line.

I can't for the life of me figure out how to include the conf.json file in the docker image to get this to work.

Any ideas?

Raphaël Luta

unread,
Jun 16, 2016, 5:30:37 AM6/16/16
to ve...@googlegroups.com
You need to mount it into the container at runtime with docker run -v option. It can work directly with a file.

For docker deployment, I typically run a wrapper script before vert.x that fetches config from an URL and interpolate ENV variables in the config before actually running vert.x.

-- raphael
> --
> You received this message because you are subscribed to the Google Groups "vert.x" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
> Visit this group at https://groups.google.com/group/vertx.
> To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/286c95b3-77bc-4de8-be81-59b2928e0069%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

signature.asc

Tim Fox

unread,
Jun 16, 2016, 5:51:17 AM6/16/16
to vert.x
Thanks, but not sure how to do that with the f8 example, as it's all controlled by Maven:



On Thursday, 16 June 2016 10:30:37 UTC+1, Raphaël Luta wrote:
You need to mount it into the container at runtime with docker run -v option. It can work directly with a file.

For docker deployment, I typically run a wrapper script before vert.x that fetches config from an URL and interpolate ENV variables in the config before actually running vert.x.

-- raphael

> Le 16 juin 2016 à 11:23, Tim Fox <timv...@gmail.com> a écrit :
>
> Hi,
>
> I'm trying to adapt the docker f8 example to build a docker image that runs the verticle with a -conf some/path/to/conf.json on the command line.
>
> I can't for the life of me figure out how to include the conf.json file in the docker image to get this to work.
>
> Any ideas?
>
> --
> You received this message because you are subscribed to the Google Groups "vert.x" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to vertx+unsubscribe@googlegroups.com.

Raphaël Luta

unread,
Jun 16, 2016, 7:11:47 AM6/16/16
to ve...@googlegroups.com
Sorry I misunderstood the initial question, I thought you were looking for runtime config management.

To include the conf file in the build image, you can edit the src/main/docker/assembly.xml and include your myconf.json config file, for example:

<assembly>
<dependencySets>
<dependencySet>
<includes>
<include>:${project.artifactId}</include>
</includes>
<outputDirectory>.</outputDirectory>
</dependencySet>
</dependencySets>
<files>
<file>
<outputDirectory>.</outputDirectory>
<source>conf/myconf.json</source>
</file>
</files>
</assembly>

You can then edit the pom.xml to update the docker image configuration XML exec clause to :
<cmd>
<exec>
<arg>vertx</arg>
<arg>run</arg>
<arg>${verticle.name}</arg>
<arg>-cp</arg>
<arg>/usr/verticles/${project.artifactId}-${project.version}.jar</arg>
<arg>-conf</arg>
<arg>/usr/verticles/myconf.json</arg>
</exec>
</cmd>

It works for me on a local docker and it seems it's baked into the image, it should also work on fabric8

-- raphael

> Le 16 juin 2016 à 11:51, Tim Fox <timv...@gmail.com> a écrit :
>
> Thanks, but not sure how to do that with the f8 example, as it's all controlled by Maven:
>
> https://github.com/vert-x3/vertx-examples/tree/master/docker-examples/vertx-docker-example-fabric8
>
> On Thursday, 16 June 2016 10:30:37 UTC+1, Raphaël Luta wrote:
> You need to mount it into the container at runtime with docker run -v option. It can work directly with a file.
>
> For docker deployment, I typically run a wrapper script before vert.x that fetches config from an URL and interpolate ENV variables in the config before actually running vert.x.
>
> -- raphael
>
> > Le 16 juin 2016 à 11:23, Tim Fox <timv...@gmail.com> a écrit :
> >
> > Hi,
> >
> > I'm trying to adapt the docker f8 example to build a docker image that runs the verticle with a -conf some/path/to/conf.json on the command line.
> >
> > I can't for the life of me figure out how to include the conf.json file in the docker image to get this to work.
> >
> > Any ideas?
> >
> > --
> > You received this message because you are subscribed to the Google Groups "vert.x" group.
> > To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
> --
> You received this message because you are subscribed to the Google Groups "vert.x" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
> To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/00bb91d3-c6f6-41eb-8c7c-6c5be5db0894%40googlegroups.com.
signature.asc

Clement Escoffier

unread,
Jun 16, 2016, 11:58:02 AM6/16/16
to ve...@googlegroups.com
Hello,

Here is “generic” docker file I use every time I’m using Openshift 3 / Kubernetes :

FROM java:8u92-jre-alpine

ENV VERTICLE_FILE my-jar-1.0.0-SNAPSHOT-fat.jar <— change here
ENV VERTICLE_HOME /usr/verticles

EXPOSE 8080

COPY target/$VERTICLE_FILE $VERTICLE_HOME/
COPY src/conf/ $VERTICLE_HOME/
RUN chmod 777 $VERTICLE_HOME <— only required on Openshift Enterprise, if you forgot to give the permission in the SCC

WORKDIR $VERTICLE_HOME
ENTRYPOINT ["sh", "-c"]
CMD ["java -jar $VERTICLE_FILE -conf config.json -cp . -cluster] <- change here
If you plan to create a distributed application (cluster), check https://github.com/vert-x3/vertx-service-discovery/blob/master/vertx-service-discovery-bridge-kubernetes/HAZELCAST_DISCOVERY_EXTENSION.md. Don’t forget to add the view permission to the user.

With the previous dockerFile, deploy to Openshift using:
oc new-build --binary --name=hello -l app=hello
mvn package; oc start-build hello --from-dir=. --follow
oc new-app hello -l app=hello
oc expose service hello -l vertx-cluster=true
For the fabric8 maven plugin, check this pom file: https://gist.github.com/cescoffier/0b3bd518141f42034e6b73edd6bd6564. It packages your project as a fat jar and deploy it on Openshift / Kubernetes using "mvn clean package docker:build fabric8:json fabric8:apply -Popenshift" (I should change the profile name). 
You may need this in your env:
export FABRIC8_PROFILES=kubernetes
export KUBERNETES_MASTER=https://10.1.2.2:8443/  <— that’s CDK, you may run a different kubernetes / openshift

Clement


Reply all
Reply to author
Forward
0 new messages