Using your sandbox, s2i, and source code to build an application
Developer Sandbox for Red Hat OpenShift is a free OpenShift cluster that gives you access to the cutting-edge technologies built on Kubernetes. A quick sign-up gets you a cluster and some source code. Now, the power of Kubernetes is literally at your fingertips—for free. You can build and run sample applications. You can take an existing image and run it in OpenShift. You can select one of the built-in templates, such as MySQL, and create resources with two mouse clicks.
One of the ways to create an application is by using the Source-to-Image (s2i) feature. Here's how to use that feature to build an application.
With access to Developer Sandbox for Red Hat OpenShift ("the Sandbox"), you are ready to start using the technologies at hand. Kubernetes, images, containers, services, routes, deployments, and more — they're all there for you to start experimenting. One particularly powerful and easy-to-use feature is the "Source-To-Image", or "s2i," build process. This enables you to point OpenShift to a Git repository, supply a few optional parameters, and create an executable binary, i.e., an application.
To help you move forward and get an early success, we've taken the Spring Petclinic application and packaged it up to run in a container, along with the MySQL database that it uses. The GitHub repo contains all the instructions and code you need to create the Petclinic application using the s2i build process, along with a point-and-click creation of the MySQL database it needs.
Scenario overview
Here's a general overview of the application, with some helpful information:
- It's a container-ready implementation of the iconic Spring Petclinic application.
- The MySQL database used is ephemeral. If (when) you delete the pod running MySQL, all the data is lost. This is often very useful when developing an application, but for production, you'll want to use a persistent database.
- The database name, user, password, etc. are all hard-coded in the application; that explains why you need change the parameters when creating the MySQL database. Those specific instructions are included with the repo.
- Hard-coding is okay, especially for the name of the OpenShift service (mysql), because Kubernetes solves the "service discovery" problem. No need to know IP addresses.
- It takes about six minutes for the application to build and deploy. During that time, you may see errors being reported. That's because OpenShift will keep trying to access the application until it's up and running. Don't panic, be patient.
- After it's all built, download the YAML files for the Deployment, Service, and Route that are created. These YAML files, combined with web searches and material from Red Hat Developers, are great learning tools.
Next up
The Spring Petclinic GitHub repo contains the source code you need to experience the s2i feature at your command. Instructions for implementing the code, screen captures, and explanations of what to do and expect are part of the repo. It's not just code; It's everything you need.
Get your cluster now, then head over to the Spring Petclinic GitHub repo and start building.
Once you've finished that, it's time to try using s2i with your own code.