Skip to content

Commit

Permalink
Merge pull request #21 from redhatHameed/Jira-2742
Browse files Browse the repository at this point in the history
added 3scale toolbox Jenkins pipelines to publish API on 3scale and improvements in readme files
  • Loading branch information
nmasse-itix authored Jun 27, 2019
2 parents 2dd184a + 0c8fee4 commit a55ed37
Show file tree
Hide file tree
Showing 21 changed files with 777 additions and 2,135 deletions.
534 changes: 282 additions & 252 deletions Jenkinsfile

Large diffs are not rendered by default.

89 changes: 57 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ An integration application consisting of Multiple services working in combinatio
• OpenShift Container Platform
• Red Hat 3scale API Management
• Red Hat Fuse
• Apicurio
• MySQL Database
• Red Hat AMQ
• Node.js (RHOAR) Web Application
Expand All @@ -27,10 +28,10 @@ An integration application consisting of Multiple services working in combinatio

Steps

• Design an application using Fuse, AMQ, and 3Scale.
• Design an application using Apicurio, Fuse, AMQ, and 3Scale.
• Design API with Apicurio, integrate API with Fuse/Camel.
• Source to Image (S2I) build and deploy apps on openshift environment.
• Building a pipeline to support automated CI/CD
• Expose a REST API using Camel, and export API doc to swagger.
. Building a pipeline to support automated CI/CD
• Publish API on 3scale environment using 3scaletoolbox jenkins pipeline.
• Manage the API through 3scale API management and update the application plan to rate-limit the application.
• Design a web application that makes its calls through the 3scale API gateway.
Expand Down Expand Up @@ -79,18 +80,26 @@ If you run the above setup.sh, the pipelines are automatically imported. In case
You can also customize the pipelines by changing their parameters. Different templates have different parameters but they are all listed below:

```
Parameters Default Explanations
GIT_REPO https://github.com/rh-integration/IntegrationApp-Automation.git
GIT_BRANCH master #git branch where you want to build
OPENSHIFT_HOST <leave it for now, will be used in future release>
OPENSHIFT_TOKEN <leave it for now, will be used in future release>
DEV_PROJECT rh-dev
TEST_PROJECT rh-test
PROD_PROJECT rh-prod
MYSQL_USER dbuser #your DB user account
MYSQL_PWD password #DB user password
IMAGE_REGISTRY docker-registry.default.svc:5000 #image registry, typically the docker registry service of your OpenShift environment
IMAGE_NAMESPACE rh-dev #the OpenShift project/namespace where you built and pushed the image
NAME DESCRIPTION GENERATOR VALUE
GIT_REPO https://github.com/rh-integration/IntegrationApp-Automation
GIT_BRANCH master
DEV_PROJECT
TEST_PROJECT
PROD_PROJECT
MYSQL_USER dbuser
MYSQL_PWD password
IMAGE_REGISTRY docker-registry.default.svc:5000
IMAGE_NAMESPACE
PRIVATE_BASE_URL http://maingateway-service-rh-test.app.middleware.ocp.cloud.lab.eng.bos.redhat.com
PRODUCTION_PUBLIC_BASE_URL https://3scalefuse.app.middleware.ocp.cloud.lab.eng.bos.redhat.com
STAGING_PUBLIC_BASE_URL https://3scalefuse-staging.app.middleware.ocp.cloud.lab.eng.bos.redhat.com
PUBLIC_PRODUCTION_WILDCARD_DOMAIN app.middleware.ocp.cloud.lab.eng.bos.redhat.com
PUBLIC_STAGING_WILDCARD_DOMAIN staging.app.middleware.ocp.cloud.lab.eng.bos.redhat.com
API_BASE_SYSTEM_NAME 3scalefuse
SECRET_NAME 3scale-toolbox
TARGET_INSTANCE instance_a
DEVELOPER_ACCOUNT_ID Developer
DISABLE_TLS_VALIDATION yes
* If you have customized MYSQL_USER or MYSQL_PWD, please edit the nodejsalert-ui/config.js accordingly.
Expand Down Expand Up @@ -152,42 +161,58 @@ oc new-app -f nodejsalert-ui/resources/pipeline-app-build.yml -p IMAGE_REGISTRY=
oc new-app -f fisalert-service/src/main/resources/pipeline-app-build.yml -p IMAGE_REGISTRY=docker-registry.default.svc:5000 -p IMAGE_NAMESPACE=rh-dev -p DEV_PROJECT=rh-dev -p TEST_PROJECT=rh-test -p PROD_PROJECT=rh-prod

# import aggregated-pipeline
oc new-app -f pipelinetemplates/pipeline-aggregated-build.yml -p IMAGE_REGISTRY=docker-registry.default.svc:5000 -p IMAGE_NAMESPACE=rh-dev -p DEV_PROJECT=rh-dev -p TEST_PROJECT=rh-test -p PROD_PROJECT=rh-prod
oc new-app -f pipelinetemplates/pipeline-aggregated-build.yml -p IMAGE_REGISTRY=docker-registry.default.svc:5000 -p IMAGE_NAMESPACE=rh-dev -p DEV_PROJECT=rh-dev -p TEST_PROJECT=rh-test -p PROD_PROJECT=rh-prod -p PRIVATE_BASE_URL=http://maingateway-service-rh-test.app.middleware.ocp.cloud.lab.eng.bos.redhat.com -p PUBLIC_PRODUCTION_WILDCARD_DOMAIN=app.middleware.ocp.cloud.lab.eng.bos.redhat.com -p PUBLIC_STAGING_WILDCARD_DOMAIN=staging.app.middleware.ocp.cloud.lab.eng.bos.redhat.com -p DEVELOPER_ACCOUNT_ID=developer

# import 3scale pipeline
oc new-app -f cicd-3scale/3scaletoolbox/pipeline-template.yaml -p IMAGE_NAMESPACE=rh-dev -p DEV_PROJECT=rh-dev -p TEST_PROJECT=rh-test -p PROD_PROJECT=rh-prod
oc new-app -f cicd-3scale/3scaletoolbox/pipeline-template.yaml -p IMAGE_NAMESPACE=rh-dev -p DEV_PROJECT=rh-dev -p TEST_PROJECT=rh-test -p PROD_PROJECT=rh-prod -p PRIVATE_BASE_URL=http://maingateway-service-rh-test.app.middleware.ocp.cloud.lab.eng.bos.redhat.com -p PUBLIC_PRODUCTION_WILDCARD_DOMAIN=app.middleware.ocp.cloud.lab.eng.bos.redhat.com -p PUBLIC_STAGING_WILDCARD_DOMAIN=staging.app.middleware.ocp.cloud.lab.eng.bos.redhat.com -p DEVELOPER_ACCOUNT_ID=developer


```

After you have imported all of the pipeline templates, you should have them under `Builds`, `Pipelines` of the selected OpenShift project.
#### 3scale pipeline setup

![Pipeline View](images/pipeline_import_view.png "Pipeline View")
Before running Pipelines, listed 3scale configurtation required to set.

Please start the pipeline from `maingateway-service-pipeline`, `fisuser-service-pipeline`, `fisalert-service-pipeline`, `nodejsalert-ui-pipeline` and then `publish-api-3scale` to publish API on 3scale.

With `aggregated-pipeline`, you can build the entire application including all of the above modules mentioned. If you choose this pipeline, by default, it will build the entire application, but you will also be asked to select which individual module you want to bulid. You will need to make your selection in your Jenkins console.
* Create the routes for your APIcast gateways in 3scale Project if required with below command

Once the build is finished, in your OpenShift, go to `rh-test` or `rh-prod`, nevigate to `Applications`, `Routes` and click on maingateway-service and nodejsalert-ui URL to launch the application.
You should see the application and it is started with web front-end like this:
```sh
oc new-app -f apicast-routes-template.yaml -p BASE_NAME=rh-test-3scalefuse -p MAJOR_VERSION=1 -p WILDCARD_DOMAIN=<openshift_wildcard_domain> -n <3scale_namespace>
oc new-app -f apicast-routes-template.yaml -p BASE_NAME=rh-prod-3scalefuse -p MAJOR_VERSION=1 -p WILDCARD_DOMAIN=<openshift_wildcard_domain> -n <3scale_namespace>

* BASE_NAME = project environment name- base name mentioned in Jenkins pipeline
```

![Application View](images/application_launch_view.png "Application View")
* set below listed parameters

```sh
PRIVATE_BASE_URL
PUBLIC_PRODUCTION_WILDCARD_DOMAIN
PUBLIC_STAGING_WILDCARD_DOMAIN
API_BASE_SYSTEM_NAME
SECRET_NAME
TARGET_INSTANCE
DEVELOPER_ACCOUNT_ID
DISABLE_TLS_VALIDATION set "yes" to disable TLS validation.
```
* Read [3scaletoolbox Configuration]( https://github.com/rh-integration/3scale-toolbox-jenkins-samples )

### In-process Script Approval & 3scale pipeline setup
#### Run pipelines

Before running `Pipelines `, please read the following instructions.
After you have set the parameters and imported all of the pipeline templates, you should have them under `Builds`, `Pipelines` of the selected OpenShift project.

![Pipeline View](images/pipeline_import_view.png "Pipeline View")

* In Jenkins 2, running script in pipeline are subject to script security check (this issue will be faced with smoke test step script), and the script has to be approved before it is allowed to run. When you start to run ` Pipelines`, you mostly will encounter "Scripts not permitted to use method ... " exceptions. If this happens, please login Jenkins as an administrator, go to "Manage Jenkins", "In-process Script Approval" page to approval the script. You may need to do the approval multiple times as we found that Jenkins does the check on method level. You only need to approve once on all those methods during the first run. We suggest you to use persistent storage enabled Jenkins pod so that your approvals can be saved and reloaded if pod is restarted.
Please start the pipeline from `maingateway-service-pipeline`, `fisuser-service-pipeline`, `fisalert-service-pipeline`, `nodejsalert-ui-pipeline` and then `publish-api-3scale` to publish API on 3scale.

* Create the routes for your APIcast gateways in 3scale Project if required with below command
With `aggregated-pipeline`, you can build the entire application including all of the above modules mentioned. If you choose this pipeline, by default, it will build the entire application, but you will also be asked to select which individual module you want to bulid. You will need to make your selection in your Jenkins console.

Once the build is finished, in your OpenShift, go to `rh-test` or `rh-prod`, nevigate to `Applications`, `Routes` and click on maingateway-service and nodejsalert-ui route to launch the application.
You should see the application and it is started with web front-end like this, add 3scale user key and 3scale gatway url and click sendAlert button:

![Application View](images/application_launch_view.png "Application View")

```sh
oc new-app -f apicast-routes-template.yaml -p BASE_NAME=3scalefuse -p WILDCARD_DOMAIN=<openshift_wildcard_domain> -n <3scale_namespace>
```

* Read [3scaletoolbox Configuration](cicd-3scale/README.md)

### Deploy with BlueGreen Deployment Strategy

Expand Down
83 changes: 43 additions & 40 deletions apicast-routes-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,47 @@ metadata:
description: RHTE APIcast Routes
name: rhte-apicast-routes
objects:
- apiVersion: route.openshift.io/v1
kind: Route
metadata:
name: ${BASE_NAME}-staging
spec:
host: ${BASE_NAME}-staging.${WILDCARD_DOMAIN}
port:
targetPort: gateway
tls:
termination: edge
insecureEdgeTerminationPolicy: Allow
to:
kind: Service
name: apicast-staging

- apiVersion: route.openshift.io/v1
kind: Route
metadata:
name: ${BASE_NAME}-production
spec:
host: ${BASE_NAME}.${WILDCARD_DOMAIN}
port:
targetPort: gateway
tls:
termination: edge
insecureEdgeTerminationPolicy: Allow
to:
kind: Service
name: apicast-production

parameters:
- description: The DNS domain under which APIs will be exposed
displayName: 3scale wildcard domain
name: WILDCARD_DOMAIN
required: true
- description: 'The system_name of the API, converted to DNS ("_" -> "-")'
displayName: 3scale API Base Name
name: BASE_NAME
value: rhte-api
required: true
- apiVersion: route.openshift.io/v1
kind: Route
metadata:
name: ${BASE_NAME}-${MAJOR_VERSION}-staging
spec:
host: ${BASE_NAME}-${MAJOR_VERSION}.staging.${WILDCARD_DOMAIN}
port:
targetPort: gateway
tls:
termination: edge
insecureEdgeTerminationPolicy: Allow
to:
kind: Service
name: apicast-staging

- apiVersion: route.openshift.io/v1
kind: Route
metadata:
name: ${BASE_NAME}-${MAJOR_VERSION}-production
spec:
host: ${BASE_NAME}-${MAJOR_VERSION}.${WILDCARD_DOMAIN}
port:
targetPort: gateway
tls:
termination: edge
insecureEdgeTerminationPolicy: Allow
to:
kind: Service
name: apicast-production

parameters:
- description: The DNS domain under which APIs will be exposed
displayName: 3scale wildcard domain
name: WILDCARD_DOMAIN
required: true
- description: 'The system_name of the API, converted to DNS ("_" -> "-")'
displayName: 3scale API Base Name
name: BASE_NAME
value: rhte-api
required: true
- description: The API major version (1, 2, etc.)
displayName: 3scale API major version
name: MAJOR_VERSION
required: true
Loading

0 comments on commit a55ed37

Please sign in to comment.