Skip to content

Commit

Permalink
Merge pull request vert-x#25 from vert-x3/docker-examples
Browse files Browse the repository at this point in the history
Move the docker examples from the vert-stack to the vert-examples
  • Loading branch information
purplefox committed Jun 4, 2015
2 parents ea519ad + 964a09e commit 2b6f74f
Show file tree
Hide file tree
Showing 23 changed files with 693 additions and 5 deletions.
89 changes: 89 additions & 0 deletions docker-examples/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
= Vert.x Doker Examples

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].

== vertx-docker-java

This example deploys a Java verticle inside Docker.

The link:vertx-docker-java

To build and run it:
----
docker build -t sample/vertx-java .
docker run -t -i -p 8080:8080 sample/vertx-java
----

== vertx-docker-javascript

This example deploys a JavaScript verticle inside Docker.

The link:vertx-docker-javascript

To build and run it:
----
docker build -t sample/vertx-javascript .
docker run -t -i -p 8080:8080 sample/vertx-javascript
----

== vertx-docker-groovy

This example deploys a Groovy verticle inside Docker.

The link:vertx-docker-groovy

To build and run it:
----
docker build -t sample/vertx-groovy .
docker run -t -i -p 8080:8080 sample/vertx-groovy
----

== vertx-docker-ruby

This example deploys a Ruby verticle inside Docker.

The link:vertx-docker-ruby

To build and run it:
----
docker build -t sample/vertx-ruby .
docker run -t -i -p 8080:8080 sample/vertx-ruby
----

== vertx-docker-example

This example builds and deploys a Java verticle inside Docker using Apache Maven

The link:vertx-docker-example

To build and run it:
----
mvn clean package
docker run -t -i -p 8080:8080 vertx/vertx3-example
----

== vertx-docker-example-fabric8

This example builds and deploys a Java verticle inside Docker and generate the medatadata required by Fabric8.

The link:vertx-docker-example-fabric8

To build and run it:
----
mvn clean package
# Set $DOCKER_REGISTRY to poin on the Docker Registry provided by Fabric8
docker push $DOCKER_REGISTRY/vertx/vertx3-example-fabric8
mvn io.fabric8:fabric8-maven-plugin:2.1.4:apply
----

== vertx-docker-java-fatjar

This example deploys a Java verticle inside Docker. The verticle is packaged as a _fat jar_.

The link:vertx-docker-java-fatjar

To build and run it:
----
docker build -t sample/vertx-java-fat .
docker run -t -i -p 8080:8080 sample/vertx-java-fat
----
25 changes: 25 additions & 0 deletions docker-examples/vertx-docker-example-fabric8/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Vert.x Docker Example for Fabric8

This project builds a docker image launching a very simple Vert.x verticle that you can deploy using Fabric8

# Build the image

To build the docker image, just launch:

`mvn clean package`

Notice that you need to have docker installed on your machine.

# Deployment on Fabric8

The build creates the `kubernates.json` file with the required metadata.

First, deploy the image on the Docker registry manage by fabric8:

`docker push $DOCKER_REGISTRY/vertx/vertx3-example-fabric8`

Then, apply it:

`mvn io.fabric8:fabric8-maven-plugin:2.1.4:apply`

That's all.
115 changes: 115 additions & 0 deletions docker-examples/vertx-docker-example-fabric8/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>io.vertx</groupId>
<artifactId>vertx-examples</artifactId>
<version>3.0.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<modelVersion>4.0.0</modelVersion>

<artifactId>vertx-docker-example-fabric</artifactId>
<name>Sample Docker Image for Fabric8</name>

<properties>
<!-- Metadata to generate the kubernates.json - ignore them if you don't plan to use kubernates / fabric8 -->
<docker.image>vertx/vertx3-example-fabric8</docker.image>
<fabric8.label.container>vert.x</fabric8.label.container>
<fabric8.label.group>example</fabric8.label.group>
<docker.port.container.http>8080</docker.port.container.http>
</properties>


<dependencies>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>

<plugin>
<groupId>org.jolokia</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.11.5</version>
<executions>
<execution>
<id>build</id>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
<configuration>
<images>
<image>
<name>${docker.image}</name>
<build>
<from>vertx/vertx3</from>
<tags>
<tag>${project.version}</tag>
</tags>
<ports>
<port>8080</port>
</ports>
<command>vertx run io.vertx.example.HelloWorldVerticle -cp
/usr/verticles/${project.artifactId}-${project.version}.jar
</command>
<assembly>
<mode>dir</mode>
<basedir>/usr/verticles</basedir>
<descriptor>assembly.xml</descriptor>
</assembly>
</build>
</image>
</images>
</configuration>
</plugin>

<plugin>
<groupId>io.fabric8</groupId>
<artifactId>fabric8-maven-plugin</artifactId>
<version>2.1.4</version>
<executions>
<execution>
<id>json</id>
<phase>generate-resources</phase>
<goals>
<goal>json</goal>
</goals>
</execution>
<execution>
<id>attach</id>
<phase>package</phase>
<goals>
<goal>attach</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<!-- should not be deployed -->
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<assembly>
<dependencySets>
<dependencySet>
<includes>
<include>:${project.artifactId}</include>
</includes>
<outputDirectory>.</outputDirectory>
</dependencySet>
</dependencySets>
</assembly>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.vertx.example;

import io.vertx.core.AbstractVerticle;


public class HelloWorldVerticle extends AbstractVerticle {

@Override
public void start() throws Exception {
vertx.createHttpServer().requestHandler(req -> req.response().end("Hello World!")).listen(8080);
}

}
19 changes: 19 additions & 0 deletions docker-examples/vertx-docker-example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Vert.x Docker Example

This project builds a docker image launching a very simple Vert.x verticle.

# Build the image

To build the docker image, just launch:

`mvn clean package`

Notice that you need to have docker installed on your machine.

# Launching the image

Just launch:

`docker run -p 8080:8080 -i -t vertx/vertx3-example`

You should get a `Hello World` message on `http://localhost:8080`.
83 changes: 83 additions & 0 deletions docker-examples/vertx-docker-example/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>io.vertx</groupId>
<artifactId>vertx-examples</artifactId>
<version>3.0.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<modelVersion>4.0.0</modelVersion>

<artifactId>vertx-docker-example</artifactId>
<name>Sample Docker Image with Maven</name>

<properties>
<docker.image>vertx/vertx3-example</docker.image>
</properties>


<dependencies>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>

<plugin>
<!--
This plugin builds the Docker image. It merges src/main/docker/Dockerfile with the resources set in the
configuration. The resources should embed the current project and its dependencies. Here there is no
dependencies.
-->
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.2.8</version>
<executions>
<execution>
<id>docker</id>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
<configuration>
<dockerDirectory>${project.basedir}/src/main/docker</dockerDirectory>
<imageName>${docker.image}</imageName>
<resources>
<resource>
<targetPath>/verticles</targetPath>
<directory>${project.build.directory}</directory>
<includes>
<include>${project.artifactId}-${project.version}.jar</include>
</includes>
</resource>
</resources>
</configuration>
</plugin>

<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<!-- should not be deployed -->
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>
23 changes: 23 additions & 0 deletions docker-examples/vertx-docker-example/src/main/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# A simple example showing how the vertx image can be used.

FROM vertx/vertx3

# Set the location of the verticles
ENV VERTICLE_HOME /usr/verticles

# Set the name of the verticle to deploy
ENV VERTICLE_NAME io.vertx.example.HelloWorldVerticle

# Set vertx option
ENV VERTX_OPTIONS ""

###
# The rest of the file should be fine.
###

COPY ./verticles $VERTICLE_HOME

# We use the "sh -c" to turn around https://github.com/docker/docker/issues/5509 - variable not expanded
ENTRYPOINT ["sh", "-c"]
CMD ["vertx run $VERTICLE_NAME -cp $VERTICLE_HOME/* $VERTX_OPTIONS"]

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.vertx.example;

import io.vertx.core.AbstractVerticle;


public class HelloWorldVerticle extends AbstractVerticle {

@Override
public void start() throws Exception {
vertx.createHttpServer().requestHandler(req -> req.response().end("Hello World!")).listen(8080);
}
}
Loading

0 comments on commit 2b6f74f

Please sign in to comment.