Skip to content

trafficparrot/trafficparrot-examples-openshift

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

85 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Traffic Parrot service virtualization, API mocking and API simulation with OpenShift 3

This is an example of how to deploy and use a service virtualization, API mocking and API simulation tool Traffic Parrot with Docker and Openshift 3.

Follow the examples below to use Traffic Parrot in an OpenShift 3 environment.

NOTE: OpenShift 3 is now end of life

  • OpenShift 3 is now in end of life phase in favour of OpenShift 4
  • OpenShift 3 Online is replaced by OpenShift 4 cloud services
  • Minishift for OpenShift 3 is replaced by OpenShift 4 Local
  • OpenShift Origin 3 open source edition is replaced by OpenShift Origin Key Distribution 4
  • This example is still broadly applicable to OpenShift 4, but there may be slight differences in e.g. the YAML templates, permissions and oc commands that you will run into
  • If you are using OpenShift 4, please contact us and we will help you to get started with an example we have validated in OpenShift 4

Provision an OpenShift 3 cluster

There are a number of ways you can do this, for example:

  1. Locally using Minishift for OpenShift 3
  2. OpenShift Origin 3 open source edition hosted in AWS
  3. OpenShift Origin 3 open source edition hosted on premise
  4. Red Hat commercial edition hosted in OpenShift 3 Online
  5. Red Hat commercial edition hosted in AWS (requires a Red Hat subscription)
  6. Red Hat commercial edition hosted on premise (requires a Red Hat subscription)

You will need 2Gi free RAM and 2Gi free persistent volume storage to run the entire CI/CD demo including a Jenkins pipeline, demo application deployment and a Traffic Parrot deployment.

Install required tools

  1. You will need the oc client tool to issue commands to the cluster
  2. You will need Docker to be able to build and push custom Docker images to the registry

Log in to the OpenShift 3 cluster

OpenShift 3 Online

Find your login by clicking on "Command Line Tools in the web console:

Alt text

Then copy the token:

Alt text

And login to the console:

oc login https://api.<instance>.openshift.com --token=<token>

Minishift for OpenShift 3

You can use the following commands to log in with the default system user:

oc login
system
admin

Use Traffic Parrot to virtualize an OpenAPI specification as part of a CI/CD pipeline

We will work with the project trafficparrot-test

oc new-project trafficparrot-test

If you want to start again at any point, you can do:

oc delete project trafficparrot-test

Create a Traffic Parrot image

Set a local variable that contains the cluster registry, for example:

  • CLUSTER_REGISTRY=registry.<instance>.openshift.com for OpenShift 3 online
  • CLUSTER_REGISTRY=$(minishift openshift registry) for Minishift

Now let's log in to the registry so that we can build and push our Traffic Parrot image:

docker login -u developer -p $(oc whoami -t) ${CLUSTER_REGISTRY}

We build the image locally and tag it ready to be used in the cluster registry.

Note that you must set build arguments:

  1. TRAFFIC_PARROT_ZIP is a HTTP location or a local file location. You can download a trial copy.
  2. ACCEPT_LICENSE should be set to true if you accept the terms of the LICENSE
docker build \
--build-arg TRAFFIC_PARROT_ZIP=<fill this in> \
--build-arg ACCEPT_LICENSE=<fill this in> \
--tag trafficparrot:4.1.6 \
--file openshift/trafficparrot/Dockerfile .

Next, we tag and push to the cluster registry:

docker tag trafficparrot:4.1.6 ${CLUSTER_REGISTRY}/trafficparrot-test/trafficparrot-image
docker push ${CLUSTER_REGISTRY}/trafficparrot-test/trafficparrot-image

Install Jenkins

You will need Jenkins in the OpenShift 3 cluster to provide CI/CD support for the pipeline.

The easiest way to do this is via the web console catalog:

Alt text

Change the memory to 750Mi, Jenkins is quite memory hungry. Accept the default values for everything else.

NOTE: It is best to wait at least 10 minutes for Jenkins to fully start up the first time. The UI will initially be unresponsive and return an "Application is not available" message.

Import and run the pipeline

First we need the ability to build Java images:

oc create -f openshift/openjdk-s2i-imagestream.json

Now we can import the pipeline:

oc create -f openshift/finance/pipeline.yaml

Next, run the pipeline:

Alt text

The pipeline will:

  1. Build the finance-application demo image
  2. Deploy Traffic Parrot using the trafficparrot-image we pushed to the registry earlier
  3. Import the OpenAPI definition markit.yaml into Traffic Parrot
  4. Deploy the finance-application
  5. Wait for you to preview the demo

Alt text

To preview the demo, click on the finance route:

Alt text

You should see this:

Alt text

You can push the pipeline forwards by clicking on Alt text and then the button in Jenkins:

Alt text

What just happened?

Behind the scenes, we just demonstrated that the demo finance application was able to communicate with Traffic Parrot inside the cluster.

Traffic Parrot was configured by importing an OpenAPI definition markit.yaml using the HTTP Management API.

Have a look at the configuration files in this project to see how it is done. The key files are:

Clean up

To clean up the pipeline:

oc delete bc finance-pipeline

To clean up the demo app:

oc delete all -l "app=${DEMO_ID}"
oc delete configmap ${DEMO_ID}-config

To clean up Traffic Parrot:

oc delete all -l "app=${TRAFFIC_PARROT_ID}"
oc delete imagestream ${TRAFFIC_PARROT_ID}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published