Take note of the new Dockerfile in the application's directory. We've pre-written it for you. But we've copied it here too, go through each line and read the corresponding comment.
# Use an official JDK image
FROM maven:3.5-jdk-8 as BUILD
# Copy the application source code
COPY src /usr/src/app/src
COPY pom.xml /usr/src/app
# Run maven to build the application
RUN mvn -f /usr/src/app/pom.xml clean package
FROM open-liberty:microProfile2-java11
COPY liberty/server.xml /config/
COPY --from=BUILD /usr/src/app/target/authors.war /config/apps/
# Allow traffic on port 3000
EXPOSE 3000
From the OpenShift console click the user name in the top right corner and select Copy Login Command.
The login command will be copied to the clipboard, in the IBM Cloud Shell, paste that command. For example:
Create a new OpenShift project to deploy our application, call it cloud-native-starter.
ocnew-projectcloud-native-starter
Build your application's image by running the oc new-build command from your source code root directory. This will create a Build and an ImageStream of the app.
View the build logs by running the oc logs command.
oclogsbc/authors
Finally, deploy the application by running oc new-app.
ocnew-app-iauthors
The output should look like below:
$ocnew-app-iauthors-->Foundimaged3dfc36 (5 minutesold) in image stream "cloud-native-starter/authors" under tag "latest"for"authors"*Thisimagewillbedeployedindeploymentconfig"authors"*Ports3000/tcp,9080/tcp,9443/tcpwillbeloadbalancedbyservice"authors"*Othercontainerscanaccessthisservicethroughthehostname"authors"-->Creatingresources...deploymentconfig.apps.openshift.io"authors"createdservice"authors"created-->SuccessApplicationisnotexposed.Youcanexposeservicestotheoutsideworldbyexecutingoneormoreofthecommandsbelow:'oc expose svc/authors'Run'oc status'toviewyourapp
View the deployment logs by running the oc logs command.
oclogsdc/authors
The output should look like:
$oclogsdc/authorsLaunchingdefaultServer (Open Liberty19.0.0.10/wlp-1.0.33.cl191020191002-0300) on Eclipse OpenJ9 VM, version 11.0.4+11 (en_US)[AUDIT ] CWWKE0001I: The server defaultServer has been launched.[AUDIT ] CWWKG0093A: Processing configuration drop-ins resource: /opt/ol/wlp/usr/servers/defaultServer/configDropins/defaults/keystore.xml[AUDIT ] CWWKG0093A: Processing configuration drop-ins resource: /opt/ol/wlp/usr/servers/defaultServer/configDropins/defaults/open-default-port.xml[AUDIT ] CWWKZ0058I: Monitoring dropins for applications.[AUDIT ] CWWKS4104A: LTPA keys created in 2.099 seconds. LTPA key file: /opt/ol/wlp/output/defaultServer/resources/security/ltpa.keys[AUDIT ] CWPKI0803A: SSL certificate created in 4.881 seconds. SSL key file: /opt/ol/wlp/output/defaultServer/resources/security/key.p12
Expose the service using oc expose, a route will be created.
ocexposesvc/authors
Find the application's route by running oc get routes.