Skip to content
This repository has been archived by the owner on Jan 21, 2022. It is now read-only.

web-servers/tomcat-operator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tomcat Operator

The purpose of this repository is to showcase a proof of concept of a simple Openshift Operator to manage tomcat Images.

Building the Operator

Requirements

To build the operator, you will first need to install the following tools:

Procedure

  1. Clone the repository under your $GOPATH
$ git clone https://github.com/web-servers/tomcat-operator.git $GOPATH/src/github.com/tomcat-operator
  1. Change to the source directory
$ cd $GOPATH/src/github.com/tomcat-operator
  1. Compile and build the Tomcat Operator
$ make build
  1. Push it to docker (docker.io/${USER}/tomcat-operator:version)
$ make push

Deploy to an Openshift Cluster

  1. Login to your Openshift Server using oc login and use it to create a new project
$ oc new-project tomcat-operator
  1. Now deploy the operator
$ make run-openshift

Deploy your Web Application

Once the Tomcat Operator has been deployed, you can now deploy your own webapps via the operator custom resources.

From Sources using Source-To-Image (s2i)

  1. Build your Web Application using Source-To-Image and git it a name prefixed with your container registry access user
$ s2i build [GIT_URL] ${USER}/tomcat-s2i docker.io/${USER}/tomcat-app
  1. Push the image
$ docker push docker.io/${USER}/tomcat-app
  1. Configure your Custom Resource
apiVersion: tomcat.apache.org/v1alpha1
kind: Tomcat
metadata:
  name: example-tomcat
spec:
  applicationName: tomcat-app
  applicationImage: docker.io/${USER}/tomcat-app
  size: 3
  1. Deploy the Custom Resource
$ oc apply -f path/to/your/custom_resource.yaml
  1. Finally, to access the newly deployed application, simply create a route using the Openshift UI

From a WAR

If you would like to deploy an existing WAR, you will have to build your container image using the tomcat-maven module of Tomcat:

  1. Build the maven fat jar for tomcat
$ git clone https://github.com/apache/tomcat
$ cd tomcat
$ ant
$ CATALINA_HOME=`pwd`
$ cd $CATALINA_HOME/res/tomcat-maven
$ mvn install
  1. Copy your WAR file into the $CATALINA_HOME/res/tomcat-maven/webapps directory
$ mkdir -p $CATALINA_HOME/res/tomcat-maven/webapps
$ cd $CATALINA_HOME/res/tomcat-maven/webapps
$ cp path/to/war .
  1. Copy your configuration files to the $CATALINA_HOME/res/tomcat-maven directory
$ mkdir -p $CATALINA_HOME/res/tomcat-maven/conf
$ mkdir -p $CATALINA_HOME/res/tomcat-maven/conf/Catalina
$ chmod g+w $CATALINA_HOME/res/tomcat-maven/conf/Catalina
$ cd $CATALINA_HOME/res/tomcat-maven
$ cp $CATALINA_HOME/output/build/conf/server.xml conf
$ cp $CATALINA_HOME/output/build/conf/logging.properties conf
$ cp $CATALINA_HOME/output/build/conf/tomcat-users.xml conf
  1. Build the container image using a tag to access your docker registry and push it
$ docker build . -t <registry>/<username>/tomcat-demo
$ docker push <registry>/<username>/tomcat-demo

Make sure that your registry is accessible by your Openshift Cluster.

  1. Configure your Custom Resource
apiVersion: tomcat.apache.org/v1alpha1
kind: Tomcat
metadata:
  name: example-tomcat
spec:
  applicationName: tomcat-app
  applicationImage: <registry>/<username>/tomcat-demo
  size: 3
  1. Deploy the Custom Resource
$ oc apply -f path/to/your/custom_resource.yaml
  1. Create a route using the Openshift UI to access your application.