From 6bebdc2c5eff314ac292a1ea06e93978560ddc88 Mon Sep 17 00:00:00 2001 From: Brent Daniel Date: Mon, 9 Sep 2019 09:31:07 -0700 Subject: [PATCH] Initial commit --- .gitignore | 1 + LICENSE | 203 +++++++++++++++ Makefile | 6 + README.md | 48 ++++ doc/build-mac.md | 33 +++ image.yaml | 52 ++++ imagestreams/openliberty-ubi-min.json | 33 +++ make/build.sh | 9 + make/common.mk | 14 ++ modules/ibmjdk8/install.sh | 18 ++ modules/ibmjdk8/module.yaml | 15 ++ modules/maven/install.sh | 14 ++ modules/maven/module.yaml | 15 ++ .../ol-s2i/artifacts/usr/local/s2i/assemble | 100 ++++++++ modules/ol-s2i/artifacts/usr/local/s2i/run | 10 + .../artifacts/usr/local/s2i/save-artifacts | 10 + modules/ol-s2i/artifacts/usr/local/s2i/usage | 32 +++ modules/ol-s2i/configure.sh | 17 ++ modules/ol-s2i/module.yaml | 16 ++ test/run | 233 ++++++++++++++++++ test/test-app/Readme.md | 5 + test/test-app/pom.xml | 50 ++++ .../java/test/simple/war/TestServlet.java | 30 +++ .../test/simple/war/UpdatedTestServlet.java | 30 +++ .../src/main/resources/WEB-INF/web.xml | 26 ++ test/test-app/src/main/webapp/index.html | 9 + test/test.cid | 1 + 27 files changed, 1030 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 Makefile create mode 100644 README.md create mode 100644 doc/build-mac.md create mode 100644 image.yaml create mode 100644 imagestreams/openliberty-ubi-min.json create mode 100755 make/build.sh create mode 100644 make/common.mk create mode 100755 modules/ibmjdk8/install.sh create mode 100644 modules/ibmjdk8/module.yaml create mode 100755 modules/maven/install.sh create mode 100644 modules/maven/module.yaml create mode 100755 modules/ol-s2i/artifacts/usr/local/s2i/assemble create mode 100755 modules/ol-s2i/artifacts/usr/local/s2i/run create mode 100755 modules/ol-s2i/artifacts/usr/local/s2i/save-artifacts create mode 100755 modules/ol-s2i/artifacts/usr/local/s2i/usage create mode 100644 modules/ol-s2i/configure.sh create mode 100644 modules/ol-s2i/module.yaml create mode 100755 test/run create mode 100644 test/test-app/Readme.md create mode 100644 test/test-app/pom.xml create mode 100644 test/test-app/src/main/java/test/simple/war/TestServlet.java create mode 100644 test/test-app/src/main/java/test/simple/war/UpdatedTestServlet.java create mode 100644 test/test-app/src/main/resources/WEB-INF/web.xml create mode 100644 test/test-app/src/main/webapp/index.html create mode 100644 test/test.cid diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eb5a316 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +target diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..5032843 --- /dev/null +++ b/LICENSE @@ -0,0 +1,203 @@ +Eclipse Public License - v 1.0 + +THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC +LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM +CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. + +1. DEFINITIONS + +"Contribution" means: + +a) in the case of the initial Contributor, the initial code and documentation + distributed under this Agreement, and +b) in the case of each subsequent Contributor: + i) changes to the Program, and + ii) additions to the Program; + + where such changes and/or additions to the Program originate from and are + distributed by that particular Contributor. A Contribution 'originates' + from a Contributor if it was added to the Program by such Contributor + itself or anyone acting on such Contributor's behalf. Contributions do not + include additions to the Program which: (i) are separate modules of + software distributed in conjunction with the Program under their own + license agreement, and (ii) are not derivative works of the Program. + +"Contributor" means any person or entity that distributes the Program. + +"Licensed Patents" mean patent claims licensable by a Contributor which are +necessarily infringed by the use or sale of its Contribution alone or when +combined with the Program. + +"Program" means the Contributions distributed in accordance with this +Agreement. + +"Recipient" means anyone who receives the Program under this Agreement, +including all Contributors. + +2. GRANT OF RIGHTS + a) Subject to the terms of this Agreement, each Contributor hereby grants + Recipient a non-exclusive, worldwide, royalty-free copyright license to + reproduce, prepare derivative works of, publicly display, publicly + perform, distribute and sublicense the Contribution of such Contributor, + if any, and such derivative works, in source code and object code form. + b) Subject to the terms of this Agreement, each Contributor hereby grants + Recipient a non-exclusive, worldwide, royalty-free patent license under + Licensed Patents to make, use, sell, offer to sell, import and otherwise + transfer the Contribution of such Contributor, if any, in source code and + object code form. This patent license shall apply to the combination of + the Contribution and the Program if, at the time the Contribution is + added by the Contributor, such addition of the Contribution causes such + combination to be covered by the Licensed Patents. The patent license + shall not apply to any other combinations which include the Contribution. + No hardware per se is licensed hereunder. + c) Recipient understands that although each Contributor grants the licenses + to its Contributions set forth herein, no assurances are provided by any + Contributor that the Program does not infringe the patent or other + intellectual property rights of any other entity. Each Contributor + disclaims any liability to Recipient for claims brought by any other + entity based on infringement of intellectual property rights or + otherwise. As a condition to exercising the rights and licenses granted + hereunder, each Recipient hereby assumes sole responsibility to secure + any other intellectual property rights needed, if any. For example, if a + third party patent license is required to allow Recipient to distribute + the Program, it is Recipient's responsibility to acquire that license + before distributing the Program. + d) Each Contributor represents that to its knowledge it has sufficient + copyright rights in its Contribution, if any, to grant the copyright + license set forth in this Agreement. + +3. REQUIREMENTS + +A Contributor may choose to distribute the Program in object code form under +its own license agreement, provided that: + + a) it complies with the terms and conditions of this Agreement; and + b) its license agreement: + i) effectively disclaims on behalf of all Contributors all warranties + and conditions, express and implied, including warranties or + conditions of title and non-infringement, and implied warranties or + conditions of merchantability and fitness for a particular purpose; + ii) effectively excludes on behalf of all Contributors all liability for + damages, including direct, indirect, special, incidental and + consequential damages, such as lost profits; + iii) states that any provisions which differ from this Agreement are + offered by that Contributor alone and not by any other party; and + iv) states that source code for the Program is available from such + Contributor, and informs licensees how to obtain it in a reasonable + manner on or through a medium customarily used for software exchange. + +When the Program is made available in source code form: + + a) it must be made available under this Agreement; and + b) a copy of this Agreement must be included with each copy of the Program. + Contributors may not remove or alter any copyright notices contained + within the Program. + +Each Contributor must identify itself as the originator of its Contribution, +if +any, in a manner that reasonably allows subsequent Recipients to identify the +originator of the Contribution. + +4. COMMERCIAL DISTRIBUTION + +Commercial distributors of software may accept certain responsibilities with +respect to end users, business partners and the like. While this license is +intended to facilitate the commercial use of the Program, the Contributor who +includes the Program in a commercial product offering should do so in a manner +which does not create potential liability for other Contributors. Therefore, +if a Contributor includes the Program in a commercial product offering, such +Contributor ("Commercial Contributor") hereby agrees to defend and indemnify +every other Contributor ("Indemnified Contributor") against any losses, +damages and costs (collectively "Losses") arising from claims, lawsuits and +other legal actions brought by a third party against the Indemnified +Contributor to the extent caused by the acts or omissions of such Commercial +Contributor in connection with its distribution of the Program in a commercial +product offering. The obligations in this section do not apply to any claims +or Losses relating to any actual or alleged intellectual property +infringement. In order to qualify, an Indemnified Contributor must: +a) promptly notify the Commercial Contributor in writing of such claim, and +b) allow the Commercial Contributor to control, and cooperate with the +Commercial Contributor in, the defense and any related settlement +negotiations. The Indemnified Contributor may participate in any such claim at +its own expense. + +For example, a Contributor might include the Program in a commercial product +offering, Product X. That Contributor is then a Commercial Contributor. If +that Commercial Contributor then makes performance claims, or offers +warranties related to Product X, those performance claims and warranties are +such Commercial Contributor's responsibility alone. Under this section, the +Commercial Contributor would have to defend claims against the other +Contributors related to those performance claims and warranties, and if a +court requires any other Contributor to pay any damages as a result, the +Commercial Contributor must pay those damages. + +5. NO WARRANTY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR +IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, +NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each +Recipient is solely responsible for determining the appropriateness of using +and distributing the Program and assumes all risks associated with its +exercise of rights under this Agreement , including but not limited to the +risks and costs of program errors, compliance with applicable laws, damage to +or loss of data, programs or equipment, and unavailability or interruption of +operations. + +6. DISCLAIMER OF LIABILITY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY +CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION +LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE +EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY +OF SUCH DAMAGES. + +7. GENERAL + +If any provision of this Agreement is invalid or unenforceable under +applicable law, it shall not affect the validity or enforceability of the +remainder of the terms of this Agreement, and without further action by the +parties hereto, such provision shall be reformed to the minimum extent +necessary to make such provision valid and enforceable. + +If Recipient institutes patent litigation against any entity (including a +cross-claim or counterclaim in a lawsuit) alleging that the Program itself +(excluding combinations of the Program with other software or hardware) +infringes such Recipient's patent(s), then such Recipient's rights granted +under Section 2(b) shall terminate as of the date such litigation is filed. + +All Recipient's rights under this Agreement shall terminate if it fails to +comply with any of the material terms or conditions of this Agreement and does +not cure such failure in a reasonable period of time after becoming aware of +such noncompliance. If all Recipient's rights under this Agreement terminate, +Recipient agrees to cease use and distribution of the Program as soon as +reasonably practicable. However, Recipient's obligations under this Agreement +and any licenses granted by Recipient relating to the Program shall continue +and survive. + +Everyone is permitted to copy and distribute copies of this Agreement, but in +order to avoid inconsistency the Agreement is copyrighted and may only be +modified in the following manner. The Agreement Steward reserves the right to +publish new versions (including revisions) of this Agreement from time to +time. No one other than the Agreement Steward has the right to modify this +Agreement. The Eclipse Foundation is the initial Agreement Steward. The +Eclipse Foundation may assign the responsibility to serve as the Agreement +Steward to a suitable separate entity. Each new version of the Agreement will +be given a distinguishing version number. The Program (including +Contributions) may always be distributed subject to the version of the +Agreement under which it was received. In addition, after a new version of the +Agreement is published, Contributor may elect to distribute the Program +(including its Contributions) under the new version. Except as expressly +stated in Sections 2(a) and 2(b) above, Recipient receives no rights or +licenses to the intellectual property of any Contributor under this Agreement, +whether expressly, by implication, estoppel or otherwise. All rights in the +Program not expressly granted under this Agreement are reserved. + +This Agreement is governed by the laws of the State of New York and the +intellectual property laws of the United States of America. No party to this +Agreement will bring a legal action under this Agreement more than one year +after the cause of action arose. Each party waives its rights to a jury trial in +any resulting litigation. \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..dbc406e --- /dev/null +++ b/Makefile @@ -0,0 +1,6 @@ +IMAGE_VERSION=latest +NAMESPACE=openliberty +PLATFORM=javaee8-ubi-openshift +IMAGE_NAME=${NAMESPACE}/ol-${PLATFORM} +# Include common Makefile code. +include make/common.mk diff --git a/README.md b/README.md new file mode 100644 index 0000000..2ae41f3 --- /dev/null +++ b/README.md @@ -0,0 +1,48 @@ +Open Liberty UBI-min images for OpenShift S2I +============================================= + +This repository contains the source for building an Open Liberty Source to Image (S2I) builder using Red Hat Universal Base Image (UBI) 7 and Java 8. + +More information on S2I can be found at https://github.com/openshift/source-to-image + +The built S2I image can be run using [Docker](https://docker.io). + +Building the images +=================== +Images are built using [docker community edition](https://docs.docker.com/) and [cekit version 3](https://cekit.readthedocs.io/en/latest/index.html). +Mac OSX installation and build [tips](doc/build-mac.md). + +Cloning the repository: + +``` +$ git clone https://github.com/openliberty/openliberty-s2i +$ cd openliberty-s2i +``` + +Building the Open Liberty S2I builder: + +``` +$ cekit build docker +``` +S2I Usage +--------- +To build a simple [jee application](https://github.com/openshift/openshift-jee-sample) +using standalone [S2I](https://github.com/openshift/source-to-image) and then run the +resulting image with [Docker](http://docker.io) execute: + +``` +$ s2i build git://github.com/openshift/openshift-jee-sample openliberty/ol-javaee8-ubi-openshift:latest open-liberty-test +$ docker run -p 9080:9080 open-liberty-test +``` + +**Accessing the application:** +``` +$ curl 127.0.0.1:9080 +``` + +Test +---- +The tests for this repository check basic functionality of a JEE application built on top of the Open Liberty S2I image. +``` +$ make test +``` diff --git a/doc/build-mac.md b/doc/build-mac.md new file mode 100644 index 0000000..7270dc8 --- /dev/null +++ b/doc/build-mac.md @@ -0,0 +1,33 @@ +Building on Mac +=============== + +* Installing Docker + * Install [Docker Desktop](https://hub.docker.com/editions/community/docker-ce-desktop-mac) + +* Installing Python (required by cekit) + * Install [python 3](https://www.python.org) + * Install virtualenv: `sudo pip3 install virtualenv` + * Create a directory for the cekit virtualenv: `mkdir my-vertualenv` + * Create the virtualenv: `virtualenv my-vertualenv/cekit` + * Activate the virtualenv `source my-vertualenv/cekit/bin/activate` + +* Installing cekit and dependencies. NB: Be sure to install a cekit version >= to 3.1.0. + * `pip3 install cekit` + * `pip3 install docker` + * `pip3 install docker_squash` + +You are ready to build OpenLiberty images using cekit! + +Known issues +============ + +On Mac, if you are using cekit 3.0.1, you will be impacted by this [issue](https://github.com/cekit/cekit/issues/517). +To workaround this problem, you need to do the build in 2 steps. +run cekit first, it will fail but the target/image/Dockerfile is properly generated so you can then use docker to build the image. +For example, to build the builder image: + +``` +$ cekit build docker +$ cd target/image +$ docker build -t openliberty/ol-javaee8-ubi-openshift:latest . +``` \ No newline at end of file diff --git a/image.yaml b/image.yaml new file mode 100644 index 0000000..dcd7a94 --- /dev/null +++ b/image.yaml @@ -0,0 +1,52 @@ +schema_version: 1 + +name: openliberty/ol-javaee8-ubi-openshift +version: 1.0 +from: openliberty/open-liberty:javaee8-ubi-min +description: "Open Libety UBI image with javaee-8" +labels: + - name: io.k8s.description + value: "Open Liberty S2I Image" + - name: io.k8s.display-name + value: "Open Liberty S2I Builder" + - name: io.openshift.tags + value: "runner,builder,openliberty,javaee" + - name: io.openshift.s2i.scripts-url + value: image:///usr/local/s2i + - name: io.s2i.scripts-url + value: image:///usr/local/s2i + - name: io.openshift.expose-services + value: "9080/tcp:http, 9443/tcp:https" + - name: io.openshift.s2i.destination + value: "/tmp" + +envs: + - name: STI_SCRIPTS_PATH + value: "/usr/local/s2i" + - name: WORKDIR + value: "/usr/local/workdir" + - name: S2I_DESTINATION + value: "/tmp" + - name: JAVA_HOME + value: /opt/ibm/java + - name: PATH + value: /opt/ibm/java/bin:$PATH + +packages: + manager: microdnf + +modules: + repositories: + - path: modules + + # Install selected modules (in order) + install: + - name: ibmjdk8 + - name: maven + - name: ol-s2i + +run: + user: 1001 + cmd: + - "/opt/ol/wlp/bin/server run defaultServer" + diff --git a/imagestreams/openliberty-ubi-min.json b/imagestreams/openliberty-ubi-min.json new file mode 100644 index 0000000..56c05bd --- /dev/null +++ b/imagestreams/openliberty-ubi-min.json @@ -0,0 +1,33 @@ +{ + "apiVersion": "v1", + "kind": "ImageStream", + "metadata": { + "annotations": { + "openshift.io/display-name": "Open Liberty" + }, + "name": "openliberty" + }, + "spec": { + "tags": [ + { + "annotations": { + "description": "Build and run Open Liberty applications on Red Hat Universal Base Image 7. For more information about using this builder image, including OpenShift considerations, see TODO.\n\nWARNING: By selecting this tag, your application will automatically update to use the latest version of Open Liberty available on OpenShift, including major versions updates.", + "iconClass": "icon-openliberty", + "openshift.io/display-name": "Open Liberty (Latest)", + "openshift.io/provider-display-name": "IBM", + "sampleRepo": "https://github.com/openshift/openshift-jee-sample.git", + "supports": "jee,java", + "tags": "builder,openliberty,java" + }, + "from": { + "kind": "DockerImage", + "name": "dockerhub.io/openliberty/open-liberty-s2i:latest" + }, + "referencePolicy": { + "type": "Local" + }, + "name": "latest" + } + ] + } +} diff --git a/make/build.sh b/make/build.sh new file mode 100755 index 0000000..29503ee --- /dev/null +++ b/make/build.sh @@ -0,0 +1,9 @@ +#!/bin/bash -e +SCRIPT_DIR=$(dirname $0) +pushd ${SCRIPT_DIR}/.. +cekit build docker +popd + +if [[ ! -z "${TEST_MODE:-}" ]]; then + ${SCRIPT_DIR}/../test/run +fi diff --git a/make/common.mk b/make/common.mk new file mode 100644 index 0000000..a97ff46 --- /dev/null +++ b/make/common.mk @@ -0,0 +1,14 @@ +build = make/build.sh + +script_env = \ + IMAGE_NAME=$(IMAGE_NAME) \ + IMAGE_VERSION=$(IMAGE_VERSION) \ + RUNTIME_IMAGE_NAME=$(RUNTIME_IMAGE_NAME) + +.PHONY: build +build: + $(script_env) $(build) + +.PHONY: test +test: + $(script_env) TEST_MODE=true $(build) diff --git a/modules/ibmjdk8/install.sh b/modules/ibmjdk8/install.sh new file mode 100755 index 0000000..02c8e69 --- /dev/null +++ b/modules/ibmjdk8/install.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +set -e + +microdnf install gzip + +echo "INSTALLER_UI=silent" > /tmp/response.properties \ + && echo "USER_INSTALL_DIR=/opt/ibm/java" >> /tmp/response.properties \ + && echo "LICENSE_ACCEPTED=TRUE" >> /tmp/response.properties \ + && mkdir -p /opt/ibm \ + && chmod +x /tmp/artifacts/ibm-java.bin \ + && /tmp/artifacts/ibm-java.bin -i silent -f /tmp/response.properties \ + && rm -f /tmp/response.properties \ + && rm -f /tmp/artifacts/ibm-java.bin + +# Subsequent installation of maven needs gzip +# microdnf remove gzip + diff --git a/modules/ibmjdk8/module.yaml b/modules/ibmjdk8/module.yaml new file mode 100644 index 0000000..caa6e23 --- /dev/null +++ b/modules/ibmjdk8/module.yaml @@ -0,0 +1,15 @@ +schema_version: 1 + +name: ibmjdk8 +version: 1.0 +description: "Module used to install IBM JDK 8" + +# Defined artifacts that are used to build the image +artifacts: + - name: ibm-java.bin + url: https://public.dhe.ibm.com/ibmdl/export/pub/systems/cloud/runtimes/java/8.0.5.40/linux/x86_64/ibm-java-sdk-8.0-5.40-x86_64-archive.bin + sha256: bc53faf476655e565f965dab3db37f9258bfc16bb8c5352c93d43d53860b79d3 + +execute: + - script: install.sh + diff --git a/modules/maven/install.sh b/modules/maven/install.sh new file mode 100755 index 0000000..d50465e --- /dev/null +++ b/modules/maven/install.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +set -e + +microdnf install gzip + + tar -C /usr/local -zxf /tmp/artifacts/maven.tar.gz \ + && ln -sf /usr/local/apache-maven-3.5.4/bin/mvn /usr/local/bin/mvn + +microdnf remove gzip + +mkdir -p /home/default/.m2/repository +chown -R 1001 /home/default/.m2 +chmod -R ug+rwX /home/default/.m2 diff --git a/modules/maven/module.yaml b/modules/maven/module.yaml new file mode 100644 index 0000000..2f77bcd --- /dev/null +++ b/modules/maven/module.yaml @@ -0,0 +1,15 @@ +schema_version: 1 + +name: maven +version: 1.0 +description: "Module used to install Maven 3.5.4" + +# Defined artifacts that are used to build the image +artifacts: + - name: maven.tar.gz + url: https://www.apache.org/dist/maven/maven-3/3.5.4/binaries/apache-maven-3.5.4-bin.tar.gz + sha512: 2a803f578f341e164f6753e410413d16ab60fabe31dc491d1fe35c984a5cce696bc71f57757d4538fe7738be04065a216f3ebad4ef7e0ce1bb4c51bc36d6be86 + +execute: + - script: install.sh + diff --git a/modules/ol-s2i/artifacts/usr/local/s2i/assemble b/modules/ol-s2i/artifacts/usr/local/s2i/assemble new file mode 100755 index 0000000..1dbdce8 --- /dev/null +++ b/modules/ol-s2i/artifacts/usr/local/s2i/assemble @@ -0,0 +1,100 @@ +#!/bin/bash -e +# +# (C) Copyright IBM Corporation 2016. +# +# Licensed 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. + +# S2I assemble script for the 'open-liberty-javaee8' image. + +echo "Running s2i assemble with user $USER home $HOME" + +if [ -f $S2I_DESTINATION/src/wlp/config/server.xml ]; then + cp $S2I_DESTINATION/src/wlp/config/server.xml /config +else + echo "No server.xml found, using default" +fi + +# Source code provided to S2I is at /tmp/src +LOCAL_SOURCE_DIR=/tmp/src + +# Resulting WAR files will be deployed to /opt/ol/wlp/usr/servers/defaultServer/dropins/ +DEPLOY_DIR=/opt/ol/wlp/usr/servers/defaultServer/dropins/ + +# If a pom.xml is present, this is a normal build scenario +# so run maven. +if [ -f "$LOCAL_SOURCE_DIR/pom.xml" ]; then + + pushd $LOCAL_SOURCE_DIR &> /dev/null + + if [ -z "$MAVEN_ARGS" ]; then + export MAVEN_ARGS="package -Popenshift -DskipTests" + fi + + # Append arguments to MAVEN_ARGS if necessary + if [ -n "$MAVEN_ARGS_APPEND" ]; then + echo "Maven additional arguments: $MAVEN_ARGS_APPEND" + export MAVEN_ARGS="$MAVEN_ARGS $MAVEN_ARGS_APPEND" + fi + echo "Found pom.xml... attempting to build with 'mvn ${MAVEN_ARGS}'" + + mvn --version + mvn $MAVEN_ARGS + + ERR=$? + if [ $ERR -ne 0 ]; then + echo "Aborting due to error code $ERR from mvn package" + exit $ERR + fi + + + #Copy .war file from the source directory + echo "Copying built war files into $DEPLOY_DIR for later deployment..." + popd &> /dev/null +else + echo "Copying binaries in source directory into $DEPLOY_DIR for later deployment..." +fi + +ls -l /tmp/src + +if [ -d $LOCAL_SOURCE_DIR/target ]; then + cp $LOCAL_SOURCE_DIR/target/*.war $DEPLOY_DIR 2>/dev/null || : + cp $LOCAL_SOURCE_DIR/target/*.ear $DEPLOY_DIR 2>/dev/null || : + cp $LOCAL_SOURCE_DIR/target/*.jar $DEPLOY_DIR 2>/dev/null || : + cp $LOCAL_SOURCE_DIR/target/*.rar $DEPLOY_DIR 2>/dev/null || : +fi + +if [ -d $LOCAL_SOURCE_DIR/deployments ]; then + cp $LOCAL_SOURCE_DIR/deployments/*.war $DEPLOY_DIR >& /dev/null + cp $LOCAL_SOURCE_DIR/deployments/*.ear $DEPLOY_DIR >& /dev/null + cp $LOCAL_SOURCE_DIR/deployments/*.jar $DEPLOY_DIR >& /dev/null + cp $LOCAL_SOURCE_DIR/deployments/*.rar $DEPLOY_DIR >& /dev/null +fi + +# Copy supporting files from OL directory +if [ -d $S2I_DESTINATION/src/wlp/usr ]; then + cp -R $S2I_DESTINATION/src/wlp/usr /opt/ol/wlp +fi + +# Run configure again to pick up configuration from the environmentf +echo "whoami: " +whoami + +echo "perms:" +ls -l /opt/ol/wlp/output + +echo "Configuring Server" +echo "MP: $MP_MONITORING" +/opt/ol/helpers/build/configure.sh + +echo "Application deployment finished! Please start up the Open Liberty container using the following command: docker run -P " +exit $rc diff --git a/modules/ol-s2i/artifacts/usr/local/s2i/run b/modules/ol-s2i/artifacts/usr/local/s2i/run new file mode 100755 index 0000000..a9827fc --- /dev/null +++ b/modules/ol-s2i/artifacts/usr/local/s2i/run @@ -0,0 +1,10 @@ +#!/bin/bash -e +# +# S2I run script for the 'open-liberty-javaee8' image. +# The run script executes the server that runs your application. +# +# For more information see the documentation: +# https://github.com/openshift/source-to-image/blob/master/docs/builder_image.md +# + +/opt/ol/wlp/bin/server run defaultServer diff --git a/modules/ol-s2i/artifacts/usr/local/s2i/save-artifacts b/modules/ol-s2i/artifacts/usr/local/s2i/save-artifacts new file mode 100755 index 0000000..fdccb70 --- /dev/null +++ b/modules/ol-s2i/artifacts/usr/local/s2i/save-artifacts @@ -0,0 +1,10 @@ +#!/bin/sh -e +# +# S2I save-artifacts script for the 'liberty-javaee7' image. +# The save-artifacts script streams a tar archive to standard output. +# The archive contains the files and folders you want to re-use in the next build. +# +# For more information see the documentation: +# https://github.com/openshift/source-to-image/blob/master/docs/builder_image.md +# +# tar cf - diff --git a/modules/ol-s2i/artifacts/usr/local/s2i/usage b/modules/ol-s2i/artifacts/usr/local/s2i/usage new file mode 100755 index 0000000..94da56f --- /dev/null +++ b/modules/ol-s2i/artifacts/usr/local/s2i/usage @@ -0,0 +1,32 @@ +#! /bin/bash -e +# +# (C) Copyright IBM Corporation 2016. +# +# Licensed 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. + +# inform the user how to use the image +cat <&"/dev/null" || READLINK_EXEC="greadlink" + ! type -a "gmktemp" >&"/dev/null" || MKTEMP_EXEC="gmktemp" +fi + +SCRIPT_DIR=$(dirname $0) +_dir="$(dirname "${BASH_SOURCE[0]}")" +test_dir="$($READLINK_EXEC ${_dir} || echo ${_dir})" +log_file=$test_dir/test.log +s2i_log_file=$test_dir/s2i.log +cid_file=$test_dir/test.cid + +SNIPPETS_TARGET=/config/configDropins/overrides + +# Environment variables used to modify the Open Liberty configuration +ENABLE_SSL_VAR="-e SSL=true" +ENABLE_TLS_VAR="-e TLS=true" +HTTP_ENDPOINT_VAR="-e HTTP_ENDPOINT=true" +MP_HEALTH_CHECK_VAR="-e MP_HEALTH_CHECK=true" +MP_MONITORING_VAR="-e MP_MONITORING=true" +HZ_SESSION_CACHE_CLIENT_VAR="-e HZ_SESSION_CACHE=client" +HZ_SESSION_CACHE_EMBEDDED_VAR="-e HZ_SESSION_CACHE=embedded" +IIOP_ENDPOINT_VAR="-e IIOP_ENDPOINT=true" +JMS_ENDPOINT_VAR="-e JMS_ENDPOINT=true" + +# Since we built the image locally, we don't want S2I attempt to pull +# it from Docker hub +s2i_args="--pull-policy=never" + +test_port=9080 + +image_exists() { + echo "Checking image $1" + docker inspect $1 &>/dev/null +} + + +container_exists() { + echo "Checking container $(cat $cid_file)" + image_exists $(cat $cid_file) +} + +container_ip() { + docker inspect --format='{{(index (index .NetworkSettings.Ports "9080/tcp") 0).HostIp}}' $(cat $cid_file) | sed 's/0.0.0.0/localhost/' +} + +container_port() { + docker inspect --format="{{"{{"}}(index .NetworkSettings.Ports \"$test_port/tcp\" 0).HostPort {{"}}"}}" "$(cat "${cid_file}")" +} + + +prepare() { + app=$1 + shift + if ! image_exists ${IMAGE_NAME}:${IMAGE_VERSION}; then + echo "ERROR: The image ${IMAGE_NAME}:${IMAGE_VERSION} must exist before this script is executed." + exit 1 + fi + s2i build ${s2i_args} ${test_dir}/$app ${IMAGE_NAME}:${IMAGE_VERSION} ${IMAGE_NAME}-testapp $@ >& $s2i_log_file +} + +run_test_application() { + docker run $@ --rm -p ${test_port}:${test_port} --cidfile=${cid_file} ${IMAGE_NAME}-testapp >& $log_file +} + +run_test_mp_monitoring() { + docker exec $(cat $cid_file) cat $SNIPPETS_TARGET/mp-monitoring.xml + check_result $? +} + +run_test_mp_health_check() { + docker exec $(cat $cid_file) cat $SNIPPETS_TARGET/mp-health-check.xml + check_result $? +} + +run_test_jms_endpoint() { + docker exec $(cat $cid_file) cat $SNIPPETS_TARGET/jms-endpoint.xml + check_result $? +} + +run_test_jms_endpoint_ssl() { + docker exec $(cat $cid_file) cat $SNIPPETS_TARGET/jms-ssl-endpoint.xml + check_result $? +} + +cleanup() { + echo "Cleanup for test, cid $(cat $cid_file)" + if container_exists; then + if [[ $1 != "0" ]]; then + echo "Viewing docker logs" + docker logs $(cat $cid_file) + fi + echo "Stopping container $(cat $cid_file)" + docker stop $(cat $cid_file) || true + fi + if image_exists ${IMAGE_NAME}-testapp; then + docker rmi -f ${IMAGE_NAME}-testapp + fi + if image_exists ${RUNTIME_IMAGE_NAME}-testapp; then + docker rmi -f ${RUNTIME_IMAGE_NAME}-testapp + fi + rm -rf ${test_dir}/test-app/.git + rm -f $cid_file +} + +cleanupFinal() { + rm -f $log_file + rm -f $s2i_log_file +} + +check_result() { + local result="$1" + if [[ "$result" != "0" ]]; then + cleanup 1 + echo "S2I image '${IMAGE_NAME}' test FAILED (exit code: ${result}), last container execution log file in $log_file" + exit $result + fi +} + +wait_for_cid() { + local max_attempts=30 + local sleep_time=1 + local attempt=1 + local result=1 + while [ $attempt -le $max_attempts ]; do + [ -f $cid_file ] && [ -s $cid_file ] && break + echo "Waiting for container start..." + attempt=$(( $attempt + 1 )) + sleep $sleep_time + done +} + +run_test_usage() { + s2i usage ${s2i_args} ${IMAGE_NAME}:${IMAGE_VERSION} &>/dev/null +} + +test_connection() { + local max_attempts=30 + local sleep_time=1 + local attempt=1 + local result=1 + while [ $attempt -le $max_attempts ]; do + echo "Sending GET request to http://$(container_ip):${test_port}/" + set +e + response_code=$(curl -s -w %{http_code} -o /dev/null http://$(container_ip):${test_port}/) + status=$? + set -e + if [ $status -eq 0 ]; then + if [ $response_code -eq 200 ]; then + result=0 + fi + break + fi + attempt=$(( $attempt + 1 )) + sleep $sleep_time + done + return $result +} + + + +echo "Testing image $IMAGE_NAME" +echo "Last s2i execution is logged in $s2i_log_file" +echo "Last container execution is logged in $log_file" + +echo "### Test deployment in default server." + +prepare test-app + +# Verify the 'usage' script is working properly +run_test_usage +check_result $? + +# Verify that the HTTP connection can be established to test application container +run_test_application & + +# Wait for the container to write it's CID file +# +wait_for_cid + +test_connection +check_result $? + +cleanup 0 + +# CONFIGURATION TESTS +# These are simple tests that make sure that environment variables passed to s2i result +# in configuration files being copied to configDropins + +echo "MicroProfile Monitoring Configuration Test" +prepare test-app $MP_MONITORING_VAR +run_test_application & +wait_for_cid +test_connection +check_result $? +run_test_mp_monitoring +cleanup 0 + +echo "MicroProfile Health Configuration Test" +prepare test-app $MP_HEALTH_CHECK_VAR +run_test_application & +wait_for_cid +test_connection +check_result $? +run_test_mp_health_check +cleanup 0 + +echo "JMS Endpoint, No SSL Configuration Test" +prepare test-app $JMS_ENDPOINT_VAR +run_test_application & +wait_for_cid +test_connection +check_result $? +run_test_jms_endpoint +cleanup 0 + +echo "JMS Endpoint, SSL Configuration Test" +prepare test-app $JMS_ENDPOINT_VAR $ENABLE_SSL_VAR +run_test_application & +wait_for_cid +test_connection +check_result $? +run_test_jms_endpoint_ssl + +cleanupFinal + +# END CONFIGURATION TESTS +echo "Test SUCCESSFUL" diff --git a/test/test-app/Readme.md b/test/test-app/Readme.md new file mode 100644 index 0000000..66289b1 --- /dev/null +++ b/test/test-app/Readme.md @@ -0,0 +1,5 @@ +openshift-jee-sample +==================== + +A sample app to be deployed on OpenShift environments + diff --git a/test/test-app/pom.xml b/test/test-app/pom.xml new file mode 100644 index 0000000..840c2b8 --- /dev/null +++ b/test/test-app/pom.xml @@ -0,0 +1,50 @@ + + + 4.0.0 + + SampleApp + SampleApp + war + 1.0 + SampleApp + + + UTF-8 + 1.8 + 1.8 + + + + + javax + javaee-api + 8.0 + provided + + + + + + + + + + openshift + + SampleApp + + + org.apache.maven.plugins + maven-war-plugin + 2.3 + + false + target + ROOT + + + + + + + diff --git a/test/test-app/src/main/java/test/simple/war/TestServlet.java b/test/test-app/src/main/java/test/simple/war/TestServlet.java new file mode 100644 index 0000000..2d0a825 --- /dev/null +++ b/test/test-app/src/main/java/test/simple/war/TestServlet.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2018 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package test.simple.war; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class TestServlet extends HttpServlet { + private static final long serialVersionUID = 1L; + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + response.getWriter().println("test servlet is running."); + } + + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {} +} diff --git a/test/test-app/src/main/java/test/simple/war/UpdatedTestServlet.java b/test/test-app/src/main/java/test/simple/war/UpdatedTestServlet.java new file mode 100644 index 0000000..63e0121 --- /dev/null +++ b/test/test-app/src/main/java/test/simple/war/UpdatedTestServlet.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2018 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package test.simple.war; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class UpdatedTestServlet extends HttpServlet { + private static final long serialVersionUID = 1L; + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + response.getWriter().println("this is an updated test servlet."); + } + + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {} +} diff --git a/test/test-app/src/main/resources/WEB-INF/web.xml b/test/test-app/src/main/resources/WEB-INF/web.xml new file mode 100644 index 0000000..4b36b80 --- /dev/null +++ b/test/test-app/src/main/resources/WEB-INF/web.xml @@ -0,0 +1,26 @@ + + + + testWarApplication + + + + + TestServlet + TestServlet + test.simple.war.TestServlet + + + TestServlet + + /TestServlet + + + index.html + index.htm + index.jsp + default.html + default.htm + default.jsp + + diff --git a/test/test-app/src/main/webapp/index.html b/test/test-app/src/main/webapp/index.html new file mode 100644 index 0000000..83b94fa --- /dev/null +++ b/test/test-app/src/main/webapp/index.html @@ -0,0 +1,9 @@ + + + + Hello World! + + +

Hello World!

+ + diff --git a/test/test.cid b/test/test.cid new file mode 100644 index 0000000..84d450a --- /dev/null +++ b/test/test.cid @@ -0,0 +1 @@ +034773a2c4a3f92d2f16101b2c355ebb5813196badbb5fac308bbffc97e3fc22 \ No newline at end of file