The purpose of this repository is to showcase a proof of concept of a simple Openshift Operator to manage tomcat Images.
To build the operator, you will first need to install the following tools:
- Go with
$GOPATH
set to$HOME/go
- Docker
- Operator-sdk
- Clone the repository under your
$GOPATH
$ git clone https://github.com/web-servers/tomcat-operator.git $GOPATH/src/github.com/tomcat-operator
- Change to the source directory
$ cd $GOPATH/src/github.com/tomcat-operator
- Compile and build the Tomcat Operator
$ make build
- Push it to docker (docker.io/${USER}/tomcat-operator:version)
$ make push
- Login to your Openshift Server using
oc login
and use it to create a new project
$ oc new-project tomcat-operator
- Now deploy the operator
$ make run-openshift
Once the Tomcat Operator has been deployed, you can now deploy your own webapps via the operator custom resources.
- 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
- Push the image
$ docker push docker.io/${USER}/tomcat-app
- 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
- Deploy the Custom Resource
$ oc apply -f path/to/your/custom_resource.yaml
- Finally, to access the newly deployed application, simply create a route using the Openshift UI
If you would like to deploy an existing WAR, you will have to build your container image using the tomcat-maven module of Tomcat:
- 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
- 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 .
- 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
- 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.
- 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
- Deploy the Custom Resource
$ oc apply -f path/to/your/custom_resource.yaml
- Create a route using the Openshift UI to access your application.