We will use oc new-app
to build a simple NodeJS application that uses the NextJS React framework. The application is trivial - simply taking an input text (reversing or not) and then storing it in a PostgreSQL database.
The first step of the pipeline is to provision an instance of a composition (step 3) which has populated its connection details into a secret in the cluster.
The OpenShift template has two key parts - the BuildConfig
and DeploymentConfig
.
The BuildConfig
instructions build the Next application (next build
) and run a script to create the database schema, tables and pre-populate with base data - in the database provisioned by Crossplane.
The DeploymentConfig
specification also utilises the connections information from the secret so that the application at runtime can connect and use the database.
oc project demo-apps
oc new-app -f ./reverse-app-acme-stack-oc-template.yaml \
-p NAME=reverse-app-pg -p SERVER_PORT=3000 -p CONN_NAME=acme-postgresqlinstance-conn
Output
--> Deploying template "demo-apps/reverse-app-with-pg" for "./reverse-app-acme-stack-oc-template.yaml" to project demo-apps
Node.js
---------
Simple NodeJS app interacting with PostgreSQL database
The following service(s) have been created in your project: reverse-app-pg.
* With parameters:
* Name=reverse-app-pg
* Namespace=openshift
* Version of NodeJS Image=12
* Memory Limit=512Mi
* Git Repository URL=https://github.com/jeremycaine/reverse-app-with-pg.git
* Git Reference=
* Context Directory=
* Application Hostname=
* GitHub Webhook Secret=XXXXXX # generated
* Generic Webhook Secret=XXXXX # generated
* Custom NPM Mirror URL=
* Server Listen Port=3000
* Postgres Connection Secret=acme-postgresqlinstance-conn
--> Creating resources ...
service "reverse-app-pg" created
route.route.openshift.io "reverse-app-pg-route" created
imagestream.image.openshift.io "reverse-app-pg" created
buildconfig.build.openshift.io "reverse-app-pg" created
deploymentconfig.apps.openshift.io "reverse-app-pg" created
--> Success
Access your application via route '[YOUR ROUTE WILL APPEAR HERE]'
Build scheduled, use 'oc logs -f bc/reverse-app-pg' to track its progress.
Run 'oc status' to view your app.
Launch the app at the URL generated by the OpenShift Route.
oc get route
The build uses the git repo name as the app selector e.g. reverse-app-with-pg
To delete all the components of the app deployment:
oc delete all -l app=reverse-app-with-pg