sectionid | sectionclass | title | parent-id |
---|---|---|---|
ratingsapi |
h2 |
Deploy Ratings API |
lab-ratingapp |
The rating-api
is a NodeJS application that connects to mongoDB to retrieve and rate items. Below are some of the details that you'll need to deploy this.
rating-api
on GitHub: https://github.com/microsoft/rating-api- The container exposes port 8080
- MongoDB connection is configured using an environment variable called
MONGODB_URI
To be able to setup CI/CD webhooks, you'll need to fork the application into your personal GitHub repository.
Note You're going to be using source-to-image (S2I) as a build strategy.
{% collapsible %}
oc new-app https://github.com/<your GitHub username>/rating-api --strategy=source
{% endcollapsible %}
{% collapsible %}
Create the MONGODB_URI
environment variable. This URI should look like mongodb://[username]:[password]@[endpoint]:27017/ratingsdb
. You'll need to replace the [usernaame]
and [password]
with the ones you used when creating the database. You'll also need to replace the [endpoint]
with the hostname acquired in the previous step
Hit Save when done.
{% endcollapsible %}
{% collapsible %}
If you navigate to the logs of the rating-api
deployment, you should see a log message confirming the code can successfully connect to the mongoDB.
{% endcollapsible %}
{% collapsible %}
Find the rating-api
service.
oc get svc rating-api
The service will be accessible at the following DNS name over port 8080: rating-api.workshop.svc.cluster.local:8080
which is formed of [service name].[project name].svc.cluster.local
. This resolves only within the cluster.
{% endcollapsible %}
To trigger S2I builds when you push code into your GitHib repo, you'll need to setup the GitHub webhook.
{% collapsible %}
Retrieve the GitHub webhook trigger secret. You'll need use this secret in the GitHub webhook URL.
oc get bc/rating-api -o=jsonpath='{.spec.triggers..github.secret}'
You'll get back something similar to the below. Make note the secret key in the red box as you'll need it in a few steps.
Retrieve the GitHub webhook trigger URL from the build configuration.
oc describe bc/rating-api
Replace the <secret>
placeholder with the secret you retrieved in the previous step to have a URL similar to https://openshift.9729df58f18c47bab789.eastus.azmosa.io:443/apis/build.openshift.io/v1/namespaces/workshop/buildconfigs/rating-api/webhooks/1inS0TVIN-Zw92xxtIXr/github
. You'll use this URL to setup the webhook on your GitHub repository.
In your GitHub repository, select Add Webhook from Settings → Webhooks.
Paste the URL output (similar to above) into the Payload URL field.
Change the Content Type from GitHub’s default application/x-www-form-urlencoded to application/json.
Click Add webhook.
You should see a message from GitHub stating that your webhook was successfully configured.
Now, whenever you push a change to your GitHub repository, a new build will automatically start, and upon a successful build a new deployment will start.
{% endcollapsible %}
Resources