Coder Social home page Coder Social logo

vertx-openshift-s2i's Introduction

OpenShift S2I Builder for Vert.x

This Source-to-Image Builder let’s you create projects using Vert.x 3 and built with:

  • maven

  • gradle

This builder expect the build process to generate a (unique) "fat" jar (with a file ending with .jar).

Note
If a project has a pom.xml and a build.gradle, maven will take precedence

ENV Options

  • BUILDER_ARGS: Allows you to specify options to pass to maven or gradle

  • OUTPUT_DIR: The directory where the "fat-jar" is located. It can be adjusted when building a multi-module projects.

Defaults

If you do not specify any BUILDER_ARGS, by default the s2i image will use the following:

  • Maven

BUILDER_ARGS="package -Popenshift -DskipTests"
OUTPUT_DIR=target
  • Gradle

BUILDER_ARGS="build -x test"
OUTPUT_DIR=build/libs

Test in OpenShift

  • First load all the needed resources in a project.

oc create -f https://raw.githubusercontent.com/vert-x3/vertx-openshift-s2i/master/vertx-s2i-all.json
  • Once the builder vertx-s2i has finished building, you can create an app with:

    • Instant app already provided as template

    • Using the vertx-s2i builder image using a regular Git repository

Application configuration

  • APP_OPTIONS: let you pass options to the application, such as -cluster -cp ./cluster.xml…​

APP_OPTIONS are set using a .s2i/environment file in your source code:

APP_OPTIONS=-cluster -cp .:./cluster.xml

Additional files

This S2I builds the fat jar of your application, but also let you copy additional files. You can use this feature to copy configuration files (cluster.xml, json files). These files are copied in the deploy directory (/opt/openshift) and are copied from:

  • ./src/env

  • OUTPUT_DIR/env

The first location is used for mono-module project and files that does not require processing (at built time). The second location is used for multi-module projects, or for files having being processed during the packaging (filtering, computation…​).

Be aware that in the second case you would need to configure your build process to copy the files to the right location.

Clustered Vert.x application

To run clustered vert.x applications (with Hazelcast), you would need:

  1. some dependencies in your build descriptor to use the Hazelcast Kubernetes discovery

  2. a specific service for the event bus

  3. a specific cluster configuration

  4. set APP_OPTIONS to use this specific cluster configuration

1) Using Hazelcast Kubernetes discovery

Hazelcast 3.6+ propose a SPI to extend / customize the cluster member discovery. They provide a discovery extension for Kubernetes. To use it, you need to add the related artifact in your build descriptor. For Maven, do it as follows:

<dependency>
  <groupId>com.hazelcast</groupId>
  <artifactId>hazelcast</artifactId>
  <version>3.6.1</version>
</dependency>
<dependency>
  <groupId>io.vertx</groupId>
  <artifactId>vertx-hazelcast</artifactId>
</dependency>
<dependency>
  <groupId>com.noctarius.discovery</groupId>
  <artifactId>hazelcast-kubernetes-discovery</artifactId>
  <version>0.9.2</version>
</dependency>

You should update the version numbers to latest.

When the application is packaged (as a fat jar), it embeds the kubernetes discovery.

2) The vertx-eventbus service

To work, the hazelcast-kubernetes-discovery needs a known service. Let’s call this service vertx-eventbus. In a Openshift template (used to deploy a vert.x application), add:

{
   "kind" : "Service",
   "apiVersion" : "v1",
   "metadata" : {
     "name": "vertx-eventbus",
     "labels" : {
       "component" : "vertx-eventbus"
     }
   },
   "spec" : {
     "clusterIP" : "None",
     "ports" : [ {
       "port" : 5701,
       "protocol" : "TCP",
       "targetPort" : 5701
     } ],
     "selector": {
       "deploymentconfig": "YOUR_APPLICATION_NAME"
     }
  }
}

This service is headless. Your container should also declare the port 5701. For example:

"ports": [
  {
    "containerPort": 8080,
    "protocol": "TCP"
  },
  {
    "containerPort" : 5701,
    "protocol" : "TCP"
  }
],

IMPORTANT: do not use the port 5701 for liveness.

Only one of your application would publish this service in a given namespace / project.

3) Hazelcast configuration

Your vert.x application needs to use specific cluster.xml file. Create in the src/env directory, a cluster.xml file with the following content:

<?xml version="1.0" encoding="UTF-8"?>
<hazelcast xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-3.6.xsd"
           xmlns="http://www.hazelcast.com/schema/config"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <properties>
    <property name="hazelcast.mancenter.enabled">false</property>
    <property name="hazelcast.memcache.enabled">false</property>
    <property name="hazelcast.rest.enabled">false</property>
    <property name="hazelcast.wait.seconds.before.join">0</property>
    <property name="hazelcast.logging.type">jdk</property>

    <!-- at the moment the discovery needs to be activated explicitly -->
    <property name="hazelcast.discovery.enabled">true</property>
  </properties>

  <network>
    <port auto-increment="true" port-count="10000">5701</port>
    <outbound-ports>
      <ports>0</ports>
    </outbound-ports>
    <join>
      <multicast enabled="false"/>

      <tcp-ip enabled="false"/>
      <discovery-strategies>
        <discovery-strategy enabled="true"
                                class="com.noctarius.hazelcast.kubernetes.HazelcastKubernetesDiscoveryStrategy">
          <properties>
            <!-- configure discovery headless service lookup -->
            <property name="service-dns">vertx-eventbus.vertx-demo-cluster.svc.cluster.local</property>
          </properties>
        </discovery-strategy>
      </discovery-strategies>
    </join>
    <interfaces enabled="false">
      <interface>10.10.1.*</interface>
    </interfaces>
    <ssl enabled="false"/>
    <socket-interceptor enabled="false"/>
  </network>
  <partition-group enabled="false"/>
  <executor-service name="default">
    <pool-size>16</pool-size>
    <queue-capacity>0</queue-capacity>
  </executor-service>
  <map name="__vertx.subs">
    <backup-count>1</backup-count>
    <time-to-live-seconds>0</time-to-live-seconds>
    <max-idle-seconds>0</max-idle-seconds>
    <eviction-policy>NONE</eviction-policy>
    <max-size policy="PER_NODE">0</max-size>
    <eviction-percentage>25</eviction-percentage>
    <merge-policy>com.hazelcast.map.merge.LatestUpdateMapMergePolicy</merge-policy>
  </map>
  <semaphore name="__vertx.*">
    <initial-permits>1</initial-permits>
  </semaphore>
</hazelcast>

You need to edit the service-dns property value. The value is computed as follows: service-name (vertx-eventbus).project name.svc.cluster.local.

This cluster.xml file will be placed in the same directory as your application. The source to image is copying the file there.

4) Set the application options

Create a .s2i/environment file with the following content:

APP_OPTIONS=-cluster -cp .:./cluster.xml

Here you go, your application is now distributed, and you can use the event bus to send and receive events between nodes.

vertx-openshift-s2i's People

Contributors

cescoffier avatar noseka1 avatar pmlopes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vertx-openshift-s2i's Issues

s2i build doesn't working

Build fails: An error occurred while starting the build.
Reason: Error resolving ImageStreamTag vertx-s2i:latest in namespace developer: unable to find latest tagged image

Update s2i location

In latest version the s2i repository is not /user/local/sti but /user/local/s2i

Error trying to use the "initial-work"

Git repo used: https://github.com/redhat-helloworld-msa/aloha

Error in the builder image:

[INFO] ------------------------------------------------------------------------
850 [INFO] BUILD SUCCESS
851 [INFO] ------------------------------------------------------------------------
852 [INFO] Total time: 33.408 s
853 [INFO] Finished at: 2016-03-21T15:59:52+00:00
854 [INFO] Final Memory: 30M/154M
855 [INFO] ------------------------------------------------------------------------
856 [WARNING] The requested profile "openshift" could not be activated because it does not exist.
857 Copying all (fat) JAR artifacts from /opt/app-root/src/source/target directory into /opt/openshift for later deployment...
858 F0321 11:59:53.226834       1 builder.go:204] Error: build error: non-zero (13) exit code from 172.30.84.19:5000/helloworld-msa/vertx-s2i@sha256:2bfb06279a973a3bb63590e46f4ce07ea1ab093560e69d64b4f2708060055f1c

Apache mirror is offline

When trying to build the image, the download of maven from http://apache.rediris.es/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz gets time-out.

Error:

gzip: stdin: unexpected end of file tar: Child returned status 1 tar: Error is not recoverable: exiting now F0407 21:40:55.605241 1 builder.go:59] Build error: The command '/bin/sh -c yum install -y --enablerepo=centosplus tar unzip bc which lsof java-1.8.0-openjdk java-1.8.0-openjdk-devel && yum clean all -y && (curl -0 http://apache.rediris.es/maven/maven-3/$MAVEN_VERSION/binaries/apache-maven-$MAVEN_VERSION-bin.tar.gz | tar -zx -C /usr/local) && mv /usr/local/apache-maven-$MAVEN_VERSION /usr/local/maven && ln -sf /usr/local/maven/bin/mvn /usr/local/bin/mvn && curl -sL -0 https://services.gradle.org/distributions/gradle-${GRADLE_VERSION}-bin.zip -o /tmp/gradle-${GRADLE_VERSION}-bin.zip && unzip /tmp/gradle-${GRADLE_VERSION}-bin.zip -d /usr/local/ && rm /tmp/gradle-${GRADLE_VERSION}-bin.zip && mv /usr/local/gradle-${GRADLE_VERSION} /usr/local/gradle && ln -sf /usr/local/gradle/bin/gradle /usr/local/bin/gradle && mkdir -p /opt/openshift && chmod -R a+rwX /opt/openshift && mkdir -p /opt/app-root/source && chmod -R a+rwX /opt/app-root/source && mkdir -p /opt/s2i/destination && chmod -R a+rwX /opt/s2i/destination && mkdir -p /opt/app-root/src && chmod -R a+rwX /opt/app-root/src && mkdir -p /opt/.m2 && chmod -R a+rwX /opt/.m2' returned a non-zero code: 2

Failed to build vertx-s2i-

I ran CDK 2.1 and executed "oc create -f https://raw.githubusercontent.com/vert-x3/vertx-openshift-s2i/master/vertx-s2i-all.json".

In the logs for the vertx-s2i-1 build I see the following error:

I0817 14:38:30.422674 1 source.go:197] Downloading "https://github.com/cescoffier/vertx-s2i.git" ...
Step 1 : FROM centos@sha256:643a8696ecdaacb44e9d3868fcd8168588d21a923dc58bc1c74e25c3884d82f5
Trying to pull repository registry.access.redhat.com/centos ... failed
Trying to pull repository docker.io/library/centos ... failed
F0817 14:38:34.131755 1 builder.go:204] Error: build error: manifest unknown: manifest unknown

This seems to be related to a docker-hub image format change. Any image should be published using Docker 1.9

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.