First, deploy the coolstore monolith dev project (don’t forget to include -b app-partner when you run git clone - this is the branch in use for this lab!):
$ mkdir ~/coolstore
$ cd ~/coolstore
$ git clone -b app-partner https://github.com/epe105/monolith
$ cd monolith
Please update <USERNAME>
below with your assigned username
$ oc new-project coolstore-<USERNAME>
$ oc process -f src/main/openshift/template.json | oc create -f -
Notice there is no deployment yet as there is no build yet:
Build the coolstore monolith (.war file) locally and deploy into the OpenShift via the binary build:
$ cd ~/coolstore/monolith
$ mvn clean package -Popenshift
$ oc start-build coolstore --from-file deployments/ROOT.war --follow
In the web console, navigate to Builds → Images to see the new image created as a result of combining the monolith .war file with the JBoss EAP builder image
Once the deployment is complete, navigate to the application by clicking on its route in the OpenShift web console Overview and exercise the app by adding/removing products to your shopping cart:
Log into the database pod (with postgresql in the pod name) and inspect the values stored (you will need to copy/paste the password from the POSTGRESQL_PASSWORD environment variable when running the psql command):
Make note of POSTGRESQL_PASSWORD
$ oc env dc/coolstore-dev-postgresql --list # copy value of POSTGRESQL_PASSWORD to clipboard
Make note of postgresql pod
$ oc get pods
oc rsh into postresql pod
$ oc rsh coolstore-dev-postgresql-1-3rfuw
sh-4.2$ psql -h $HOSTNAME -d $POSTGRESQL_DATABASE -U $POSTGRESQL_USER
Password for user userV31:XXXXXXXX
psql (9.5.4)
Type "help" for help.
monolith=> select * from INVENTORY;
monolith=> select * from PRODUCT_CATALOG;
Exit out of psql and then the postgresql pod
monolith=> \q
sh-4.2$ exit
exit
Create the production deployment objects that will be used to promote builds from dev to prod using the supplied CI/CD pipeline:
$ oc process -f ~/coolstore/monolith/src/main/openshift/template-prod.json | oc create -f -
Inspect the pipeline and observe the steps it executes during the pipeline run. Notice at the end of the script, the latest coolstore image is tagged with :prod, triggering a production deployment:
$ oc get bc/monolith-pipeline -o yaml
...
openshiftTag(sourceStream: 'coolstore', sourceTag: 'latest', namespace: '', destinationStream: 'coolstore', destinationTag: 'prod', destinationNamespace: '')
...
Wait for the jenkins service to be completely available, then execute the pipeline by navigating to Builds→ Pipelines and click on Start Pipeline next to the Monolith Pipeline:
Return to the Overview page, wait for the deployment to complete, then click on the route for the coolstore-prod deployment to test the production app (identical to coolstore-dev).
You should now have two identical copies of the app deployed, along with two databases:
Scale down the coolstore-dev environment by clicking the down arrow next to the coolstore-dev and coolstore-dev-postgresql pods:
If your build pipeline fails to start, you can manually tag the images:
$ oc tag coolstore:latest coolstore:prod