Page
Deploy the Spring Pet Clinic application with configured environment variables
Camels, pythons, and cats — oh my! In this scenario, the line of animals and their owners has surrounded the building, and the employees at the Pet Clinic can’t keep up with demand. The clinic needs an application to help them run the clinic more efficiently. Management wants to keep track of the pets, their owners, and the veterinarians that work at the Pet Clinic. You’ll need to create a set of microservices that lets employees view the list of veterinarians and their specialties, add new pets and owners, plus update information about existing pets and owners, and manage their visits. Of course, the application needs to be delivered yesterday.
In order to get full benefit from taking this lesson, you need to:
- Have access to the OpenShift dashboard
- Have the MySQL database service available
In this lesson, you will:
- Create a deployment of the Spring Pet Clinic application with the necessary environment variables
Deploy from source using S2I
One of the ways to create an application is by using the Source-To-Image (S2I) feature. The S2I feature allows you to import source code from a git repository and let OpenShift automatically build and start an image. In this lesson, you will create the Spring Pet Clinic app from source.
Begin by logging into your sandbox; the dashboard will appear in your browser.
Select the Developer perspective (Figure 1, Callout 1), then click the +Add option (Figure 1, Callout 2), then click the Git Repository panel (Figure 1, Callout 3).
When the Import from Git panel is displayed, enter the following value for the git repo (Figure 2, Callout 1): https://github.com/redhat-developer-demos/spring-petclinic
You will see the Import is not possible error message. When you specify a Git repo, OpenShift will inspect it and try to determine the best way to build the source code.
The three options are:
- Build from source as-is using a build image for the programming language, e.g. Java
- Use any Dockerfile in the source code to build the app
- Use any development configuration file (
devfile
) to build the app
In this case, the source code contains a development configuration file (devfile
) that is outdated, causing the error. You need to override this by clicking on the Edit Import Strategy link (Figure 2, Callout 2).
After selecting the Edit Import Strategy link, choose the Builder Image option (Figure 3).
Scroll down and open the Resource type dropdown list. Select the Deployment option (Figure 4).
Select the link to access the advanced options for the Build configuration (Figure 5).
Enter the two necessary Environment variables:
- SPRING_PROFILES_ACTIVE mysql
- MYSQL_URL jdbc:mysql://mysql:3306/petclinic
Click Create to build the application (Figure 6).
The build will begin. After a few minutes, you will see the app icon showing the completed build. You will know the build is complete when the outer ring turns dark blue. When it's complete, click the Open URL link to display the app (Figure 7).
Your browser will open to the Spring Petclinic app (Figure 8).
Summary
Congratulations. You've done it. We have walked you through a simplistic example that demonstrates the power of OpenShift S2I. This lesson has walked you through entering required parameters and creating the Spring Petclinic app from source code..
Want to learn more? Try these: