myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lof...@apache.org
Subject [myfaces-tobago] 04/04: TOBAGO-1757: Docker example for demo
Date Wed, 28 Nov 2018 22:41:29 GMT
This is an automated email from the ASF dual-hosted git repository.

lofwyr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git

commit 9a3f54b3a54b7d1958d92e2de0f1a10e03706fab
Author: Udo Schnurpfeil <lofwyr@apache.org>
AuthorDate: Wed Nov 28 23:40:36 2018 +0100

    TOBAGO-1757: Docker example for demo
    
    * sample calls in the demo
---
 .../tobago/example/demo/DockerController.java      | 100 +++++++++++++++++++++
 .../myfaces/tobago/example/demo/DockerServer.java  |  77 ++++++++++++++++
 .../10-getting-started/Getting_Started.xhtml       |  20 +----
 .../webapp/content/10-intro/20-docker/Docker.xhtml |  73 +++++++++++++++
 .../webapp/content/10-intro/20-docker/docker.js    |  15 ++++
 5 files changed, 267 insertions(+), 18 deletions(-)

diff --git a/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/DockerController.java
b/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/DockerController.java
new file mode 100644
index 0000000..c58e354
--- /dev/null
+++ b/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/DockerController.java
@@ -0,0 +1,100 @@
+package org.apache.myfaces.tobago.example.demo;
+
+import javax.enterprise.context.SessionScoped;
+import javax.inject.Named;
+import java.io.Serializable;
+
+@SessionScoped
+@Named
+public class DockerController implements Serializable {
+
+  private DockerServer server;
+  private int port = 8081;
+  private int sslPort = 8443;
+  private String tag;
+
+  public DockerController() {
+    setServer(DockerServer.tomee);
+  }
+
+  public DockerServer[] getServers() {
+    return DockerServer.values();
+  }
+
+  public String[] getTags() {
+    return server.getTags();
+  }
+
+  public DockerServer getServer() {
+    return server;
+  }
+
+  public void setServer(DockerServer server) {
+    if (this.server != server) {
+      tag = server.getTags()[0];
+    }
+    this.server = server;
+  }
+
+  public int getPort() {
+    return port;
+  }
+
+  public void setPort(int port) {
+    this.port = port;
+  }
+
+  public int getSslPort() {
+    return sslPort;
+  }
+
+  public void setSslPort(int sslPort) {
+    this.sslPort = sslPort;
+  }
+
+  public String getTag() {
+    return tag;
+  }
+
+  public void setTag(String tag) {
+    this.tag = tag;
+  }
+
+  public String getCommandLine() {
+    final StringBuilder builder = new StringBuilder();
+    builder.append("mvn clean install -Djsf=provided\ndocker run -it --rm");
+    builder.append(" -p ");
+    builder.append(port);
+    builder.append(":");
+    builder.append(getServer().getPort());
+    if (server.isSsl()) {
+      builder.append(" -p ");
+      builder.append(sslPort);
+      builder.append(":");
+      builder.append(getServer().getSslPort());
+    }
+    builder.append(" -v `pwd`/target/tobago-example-demo.war:");
+    builder.append(server.getVolume());
+    builder.append(" ");
+    builder.append(server.getImage());
+    builder.append(":");
+    builder.append(tag);
+    return builder.toString();
+  }
+
+  public String getUrl() {
+    final StringBuilder builder = new StringBuilder();
+    builder.append("http://localhost:");
+    builder.append(port);
+    builder.append("/demo/");
+    return builder.toString();
+  }
+
+  public String getSslUrl() {
+    final StringBuilder builder = new StringBuilder();
+    builder.append("https://localhost:");
+    builder.append(sslPort);
+    builder.append("/demo/");
+    return builder.toString();
+  }
+}
diff --git a/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/DockerServer.java
b/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/DockerServer.java
new file mode 100644
index 0000000..508fa73
--- /dev/null
+++ b/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/DockerServer.java
@@ -0,0 +1,77 @@
+package org.apache.myfaces.tobago.example.demo;
+
+import java.io.Serializable;
+
+public enum DockerServer implements Serializable {
+
+  tomee(
+      "TomEE",
+      "/usr/local/tomee/webapps/demo.war",
+      8080,
+      0,
+      "tomee",
+      new String[]{
+          "8-jre-1.7.5-plus",
+          "8-jre-7.0.5-plus",
+          "8-jre-7.1.0-plus",
+          "8-jre-8.0.0-M1-plus"},
+      false),
+  liberty(
+      "Liberty",
+      "/config/dropins/demo.war",
+      9080,
+      9443,
+      "websphere-liberty",
+      new String[]{
+          "webProfile7",
+          "webProfile8"},
+      true);
+
+  private String displayName;
+  private String volume;
+  private int port;
+  private int sslPort;
+  private String image;
+  private String[] tags;
+  private boolean ssl;
+
+  DockerServer(
+      final String displayName, final String volume, final int port,final int sslPort,
+      final String image, final String[] tags, final boolean ssl) {
+    this.displayName = displayName;
+    this.volume = volume;
+    this.port = port;
+    this.sslPort = sslPort;
+    this.image = image;
+    this.tags = tags;
+    this.ssl = ssl;
+  }
+
+  public String getDisplayName() {
+    return displayName;
+  }
+
+  public String getVolume() {
+    return volume;
+  }
+
+  public int getPort() {
+    return port;
+  }
+
+  public int getSslPort() {
+    return sslPort;
+  }
+
+  public String getImage() {
+    return image;
+  }
+
+  public String[] getTags() {
+    return tags;
+  }
+
+  public boolean isSsl() {
+    return ssl;
+  }
+}
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/10-intro/10-getting-started/Getting_Started.xhtml
b/tobago-example/tobago-example-demo/src/main/webapp/content/10-intro/10-getting-started/Getting_Started.xhtml
index 552f6cf..8effc06 100644
--- a/tobago-example/tobago-example-demo/src/main/webapp/content/10-intro/10-getting-started/Getting_Started.xhtml
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/10-intro/10-getting-started/Getting_Started.xhtml
@@ -30,20 +30,10 @@
 
     <pre><code class="language-bash">$ git clone https://github.com/apache/myfaces-tobago
tobago</code></pre>
 
-    Check out the 4.x sources by running the following:
+    You can check out older versions like 2.x by using the git remote branch (tobaog-2.x)
running:
 
     <pre><code
-        class="language-bash">$ git clone -b tobago-4.x https://github.com/apache/myfaces-tobago
tobago-4.x</code></pre>
-
-    Check out the 3.x sources by running the following:
-
-    <pre><code
-        class="language-bash">$ git clone -b tobago-3.x https://github.com/apache/myfaces-tobago
tobago-3.x</code></pre>
-
-    Check out the 2.x sources by running the following:
-
-    <pre><code
-        class="language-bash">$ git clone -b tobago-2.x https://github.com/apache/myfaces-tobago
tobago-2.x</code></pre>
+        class="language-bash">$ git clone -b tobaog-2.x https://github.com/apache/myfaces-tobago
tobago-2.x</code></pre>
 
   </tc:section>
 
@@ -59,12 +49,6 @@
       Change to the local loaded source directory and call
     </p>
 
-    <pre><code class="language-bash">$ mvn</code></pre>
-
-    <p>
-      or
-    </p>
-
     <pre><code class="language-bash">$ mvn clean install</code></pre>
 
     <p>
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/10-intro/20-docker/Docker.xhtml
b/tobago-example/tobago-example-demo/src/main/webapp/content/10-intro/20-docker/Docker.xhtml
new file mode 100644
index 0000000..d8d174d
--- /dev/null
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/10-intro/20-docker/Docker.xhtml
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+-->
+
+<ui:composition template="/main.xhtml"
+                xmlns="http://www.w3.org/1999/xhtml"
+                xmlns:tc="http://myfaces.apache.org/tobago/component"
+                xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core">
+
+  <p>
+    To run the examples, or other Tobago applications (or any web applications), you
+    may want to use docker. You don't need to install an JavaEE server by yourself,
+    just run it in Docker.
+  </p>
+
+  <tc:script file="docker.js"/>
+
+  <tc:section id="cli" label="Command Line Configurator">
+
+    <tc:segmentLayout medium="6seg;6seg">
+
+      <tc:selectOneChoice label="Server" value="#{dockerController.server}">
+        <tc:selectItems value="#{dockerController.servers}" var="server"
+                        itemLabel="#{server.displayName}" itemValue="#{server}"/>
+        <f:ajax execute="@this" render="cli"/>
+      </tc:selectOneChoice>
+
+      <tc:selectOneChoice label="Tag" value="#{dockerController.tag}">
+        <tc:selectItems value="#{dockerController.tags}" var="tag"
+                        itemLabel="#{tag}" itemValue="#{tag}"/>
+        <f:ajax execute="@this" render="cli"/>
+      </tc:selectOneChoice>
+
+      <tc:in label="HTTP Port" value="#{dockerController.port}">
+        <f:validateLongRange minimum="1" maximum="65535"/>
+        <f:ajax execute="@this" render="cli"/>
+      </tc:in>
+
+      <tc:in label="HTTPS Port" value="#{dockerController.sslPort}" disabled="#{not dockerController.server.ssl}">
+        <f:validateLongRange minimum="1" maximum="65535"/>
+        <f:ajax execute="@this" render="cli"/>
+      </tc:in>
+
+    </tc:segmentLayout>
+
+    <tc:box label="Docker Command">
+    <pre><code class="language-bash" id="commandLine"><tc:out
+        keepLineBreaks="false" value="#{dockerController.commandLine}"/></code></pre>
+
+      <!--<tc:button label="Copy Command" omit="true"/>-->
+
+      <tc:button label="HTTP" link="#{dockerController.url}"/>
+      <tc:button label="HTTPS" link="#{dockerController.sslUrl}" disabled="#{not dockerController.server.ssl}"/>
+    </tc:box>
+
+  </tc:section>
+
+</ui:composition>
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/10-intro/20-docker/docker.js
b/tobago-example/tobago-example-demo/src/main/webapp/content/10-intro/20-docker/docker.js
new file mode 100644
index 0000000..add0a57
--- /dev/null
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/10-intro/20-docker/docker.js
@@ -0,0 +1,15 @@
+var copyTextareaBtn = document.querySelector('.js-textareacopybtn');
+
+copyTextareaBtn.addEventListener('click', function(event) {
+  var copyTextarea = document.querySelector('.js-copytextarea');
+  copyTextarea.focus();
+  copyTextarea.select();
+
+  try {
+    var successful = document.execCommand('copy');
+    var msg = successful ? 'successful' : 'unsuccessful';
+    console.log('Copying text command was ' + msg);
+  } catch (err) {
+    console.log('Oops, unable to copy');
+  }
+});


Mime
View raw message