Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for restructured tomcat-in-the-cloud #2

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions tomcat-in-the-cloud-pathway.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
{
"title": "Introduction to Tomcat in the cloud",
"description": "Learn Tomcat in the cloud",
"title": "Introduction to Tomcat-in-the-cloud",
"description": "Learn Tomcat-in-the-cloud",
"paid": false,
"courses": [
{
"course_id": "deploy-titc-using-cli",
"title": "Deploy tomcat-in-the-cloud to OpenShift using CLI",
"title": "Deploy Tomcat-in-the-cloud to OpenShift using CLI - Stable",
"description": ""
},
{
"course_id": "deploy-titc-using-cli-latest",
"title": "Deploy Tomcat-in-the-cloud to OpenShift using CLI - Latest update",
"description": ""
}
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
*Clone the Cloud Deployer repository and move to its root directory:*

`git clone -b katacoda https://github.com/maxime-beck/cloudDeployer.git && cd cloudDeployer`{{execute}}

*Set up the environment - this script clones and builds dependencies:*

`./setup.sh`{{execute}}

*Build the Cloud Deployer:*

`mvn install`{{execute}}
61 changes: 61 additions & 0 deletions tomcat-in-the-cloud/deploy-titc-using-cli-latest/2_configure.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
## Edit the property file
With the file explorer, open __cloudDeployer > config > cloud.properties__.

__Set the REGISTRY_ADDRESS__


This is the address of your docker registry. You can find this information with the following command:

`oc get svc docker-registry`{{execute}}

Set the value with its ip address followed by its port like so: __ip:port__.

__Set the HOST_ADDRESS__


This property requires the full name of the host (you can also put the ip address but not in Katacoda because the route won't work if you do so !).
You'll find the full host name by clicking on the Dashboard view. This will open a new tab on your browser with a fully working OpenShift server. Then simply copy its host name in the URL ([katacoda_id]-8443-simba02.environments.katacoda.com).

__Set the REGISTRY_ID__


The registry_id is the name of your OpenShift project. We don't have a project yet so lets create one.

*Start by login into Openshift:*

`oc login localhost:8443 --username=admin --password=admin --insecure-skip-tls-verify=true`{{execute}}

*Then create the project, we'll call it my-clustered-app but any name will do*

`oc new-project my-clustered-app`{{execute}}

You can then copy/paste that name into the registry_id property in our configuration file.

__Set the WAR__


The war is simply the path to the war file you would like to deploy on the cloud. This path must be relative to the Dockerfile location of the tomcat-in-the-cloud repo and in the docker context. So make sure to place your war file into the tomcat-in-the-cloud folder. For this course, we provided a sample app called *sample.war* at the root of the cloud deploy repository.

*Move the sample.war to tomcat-in-the-cloud folder:*

`mv sample.war tomcat-in-the-cloud`{{execute}}

Then simply write *sample.war* as the value of this property.

__Set the DOCKER_USERNAME and the DOCKER_TOKEN__


If you've followed the command of this tutorial, your DOCKER_USERNAME must be *admin*. That is the username we loged into Openshift with. If you're not sure which user is currently logged in you can use the command : `oc whoami`{{execute}}.

Now for your DOCKER_TOKEN that is the token of your current user :

`oc whoami -t`{{execute}}

## Get ready for deployment
You're all set ! You can find the full documentation of all the properties by [clicking here](https://github.com/maxime-beck/cloudDeployer#configure)

The last thing before deployment is to allow the pods to see their peers for the current project (cluster) :

`oc policy add-role-to-user view system:serviceaccount:$(oc project -q):default -n $(oc project -q)`{{execute}}

__If you don't, the pods won't be able to communicate and session replication will not work.__
5 changes: 5 additions & 0 deletions tomcat-in-the-cloud/deploy-titc-using-cli-latest/3_deploy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
To deploy your cloud environment along with your application, simply run the Cloud Deployer :

`java -jar target/cloudDeployer-1.0-SNAPSHOT-jar-with-dependencies.jar`{{execute}}

If everything went alright, you can then use `oc get routes`{{execute}} to get the link to your freshly deployed application.
14 changes: 14 additions & 0 deletions tomcat-in-the-cloud/deploy-titc-using-cli-latest/env-init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# test stuff
ssh root@host01 "> /tmp/toto"

# Install jdk
yum install java-1.8.0-openjdk-devel.x86_64 -y > /tmp/toto.txt
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk

# Installing maven
wget https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.tar.gz
tar xvf apache-maven-3.5.0-bin.tar.gz
mv apache-maven-3.5.0 /usr/local/apache-maven
export M2_HOME=/usr/local/apache-maven
export M2=$M2_HOME/bin
export PATH=$M2:$PATH
1 change: 1 addition & 0 deletions tomcat-in-the-cloud/deploy-titc-using-cli-latest/finish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
More information can be found at https://docs.openshift.org/latest/dev_guide/builds.html
38 changes: 38 additions & 0 deletions tomcat-in-the-cloud/deploy-titc-using-cli-latest/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"icon": "fa-openshift",
"title": "Deploying tomcat-in-the-cloud to OpenShift",
"description": "",
"pathwayTitle": "OpenShift",
"backend": {
"imageid": "openshift",
"port": 8443
},
"environment": {
"showdashboard": true,
"dashboard": "Dashboard",
"uilayout": "editor-terminal"
},
"details": {
"steps": [
{
"title": "Step 1 - Clone and build",
"text": "1_cloneAndBuild.md"
},
{
"title": "Step 2 - Configure",
"text": "2_configure.md"
},
{
"title": "Step 3 - Deploy",
"text": "3_deploy.md"
}
],
"intro": {
"code": "set-env.sh",
"text": "intro.md"
},
"finish": {
"text": "finish.md"
}
}
}
3 changes: 3 additions & 0 deletions tomcat-in-the-cloud/deploy-titc-using-cli-latest/intro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
_Tomcat-in-the-cloud_ is the current name of the project that seeks to port Tomcat clustering into cloud services such as Kubernetes, OpenShift, AWS and Azure.

In this scenario, you will learn how to build, deploy and monitor it in OpenShift.
17 changes: 17 additions & 0 deletions tomcat-in-the-cloud/deploy-titc-using-cli-latest/set-env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
~/.launch.sh

yum clean all
# Install jdk
yum install java-1.8.0-openjdk-devel.x86_64 -y
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk

# Installing Ant
yum install ant -y

# Installing Maven
wget http://mirror.olnevhost.net/pub/apache/maven/maven-3/3.5.3/binaries/apache-maven-3.5.3-bin.tar.gz
tar xvf apache-maven-3.5.3-bin.tar.gz
mv apache-maven-3.5.3 /usr/local/apache-maven
export M2_HOME=/usr/local/apache-maven
export M2=$M2_HOME/bin
export PATH=$M2:$PATH
23 changes: 23 additions & 0 deletions tomcat-in-the-cloud/deploy-titc-using-cli/1_buildDependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
In order to function properly, _Tomcat-in-the-cloud_ needs a member provider that will essentially discover all running instances of Tomcat in the cloud environment. Currently, we developed a member provider that works for _Kubernetes_ and _OpenShift_ called **CloudMemberProvider**. We plan on extending that list by providing support for more cloud services in the near future.

_Tomcat-in-the-cloud_ also needs a way to establish connection throughout the cloud network so the HTTP requests can be sent to the right instances of the cluster. To do that, it depends upon another library that we call **CloudStreamProvider**. Stream providers can use a variety of different types of connections. We currently support unsecured and secured (via token) connections.

The first step is therefore to build these dependencies. **It's important that you follow the building order described bellow** as those dependencies depend on each other.

## A) Building CloudStreamProvider
*Clone the CloudStreamProvider repository :*

`git clone https://github.com/maxime-beck/cloudStreamProvider.git`{{execute}}

*Run the building process using Maven :*

`mvn -f cloudStreamProvider/pom.xml install`{{execute}}

## B) Building CloudMemberProvider
*Clone the CloudMemberProvider repository :*

`git clone https://github.com/maxime-beck/cloudMemberProvider.git`{{execute}}

*Run the building process using Maven :*

`mvn -f cloudMemberProvider/pom.xml install`{{execute}}
43 changes: 0 additions & 43 deletions tomcat-in-the-cloud/deploy-titc-using-cli/1_deployment.md

This file was deleted.

70 changes: 70 additions & 0 deletions tomcat-in-the-cloud/deploy-titc-using-cli/2_deployment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
OpenShift has the concept of "projects". These projects allow you to group components of a system together without interfering or conflicting with other deployments on the system.

Using projects can make the management of large-scale deployments much simpler. Instead of seeing all the applications deployed, you can focus your view depending on what you are trying to achieve. If required, it is still possible to see all deployed components at once.

## Setting up the environment
*Log into OpenShift :*

`oc login localhost:8443 --username=admin --password=admin --insecure-skip-tls-verify=true`{{execute}}

*We'll call this project "tomcat-in-the-cloud" :*

`oc new-project tomcat-in-the-cloud`{{execute}}

With the project created, the CLI context switches to the project. It is possible to change projects, or contexts, at any time.

The command `oc projects`{{execute}} lists all projects and `oc project <project-name>` allows you to switch projects if needed.

Add the permission so each pod can read the list of other tomcat-in-the-cloud pods :

`oc policy add-role-to-user view system:serviceaccount:$(oc project -q):default -n $(oc project -q)`{{execute}}

## Deploying the web application
We created a simple rest clusterized counter demo to test how it operates in the cloud environment.

*Clone the demo from Github :*

`git clone -b stable https://github.com/web-servers/tomcat-in-the-cloud.git`{{execute}}

Then simply build and deploy it using maven

`mvn -f tomcat-in-the-cloud/pom.xml fabric8:deploy`{{execute}}

## Monitor the execution
You can orchestrate your containers either via the command line or the graphical user interface
of OpenShift. The following sections will give you some instructions on how to monitor the execution
of your running application using both of these tools.

### *Using the command line*
*Check the pods :*

`oc get pods`{{execute}}

*Check the host (route) to access the application :*

`oc describe routes`{{execute}}

> The attribute *Requested Host* provides the URL to access your application.

*Scale the application to 3 pods :*

`oc scale dc tomcat-in-the-cloud --replicas=3`{{execute}}

### *Using the graphical user interface (GUI)*
*Access the GUI :*
- Select the **Dashboard** view at the top of the screen, you'll get redirected to the OpenShift GUI
- Log in with your username/password (**admin/admin** in this scenario)
- Select the project named "tomcat-in-the-cloud"

*Check the pods :*
- Go to **Applications > Pods** to list them
- Select them to display their detailed information (Status, Used volumes, Containers, etc.)

*Check the route to access the application :*
- Go to **Applications > Routes** to get a list of the routes related to your applications
- Click on your application's **Hostname** to display it

*Scale the application to 3 pods :*
- Go to **Applications > Deployments**
- Select the deployment configuration you'd like to edit and select the **latest** deployment
- In the **Details** section, use the arrows to increase or decrease the number of running pods
3 changes: 1 addition & 2 deletions tomcat-in-the-cloud/deploy-titc-using-cli/env-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ wget https://www-eu.apache.org/dist/maven/maven-3/3.6.1/binaries/apache-maven-3.
tar xvf apache-maven-3.6.1-bin.tar.gz
mv apache-maven-3.6.1 /usr/local/apache-maven
export M2_HOME=/usr/local/apache-maven
export M2=$M2_HOME/bin
export M2=$M2_HOME/bin
export PATH=$M2:$PATH

11 changes: 7 additions & 4 deletions tomcat-in-the-cloud/deploy-titc-using-cli/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@
"details": {
"steps": [
{
"title": "Step 1 - Deployment",
"text": "1_deployment.md"
}
"title": "Step 1 - Building Dependencies",
"text": "1_buildDependencies.md"
},
{
"title": "Step 2 - Deployment",
"text": "2_deployment.md"
}
],
"intro": {
"courseData": "env-init.sh",
"code": "set-env.sh",
"text": "intro.md"
},
Expand Down
2 changes: 1 addition & 1 deletion tomcat-in-the-cloud/deploy-titc-using-cli/intro.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
In this scenario, you will learn how to deploy Tomcat in the cloud in OpenShift
Intro text...
3 changes: 2 additions & 1 deletion tomcat-in-the-cloud/deploy-titc-using-cli/set-env.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
~/.launch.sh

# Install jdk
yum install java-1.8.0-openjdk-devel.x86_64 -y
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk
Expand All @@ -8,5 +9,5 @@ wget https://www-eu.apache.org/dist/maven/maven-3/3.6.1/binaries/apache-maven-3.
tar xvf apache-maven-3.6.1-bin.tar.gz
mv apache-maven-3.6.1 /usr/local/apache-maven
export M2_HOME=/usr/local/apache-maven
export M2=$M2_HOME/bin
export M2=$M2_HOME/bin
export PATH=$M2:$PATH
12 changes: 12 additions & 0 deletions tomcat-operator-pathway.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"title": "Introduction to Openshift Tomcat-Operator",
"description": "Learn how to use the Tomcat-Operator in Openshift",
"paid": false,
"courses": [
{
"course_id": "tomcat-operator-s2i",
"title": "Deploy a Webapp via Source-to-Image (s2i)",
"description": ""
}
]
}
4 changes: 4 additions & 0 deletions tomcat-operator/tomcat-operator-s2i/1_setUp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

`git clone https://github.com/jfclere/demo-webapp.git`{{execute}}

`cd demo-webapp`{{execute}
Empty file.
1 change: 1 addition & 0 deletions tomcat-operator/tomcat-operator-s2i/finish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Finishing text...
Loading