Skip to content

Commit 2b6f74f

Browse files
committed
Merge pull request vert-x#25 from vert-x3/docker-examples
Move the docker examples from the vert-stack to the vert-examples
2 parents ea519ad + 964a09e commit 2b6f74f

File tree

23 files changed

+693
-5
lines changed

23 files changed

+693
-5
lines changed

docker-examples/README.adoc

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
= Vert.x Doker Examples
2+
3+
Here you will find examples demonstrating how to run Vert.x applications in Docker container. To run these examples you need https://www.docker.com/[Docker] installed on your computer. More details about these examples are in the http://vert-x3.github.io/docs/vertx-docker/[Vert.x Docker Manual].
4+
5+
== vertx-docker-java
6+
7+
This example deploys a Java verticle inside Docker.
8+
9+
The link:vertx-docker-java
10+
11+
To build and run it:
12+
----
13+
docker build -t sample/vertx-java .
14+
docker run -t -i -p 8080:8080 sample/vertx-java
15+
----
16+
17+
== vertx-docker-javascript
18+
19+
This example deploys a JavaScript verticle inside Docker.
20+
21+
The link:vertx-docker-javascript
22+
23+
To build and run it:
24+
----
25+
docker build -t sample/vertx-javascript .
26+
docker run -t -i -p 8080:8080 sample/vertx-javascript
27+
----
28+
29+
== vertx-docker-groovy
30+
31+
This example deploys a Groovy verticle inside Docker.
32+
33+
The link:vertx-docker-groovy
34+
35+
To build and run it:
36+
----
37+
docker build -t sample/vertx-groovy .
38+
docker run -t -i -p 8080:8080 sample/vertx-groovy
39+
----
40+
41+
== vertx-docker-ruby
42+
43+
This example deploys a Ruby verticle inside Docker.
44+
45+
The link:vertx-docker-ruby
46+
47+
To build and run it:
48+
----
49+
docker build -t sample/vertx-ruby .
50+
docker run -t -i -p 8080:8080 sample/vertx-ruby
51+
----
52+
53+
== vertx-docker-example
54+
55+
This example builds and deploys a Java verticle inside Docker using Apache Maven
56+
57+
The link:vertx-docker-example
58+
59+
To build and run it:
60+
----
61+
mvn clean package
62+
docker run -t -i -p 8080:8080 vertx/vertx3-example
63+
----
64+
65+
== vertx-docker-example-fabric8
66+
67+
This example builds and deploys a Java verticle inside Docker and generate the medatadata required by Fabric8.
68+
69+
The link:vertx-docker-example-fabric8
70+
71+
To build and run it:
72+
----
73+
mvn clean package
74+
# Set $DOCKER_REGISTRY to poin on the Docker Registry provided by Fabric8
75+
docker push $DOCKER_REGISTRY/vertx/vertx3-example-fabric8
76+
mvn io.fabric8:fabric8-maven-plugin:2.1.4:apply
77+
----
78+
79+
== vertx-docker-java-fatjar
80+
81+
This example deploys a Java verticle inside Docker. The verticle is packaged as a _fat jar_.
82+
83+
The link:vertx-docker-java-fatjar
84+
85+
To build and run it:
86+
----
87+
docker build -t sample/vertx-java-fat .
88+
docker run -t -i -p 8080:8080 sample/vertx-java-fat
89+
----
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Vert.x Docker Example for Fabric8
2+
3+
This project builds a docker image launching a very simple Vert.x verticle that you can deploy using Fabric8
4+
5+
# Build the image
6+
7+
To build the docker image, just launch:
8+
9+
`mvn clean package`
10+
11+
Notice that you need to have docker installed on your machine.
12+
13+
# Deployment on Fabric8
14+
15+
The build creates the `kubernates.json` file with the required metadata.
16+
17+
First, deploy the image on the Docker registry manage by fabric8:
18+
19+
`docker push $DOCKER_REGISTRY/vertx/vertx3-example-fabric8`
20+
21+
Then, apply it:
22+
23+
`mvn io.fabric8:fabric8-maven-plugin:2.1.4:apply`
24+
25+
That's all.
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<groupId>io.vertx</groupId>
7+
<artifactId>vertx-examples</artifactId>
8+
<version>3.0.0-SNAPSHOT</version>
9+
<relativePath>../../pom.xml</relativePath>
10+
</parent>
11+
12+
<modelVersion>4.0.0</modelVersion>
13+
14+
<artifactId>vertx-docker-example-fabric</artifactId>
15+
<name>Sample Docker Image for Fabric8</name>
16+
17+
<properties>
18+
<!-- Metadata to generate the kubernates.json - ignore them if you don't plan to use kubernates / fabric8 -->
19+
<docker.image>vertx/vertx3-example-fabric8</docker.image>
20+
<fabric8.label.container>vert.x</fabric8.label.container>
21+
<fabric8.label.group>example</fabric8.label.group>
22+
<docker.port.container.http>8080</docker.port.container.http>
23+
</properties>
24+
25+
26+
<dependencies>
27+
<dependency>
28+
<groupId>io.vertx</groupId>
29+
<artifactId>vertx-core</artifactId>
30+
<version>3.0.0-SNAPSHOT</version>
31+
</dependency>
32+
</dependencies>
33+
34+
<build>
35+
<plugins>
36+
<plugin>
37+
<artifactId>maven-compiler-plugin</artifactId>
38+
<version>3.1</version>
39+
<configuration>
40+
<source>1.8</source>
41+
<target>1.8</target>
42+
</configuration>
43+
</plugin>
44+
45+
<plugin>
46+
<groupId>org.jolokia</groupId>
47+
<artifactId>docker-maven-plugin</artifactId>
48+
<version>0.11.5</version>
49+
<executions>
50+
<execution>
51+
<id>build</id>
52+
<phase>package</phase>
53+
<goals>
54+
<goal>build</goal>
55+
</goals>
56+
</execution>
57+
</executions>
58+
<configuration>
59+
<images>
60+
<image>
61+
<name>${docker.image}</name>
62+
<build>
63+
<from>vertx/vertx3</from>
64+
<tags>
65+
<tag>${project.version}</tag>
66+
</tags>
67+
<ports>
68+
<port>8080</port>
69+
</ports>
70+
<command>vertx run io.vertx.example.HelloWorldVerticle -cp
71+
/usr/verticles/${project.artifactId}-${project.version}.jar
72+
</command>
73+
<assembly>
74+
<mode>dir</mode>
75+
<basedir>/usr/verticles</basedir>
76+
<descriptor>assembly.xml</descriptor>
77+
</assembly>
78+
</build>
79+
</image>
80+
</images>
81+
</configuration>
82+
</plugin>
83+
84+
<plugin>
85+
<groupId>io.fabric8</groupId>
86+
<artifactId>fabric8-maven-plugin</artifactId>
87+
<version>2.1.4</version>
88+
<executions>
89+
<execution>
90+
<id>json</id>
91+
<phase>generate-resources</phase>
92+
<goals>
93+
<goal>json</goal>
94+
</goals>
95+
</execution>
96+
<execution>
97+
<id>attach</id>
98+
<phase>package</phase>
99+
<goals>
100+
<goal>attach</goal>
101+
</goals>
102+
</execution>
103+
</executions>
104+
</plugin>
105+
106+
<plugin>
107+
<artifactId>maven-deploy-plugin</artifactId>
108+
<configuration>
109+
<!-- should not be deployed -->
110+
<skip>true</skip>
111+
</configuration>
112+
</plugin>
113+
</plugins>
114+
</build>
115+
</project>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<assembly>
2+
<dependencySets>
3+
<dependencySet>
4+
<includes>
5+
<include>:${project.artifactId}</include>
6+
</includes>
7+
<outputDirectory>.</outputDirectory>
8+
</dependencySet>
9+
</dependencySets>
10+
</assembly>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package io.vertx.example;
2+
3+
import io.vertx.core.AbstractVerticle;
4+
5+
6+
public class HelloWorldVerticle extends AbstractVerticle {
7+
8+
@Override
9+
public void start() throws Exception {
10+
vertx.createHttpServer().requestHandler(req -> req.response().end("Hello World!")).listen(8080);
11+
}
12+
13+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Vert.x Docker Example
2+
3+
This project builds a docker image launching a very simple Vert.x verticle.
4+
5+
# Build the image
6+
7+
To build the docker image, just launch:
8+
9+
`mvn clean package`
10+
11+
Notice that you need to have docker installed on your machine.
12+
13+
# Launching the image
14+
15+
Just launch:
16+
17+
`docker run -p 8080:8080 -i -t vertx/vertx3-example`
18+
19+
You should get a `Hello World` message on `http://localhost:8080`.
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<groupId>io.vertx</groupId>
7+
<artifactId>vertx-examples</artifactId>
8+
<version>3.0.0-SNAPSHOT</version>
9+
<relativePath>../../pom.xml</relativePath>
10+
</parent>
11+
12+
<modelVersion>4.0.0</modelVersion>
13+
14+
<artifactId>vertx-docker-example</artifactId>
15+
<name>Sample Docker Image with Maven</name>
16+
17+
<properties>
18+
<docker.image>vertx/vertx3-example</docker.image>
19+
</properties>
20+
21+
22+
<dependencies>
23+
<dependency>
24+
<groupId>io.vertx</groupId>
25+
<artifactId>vertx-core</artifactId>
26+
<version>3.0.0-SNAPSHOT</version>
27+
</dependency>
28+
</dependencies>
29+
30+
<build>
31+
<plugins>
32+
<plugin>
33+
<artifactId>maven-compiler-plugin</artifactId>
34+
<version>3.1</version>
35+
<configuration>
36+
<source>1.8</source>
37+
<target>1.8</target>
38+
</configuration>
39+
</plugin>
40+
41+
<plugin>
42+
<!--
43+
This plugin builds the Docker image. It merges src/main/docker/Dockerfile with the resources set in the
44+
configuration. The resources should embed the current project and its dependencies. Here there is no
45+
dependencies.
46+
-->
47+
<groupId>com.spotify</groupId>
48+
<artifactId>docker-maven-plugin</artifactId>
49+
<version>0.2.8</version>
50+
<executions>
51+
<execution>
52+
<id>docker</id>
53+
<phase>package</phase>
54+
<goals>
55+
<goal>build</goal>
56+
</goals>
57+
</execution>
58+
</executions>
59+
<configuration>
60+
<dockerDirectory>${project.basedir}/src/main/docker</dockerDirectory>
61+
<imageName>${docker.image}</imageName>
62+
<resources>
63+
<resource>
64+
<targetPath>/verticles</targetPath>
65+
<directory>${project.build.directory}</directory>
66+
<includes>
67+
<include>${project.artifactId}-${project.version}.jar</include>
68+
</includes>
69+
</resource>
70+
</resources>
71+
</configuration>
72+
</plugin>
73+
74+
<plugin>
75+
<artifactId>maven-deploy-plugin</artifactId>
76+
<configuration>
77+
<!-- should not be deployed -->
78+
<skip>true</skip>
79+
</configuration>
80+
</plugin>
81+
</plugins>
82+
</build>
83+
</project>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# A simple example showing how the vertx image can be used.
2+
3+
FROM vertx/vertx3
4+
5+
# Set the location of the verticles
6+
ENV VERTICLE_HOME /usr/verticles
7+
8+
# Set the name of the verticle to deploy
9+
ENV VERTICLE_NAME io.vertx.example.HelloWorldVerticle
10+
11+
# Set vertx option
12+
ENV VERTX_OPTIONS ""
13+
14+
###
15+
# The rest of the file should be fine.
16+
###
17+
18+
COPY ./verticles $VERTICLE_HOME
19+
20+
# We use the "sh -c" to turn around https://github.com/docker/docker/issues/5509 - variable not expanded
21+
ENTRYPOINT ["sh", "-c"]
22+
CMD ["vertx run $VERTICLE_NAME -cp $VERTICLE_HOME/* $VERTX_OPTIONS"]
23+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package io.vertx.example;
2+
3+
import io.vertx.core.AbstractVerticle;
4+
5+
6+
public class HelloWorldVerticle extends AbstractVerticle {
7+
8+
@Override
9+
public void start() throws Exception {
10+
vertx.createHttpServer().requestHandler(req -> req.response().end("Hello World!")).listen(8080);
11+
}
12+
}

0 commit comments

Comments
 (0)