Skip to content

Commit

Permalink
Merge pull request #1186 from dewan-ahmed/dewan-springstarter-upgrade-47
Browse files Browse the repository at this point in the history
47 image update and related changes - Spring Starter course
  • Loading branch information
ryanj authored Jun 21, 2021
2 parents b154a68 + 763e183 commit c1f1558
Show file tree
Hide file tree
Showing 13 changed files with 129 additions and 39 deletions.
Binary file modified assets/middleware/rhoar-getting-started-spring/login.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/middleware/rhoar-getting-started-spring/overview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/middleware/rhoar-getting-started-spring/projects.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
In this scenario, you will learn more about developer application using Spring Boot using [Red Hat OpenShift Application Runtimes](https://developers.redhat.com/products/rhoar).
In this scenario, you will learn more about developer application using Spring Boot using [Red Hat Runtimes](https://ww.redhat.com/products/runtimes).


## What you will learn
Expand All @@ -8,4 +8,4 @@ You will learn how to get started with building a CRUD (Create, Read, Update and

Spring is one of the most popular Java Frameworks and offers an alternative to the Java EE programming model. Spring is also very popular for build application based on Microservices Architecture. Spring Boot is a popular tool in the Spring eco system that helps with organizing/using 3rd party libraries together with Spring and also provides a mechanism for boot strapping embeddable runtimes, like Apache Tomcat. Bootable applications (sometimes also called fat jars) fits the container model very well since in a container platform like OpenShift responsibilities like starting, stopping and monitoring applications are then handled by the container platform instead of an Application Server.

Red Hat fully supports Spring and Spring Boot for usage on the OpenShift platform as part of Red Hat OpenShift Application Runtimes. Red Hat also provides full support for Apache Tomcat, Hibernate and Apache CXF (for REST services) when used in a Spring Boot application on OpenShift Application Runtimes.
Red Hat fully supports Spring and Spring Boot for usage on the OpenShift platform as part of Red Hat Runtimes. Red Hat also provides full support for Apache Tomcat, Hibernate and Apache CXF (for REST services) when used in a Spring Boot application on Red Hat Runtimes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Import the code

Let's refresh the code we'll be using. Run the following command to clone the sample project:

`cd /root/projects && rm -rf rhoar-getting-started && git clone https://github.com/openshift-katacoda/rhoar-getting-started && cd rhoar-getting-started/spring/spring-rhoar-intro`{{execute}}

# Review the base structure of the application

For your convenience, this scenario has been created with a base project using the Java programming language and the Apache Maven build tool.
Expand All @@ -11,27 +17,26 @@ The output should look something like this
|-- pom.xml
`-- src
`-- main
|-- fabric8
|-- jkube
| |-- credentials-secret.yml
| |-- deployment.yml
| `-- route.yml
|-- java
| |-- route.yml
|`-- java
| `-- com
| `-- example
| |-- Application.java
| `-- booster
| `-- service
| |-- Application.java
| |`-- service
`-- resources
|-- application-local.properties
|-- application-openshift.properties
`-- static
`-- index.html
|-- index.html
```


As you can see, there are some files that we have prepared for you in the project. Under src/main/resources/index.html we have for example prepared an html file for you. Except for the fabric8 directory and the index.html, this matches very well what you would get if you generate an empty project from the [Spring Initializr](https://start.spring.io) web page. For the moment you can ignore the content of the fabric8 folder (we will discuss this later).
As you can see, there are some files that we have prepared for you in the project. Under src/main/resources/index.html we have, for example, prepared an HTML file for you. Except for the jkube directory and the index.html, this matches very well what you would get if you generate an empty project from the [Spring Initializr](https://start.spring.io) web page. For the moment you can ignore the content of the jkube folder (we will discuss this later).

One this that differs slightly is the `pom.xml`. Please open the and examine it a bit closer (but do not change anything at this time)
One that differs slightly is the `pom.xml`. Please open the and examine it a bit closer (but do not change anything at this time)

``pom.xml``{{open}}

Expand Down Expand Up @@ -79,15 +84,15 @@ Run the application by executing the below command:

``mvn spring-boot:run``{{execute}}

>**NOTE:** The Katacoda terminal window is like your local terminal. Everything that you run here you should be able to execute on your local computer as long as you have a `Java SDK 1.8` and `Maven`. In later steps, we will also use the `oc` command line tool.
>**NOTE:** The Katacoda terminal window is like your local terminal. Everything that you run here you should be able to execute on your local computer as long as you have a `Java JDK 11` and `Maven`. In later steps, we will also use the `oc` command line tool.
**3. Verify the application**

To begin with, click on the **Local Web Browser** tab in the console frame of this browser window, which will open another tab or window of your browser pointing to port 8080 on your client.

![Local Web Browser Tab](/openshift/assets/middleware/rhoar-getting-started-spring/web-browser-tab.png)

or use [this](https://[[HOST_SUBDOMAIN]]-8080-[[KATACODA_HOST]].environments.katacoda.com/) link.
or use [this](https://[[CLIENT_SUBDOMAIN]]-8080-[[KATACODA_HOST]].environments.katacoda.com/) link.

You should now see an HTML page that looks like this:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ In Step 1 you learned how to get started with our project. In this step, we will

Since our applications (like most) will need to access a database to read retrieve and store fruits entries, we need to add Java Persistence API to our project.

The default implementation in Spring Boot is Hibernate which has been tested as part of the OpenShift Application Runtimes.
The default implementation in Spring Boot is Hibernate which has been tested as part of the Red Hat Runtimes.

>**NOTE:** Hibernate is another Open Source project that is maintained by Red Hat and it will soon be productized (as in fully supported) in OpenShift Application Runtimes.
>**NOTE:** Hibernate is another Open Source project that is maintained by Red Hat and it will soon be productized (as in fully supported) in Red Hat Runtimes.
To add Hibernate to our project all we have to do is to add the following line in ``pom.xml``{{open}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ Build and start the application again

Now that we have implemented all the services we are now able to see fruits on the page, and also update, create and delete them.

When the console reports that Spring is up and running access the web page by either click the Web Browser Tab or use [this](https://[[HOST_SUBDOMAIN]]-8080-[[KATACODA_HOST]].environments.katacoda.com/) link.
When the console reports that Spring is up and running access the web page by either click the Web Browser Tab or use [this](https://[[CLIENT_SUBDOMAIN]]-8080-[[KATACODA_HOST]].environments.katacoda.com/) link.

![Local Web Browser Tab](/openshift/assets/middleware/rhoar-getting-started-spring/web-browser-tab.png)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ OpenShift also ships with a feature rich web console as well as command line too

To login, we will use the `oc` command and then specify username and password like this:

`oc login [[HOST_SUBDOMAIN]]-8443-[[KATACODA_HOST]].environments.katacoda.com -u developer -p developer --insecure-skip-tls-verify=true`{{execute interrupt}}
``oc login [[HOST_SUBDOMAIN]]-6443-[[KATACODA_HOST]].environments.katacoda.com --insecure-skip-tls-verify=true -u developer -p developer``{{execute}}

Congratulations, you are now authenticated to the OpenShift server.

Expand Down Expand Up @@ -40,7 +40,7 @@ After you have authenticated to the web console, you will be presented with a li

![Web Console Projects](/openshift/assets/middleware/rhoar-getting-started-spring/projects.png)

Click on your new project name to be taken to the project overview page which will list all of the routes, services, deployments, and pods that you have created as part of your project:
Click on your new project name to be taken to the project overview page which will show you various options to add content to your project, create an application, component or service:

![Web Console Overview](/openshift/assets/middleware/rhoar-getting-started-spring/overview.png)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ Since this is your own personal project you need to create a database instance t
``oc new-app -e POSTGRESQL_USER=luke \
-e POSTGRESQL_PASSWORD=secret \
-e POSTGRESQL_DATABASE=my_data \
openshift/postgresql-92-centos7 \
openshift/postgresql:12-el8 \
--name=my-database``{{execute}}

**2. Review Database configuration**

Take some time and review the ``src/main/fabric8/deployment.yml``{{open}}.
Take some time and review the ``src/main/jkube/deployment.yml``{{open}}.

As you can see that file specifies a couple of elements that are needed for our deployment. It also uses the username and password from a Kubernetes Secret. For this environment we are providing the secret in this file ``src/main/fabric8/credentials-secret.yml``{{open}}, however in a production environment this would likely be provided to you by the Ops team.
As you can see that file specifies a couple of elements that are needed for our deployment. It also uses the username and password from a Kubernetes Secret. For this environment we are providing the secret in this file ``src/main/jkube/credentials-secret.yml``{{open}}, however in a production environment this would likely be provided to you by the Ops team.

Now, review the ``src/main/resources/application-openshift.properties``{{open}}

Expand All @@ -33,7 +33,6 @@ So far our application has only used the H2 Database, we now need to add a depen
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgresql.version}</version>
<scope>runtime</scope>
</dependency>
</pre>
Expand All @@ -52,15 +51,15 @@ We also need a health check so that OpenShift can detect when our application is

**5. Deploy the application to OpenShift**

Run the following command to deploy the application to OpenShift
Run the following command to deploy the application to OpenShift:

``mvn package fabric8:deploy -Popenshift -DskipTests``{{execute}}
``mvn package oc:deploy -Popenshift -DskipTests``{{execute}}

After the maven build as finished, it will typically take less than 20 sec for the application to be available. To verify that everything is started run the following command and wait for it to report replication controller "fruits-s2i-1" successfully rolled out:
This step may take some time to do the Maven build and the OpenShift deployment. After the build completes you can verify that everything is started by running the following command:

``oc rollout status dc/fruits``{{execute}}
``oc rollout status dc/spring-getting-started``{{execute}}

Then either go to the openshift web console and click on the route or click [here](http://fruits-dev.[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com)
Then either go to the openshift web console and click on the route or click [here](http://spring-getting-started-dev.[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com)

Make sure that you can add, edit, and remove fruits, using the web application

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>/root/.m2/repository</localRepository>
<interactiveMode>false</interactiveMode>
<profiles>
<profile>
<id>jboss-enterprise-maven-repository-ga</id>
<repositories>
<repository>
<id>jboss-enterprise-maven-repository-ga</id>
<url>https://maven.repository.redhat.com/ga/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>jboss-enterprise-maven-repository-ga</id>
<url>https://maven.repository.redhat.com/ga/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
<profile>
<id>jboss-enterprise-maven-repository-earlyaccess</id>
<repositories>
<repository>
<id>jboss-enterprise-maven-repository-ea</id>
<url>https://maven.repository.redhat.com/earlyaccess/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>jboss-enterprise-maven-repository-ea</id>
<url>https://maven.repository.redhat.com/earlyaccess/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>jboss-enterprise-maven-repository-ga</activeProfile>
<!--<activeProfile>jboss-enterprise-maven-repository-earlyaccess</activeProfile>-->
</activeProfiles>
</settings>
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
ssh root@host01 "git --git-dir=/root/projects/rhoar-getting-started/.git --work-tree=/root/projects/rhoar-getting-started pull"
ssh root@host01 "yum install tree -y"
ssh root@host01 "touch /etc/rhsm/ca/redhat-uep.pem"
mkdir -p /root/projects/rhoar-getting-started/spring/spring-rhoar-intro
echo "-w \"\n\"" >> ~/.curlrc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"pathwayTitle": "Intro to Red Hat OpenShift Application Runtimes",
"icon": "fa-openshift",
"icon": "fa-java",
"title": "Spring Boot development on OpenShift",
"description": "In this scenario you will learn more about Spring Boot, one of the runtimes included in Red Hat OpenShift Application Runtimes.",
"description": "In this scenario you will learn more about Spring Boot, one of the runtimes included in Red Hat Runtimes.",
"difficulty": "beginner",
"time": "15 minutes",
"details": {
Expand All @@ -20,23 +20,30 @@
},
"finish": {
"text": "99-outro.md"
},
"assets": {
"client": [
{ "file": "maven/settings.xml", "target": "/root/.m2" }
]
}
},
"files": [

],
"environment": {
"showdashboard": true,
"dashboards": [{"name":"Local Web Browser","port":8080},{"name":"OpenShift Console","port":8443}],
"dashboards": [{"name":"Local Web Browser","href": "https://[[CLIENT_SUBDOMAIN]]-8080-[[KATACODA_HOST]].environments.katacoda.com"},{"name":"OpenShift Console","href": "https://console-openshift-console-[[HOST_SUBDOMAIN]]-443-[[KATACODA_HOST]].environments.katacoda.com"}],
"uilayout": "editor-terminal",
"uisettings": "java",
"hideintro": false,
"hideHiddenFiles": true,
"uieditorpath": "/root/projects/rhoar-getting-started/spring/spring-rhoar-intro",
"uimessage1": "\u001b[32mYour Interactive Bash Terminal. A safe place to learn and execute commands.\u001b[m\r\n"
},
"backend": {
"autoUpgrade": false,
"imageid": "openshift-middleware-3-7",
"imageid": "openshift-4-7",
"port": 8443
}
}




Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
#!/bin/bash
cd projects/rhoar-getting-started/spring/spring-rhoar-intro
~/.launch.sh

mkdir -p /root/projects/rhoar-getting-started/spring/spring-rhoar-intro
cd /root/projects/rhoar-getting-started/spring/spring-rhoar-intro

# Install Java 11
wget -O /tmp/jdk.tar.gz https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.10%2B9/OpenJDK11U-jdk_x64_linux_hotspot_11.0.10_9.tar.gz && \
pushd /usr/local && \
tar -xvzf /tmp/jdk.tar.gz && \
rm -rf /tmp/jdk.tar.gz && \
export JAVA_HOME="/usr/local/jdk-11.0.10+9" && \
export PATH=$JAVA_HOME/bin:$PATH && \
echo "export JAVA_HOME=$JAVA_HOME" >> ~/.bashrc && \
echo "export PATH=$JAVA_HOME/bin:\$PATH" >> ~/.bashrc && \
popd

clear

0 comments on commit c1f1558

Please sign in to comment.