-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 048ffe8
Showing
33 changed files
with
1,339 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
# CICD Pipleline for WSO2 API Manager | ||
|
||
## Overview | ||
|
||
APIs have become the defacto for connecting apps, services and data. Organizations have multiple environments such as | ||
Dev, Test and Prod for different purposes. Therefore, the APIs need to be available in each environment after developers | ||
specify the required conditions. Manually promoting APIs between environments is a tedious, error-prone, and | ||
time-consuming task. This drastically reduces an organization’s productivity. | ||
|
||
WSO2 API Manager addresses the issue of API automation by providing a platform-agnostic, developer-centric solution. | ||
WSO2 API Controller, apictl tool plays a key role in the automation pipeline | ||
|
||
![CI/CD pipeline for APIs with WSO2 API Manager](images/ci-cd-pipeline-for-apis-with-wso2-apim.png) | ||
|
||
## Architecture | ||
|
||
For this demonstration the following architecture will be used. | ||
|
||
![CI/CD pipeline architecture](images/ci-cd-pipeline-demo-architecture.png) | ||
|
||
## Prerequisites | ||
|
||
1. Deploy the backend server | ||
2. Install the Jenkins server | ||
3. Install WSO2 API Manager | ||
|
||
### 1. Deploy the backend server | ||
|
||
Sample user service is used as the backend server and the complete source code of that server can be found | ||
[here](backend_server). Note that this is a Spring Boot application and the following commands can be used to start | ||
or build the application | ||
|
||
* Start the application : `mvn spring-boot:run` | ||
* Build the application : `mvn clean install` | ||
|
||
Note that the jar is already built and stored [here](backend_server/target/backend-server-1.0.0.jar) and that can be | ||
simply started by executing `java -jar target/backend-server-1.0.0.jar` | ||
|
||
All the available services will be shown in the Swagger UI. | ||
|
||
Swagger UI URL: [http:https://localhost:8595/swagger-ui.html]() | ||
|
||
![Swagger UI](images/swagger-ui.png) | ||
|
||
### 2. Install the Jenkins server | ||
|
||
Installing jenkins server is straight forward. Please refer to their official [documentation](https://www.jenkins.io/doc/book/installing/) | ||
for this. | ||
|
||
### 3. Install WSO2 API Manager | ||
|
||
Installing WSO2 API Manager is straight forward and please refer to this [documentation](https://apim.docs.wso2.com/en/latest/install-and-setup/install/installing-the-product/installing-the-product/) | ||
for more information on that. For this demonstration I'll be having two environments called Dev and Test but any number | ||
of environments can be there and the steps are pretty much the same. | ||
|
||
## Configurations | ||
|
||
##### API Project | ||
* For this demo, I have created an API called UserAPI and the API project can be found [here](/apim_artifacts/UserAPI) | ||
* Once this project is cloned, this can be deployed on your development API Manager server by simply running the apictl | ||
tool. The CTL tool can be downloaded and installed by following [this documentation.](https://apim.docs.wso2.com/en/next/learn/api-controller/getting-started-with-wso2-api-controller/) | ||
* Execute the below commands to deploy this API on your development server. If your devlopment server is not on the local machine, | ||
please change the URLs accordingly. | ||
|
||
* Add the dev environment : `apictl add-env -e dev --apim https://localhost:9443 --token https://localhost:8243/token` | ||
* Login to the dev environment : `apictl login dev -u admin -p admin -k` | ||
* Import the UserAPI to the dev environment : `apictl import-api -f APIM_CICD/apim_artifacts/UserAPI e dev -k --preserve-provider --update —verbose` | ||
|
||
* Now you can log into the dev environment and do any kind of modifications to the UserAPI. | ||
* If you want to export the API from the dev environment, the following commands can be used | ||
|
||
* Add the dev environment : `apictl add-env -e dev --apim https://localhost:9443 --token https://localhost:8243/token` | ||
* Login to the dev environment : `apictl login dev -u admin -p admin -k` | ||
* Export the UserAPI from the dev environment : `apictl export-api -n UserAPI -v v1 -e dev -k` | ||
|
||
#### Jenkins Server | ||
1. Login to the jenkins server. You might have to create a user if this is the first time. | ||
2. Install [npm and nodejs plugins](https://wiki.jenkins.io/display/JENKINS/NodeJS+Plugin) | ||
and [Newman](https://learning.getpostman.com/docs/postman/collection-runs/integration-with-jenkins/#installation) globally in your Jenkins server. | ||
![Jenkins nodejs and newman config](images/jenkins-nodejs-newman-config.png) | ||
Newman is used to run the tests I have created using PostMan. The test script can be found [here](apim_artifacts/test_script.postman_collection.json). | ||
3. Download and configure [WSO2 API Controller](https://wso2.com/api-management/tooling/) to the Jenkins server and the developer machines. | ||
![Jenkins apictl config](images/jenkins-apictl-config.png) | ||
Note that you need to add the environments properly to the API Controller in the Jenkins Server. You can add environments | ||
by either manually editing the `<USER_HOME>/.wso2apictl/main_config.yaml` file or by running the following CTL command. | ||
Don't forget that usually jenkins create a new user called *jenkins* and the environment should be added to that user or else | ||
jenkins server won't notice this. The same commands mentioned in the above topic can be used for this. | ||
4. Now we need to create a GitHub repository and later we are planning to push [apim_artifacts](apim_artifacts) folder to that repo. | ||
5. Once the repo is created, let's configure the webhook. This is how the jenkins server will get notified when ever there is a new commit. | ||
![Jenkins GitHub Webhook](images/webhook.png). | ||
Note that the url has to be passed here and if the Jenkins is deployed locally, then you can use [ngrol](https://ngrok.com/) | ||
to expose your localhost through internet. | ||
6. Let's commit the [apim_artifacts](apim_artifacts) to this newly created repo. | ||
7. Store the GitHub and APIM user credentials on Jenkins. Note that this can be done more securely using GitHub Apps. | ||
![GitHub Credentials](images/jenkins-credentials.png) | ||
8. Add the Jenkins pipeline configuration defined in [here](jenkinsfile). Don't forget to change the GitHub url accordingly. | ||
![Jenkins Pipeline](images/jenkins_pipeline.png) | ||
|
||
#### Trigger the pipeline | ||
* You can start the pipeline manually by clicking on the *Build Now* button and all the stages should be passed. | ||
* Now let's do a small change and commit it to the repo. Jenkins should pick that change via the webhook and the job should be started. | ||
![Jenkins Builds](images/jenkins-build-jobs.png) |
Empty file.
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
id: | ||
providerName: admin | ||
apiName: UserAPI | ||
version: v1 | ||
uuid: f4fa432b-db38-42b7-a96a-67ca6a8fa37b | ||
type: HTTP | ||
context: /users/v1 | ||
contextTemplate: /users/{version} | ||
tags: [] | ||
documents: [] | ||
lastUpdated: Jul 13, 2020 1:13:17 PM | ||
availableTiers: | ||
- | ||
name: Bronze | ||
displayName: Bronze | ||
description: Allows 1000 requests per minute | ||
requestsPerMin: 1000 | ||
requestCount: 1000 | ||
unitTime: 1 | ||
timeUnit: min | ||
tierPlan: FREE | ||
stopOnQuotaReached: true | ||
- | ||
name: Gold | ||
displayName: Gold | ||
description: Allows 5000 requests per minute | ||
requestsPerMin: 5000 | ||
requestCount: 5000 | ||
unitTime: 1 | ||
timeUnit: min | ||
tierPlan: FREE | ||
stopOnQuotaReached: true | ||
- | ||
name: Silver | ||
displayName: Silver | ||
description: Allows 2000 requests per minute | ||
requestsPerMin: 2000 | ||
requestCount: 2000 | ||
unitTime: 1 | ||
timeUnit: min | ||
tierPlan: FREE | ||
stopOnQuotaReached: true | ||
- | ||
name: Unlimited | ||
displayName: Unlimited | ||
description: Allows unlimited requests | ||
requestsPerMin: 2147483647 | ||
requestCount: 2147483647 | ||
unitTime: 0 | ||
timeUnit: ms | ||
tierPlan: FREE | ||
stopOnQuotaReached: true | ||
availableSubscriptionLevelPolicies: [] | ||
uriTemplates: [] | ||
apiHeaderChanged: false | ||
apiResourcePatternsChanged: false | ||
status: PUBLISHED | ||
visibility: public | ||
gatewayLabels: [] | ||
endpointSecured: false | ||
endpointAuthDigest: false | ||
transports: http,https | ||
advertiseOnly: false | ||
subscriptionAvailability: all_tenants | ||
corsConfiguration: | ||
corsConfigurationEnabled: false | ||
accessControlAllowOrigins: | ||
- '*' | ||
accessControlAllowCredentials: false | ||
accessControlAllowHeaders: | ||
- authorization | ||
- Access-Control-Allow-Origin | ||
- Content-Type | ||
- SOAPAction | ||
- apikey | ||
accessControlAllowMethods: | ||
- GET | ||
- PUT | ||
- POST | ||
- DELETE | ||
- PATCH | ||
- OPTIONS | ||
endpointConfig: '{"endpoint_type":"http","sandbox_endpoints":{"url":"http:\/\/3.19.209.74:8595\/api\/users"},"production_endpoints":{"url":"http:\/\/3.19.209.74:8595\/api\/users"}}' | ||
responseCache: Disabled | ||
cacheTimeout: 300 | ||
implementation: ENDPOINT | ||
authorizationHeader: Authorization | ||
scopes: [] | ||
isDefaultVersion: false | ||
isPublishedDefaultVersion: false | ||
environments: | ||
- Production and Sandbox | ||
createdTime: "1594626117090" | ||
additionalProperties: {} | ||
monetizationProperties: {} | ||
isMonetizationEnabled: false | ||
environmentList: | ||
- SANDBOX | ||
- PRODUCTION | ||
apiSecurity: oauth2,oauth_basic_auth_api_key_mandatory,api_key | ||
endpoints: [] | ||
enableSchemaValidation: false | ||
apiCategories: [] | ||
accessControl: all | ||
rating: 0.0 | ||
isLatest: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
openapi: 3.0.1 | ||
info: | ||
title: UserAPI | ||
version: v1 | ||
servers: | ||
- | ||
url: / | ||
security: | ||
- | ||
default: [] | ||
paths: | ||
/*: | ||
get: | ||
responses: | ||
200: | ||
description: OK | ||
security: | ||
- | ||
default: [] | ||
x-auth-type: Application & Application User | ||
x-throttling-tier: Unlimited | ||
x-wso2-application-security: | ||
security-types: | ||
- oauth2 | ||
- api_key | ||
optional: false | ||
put: | ||
responses: | ||
200: | ||
description: OK | ||
security: | ||
- | ||
default: [] | ||
x-auth-type: Application & Application User | ||
x-throttling-tier: Unlimited | ||
x-wso2-application-security: | ||
security-types: | ||
- oauth2 | ||
- api_key | ||
optional: false | ||
post: | ||
responses: | ||
200: | ||
description: OK | ||
security: | ||
- | ||
default: [] | ||
x-auth-type: Application & Application User | ||
x-throttling-tier: Unlimited | ||
x-wso2-application-security: | ||
security-types: | ||
- oauth2 | ||
- api_key | ||
optional: false | ||
delete: | ||
responses: | ||
200: | ||
description: OK | ||
security: | ||
- | ||
default: [] | ||
x-auth-type: Application & Application User | ||
x-throttling-tier: Unlimited | ||
x-wso2-application-security: | ||
security-types: | ||
- oauth2 | ||
- api_key | ||
optional: false | ||
components: | ||
securitySchemes: | ||
default: | ||
type: oauth2 | ||
flows: | ||
implicit: | ||
authorizationUrl: https://test.com | ||
scopes: {} | ||
x-wso2-auth-header: Authorization | ||
x-wso2-cors: | ||
corsConfigurationEnabled: false | ||
accessControlAllowOrigins: | ||
- '*' | ||
accessControlAllowCredentials: false | ||
accessControlAllowHeaders: | ||
- authorization | ||
- Access-Control-Allow-Origin | ||
- Content-Type | ||
- SOAPAction | ||
- apikey | ||
accessControlAllowMethods: | ||
- GET | ||
- PUT | ||
- POST | ||
- DELETE | ||
- PATCH | ||
- OPTIONS | ||
x-wso2-production-endpoints: | ||
urls: | ||
- http:https://3.19.209.74:8595/api/users | ||
type: http | ||
x-wso2-sandbox-endpoints: | ||
urls: | ||
- http:https://3.19.209.74:8595/api/users | ||
type: http | ||
x-wso2-basePath: /users/v1 | ||
x-wso2-transports: | ||
- http | ||
- https | ||
x-wso2-response-cache: | ||
enabled: false | ||
cacheTimeoutInSeconds: 300 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# WSO2 API Manager Project | ||
|
||
## Project structure | ||
|
||
```bash | ||
├── api_params.yaml | ||
├── Docs | ||
│ └── FileContents | ||
├── Image | ||
├── Meta-information | ||
│ ├── api.json | ||
│ └── swagger.json | ||
├── README.md | ||
└── Sequences | ||
├── fault-sequence | ||
├── in-sequence | ||
└── out-sequence | ||
``` | ||
|
||
## Deploy a minimal API | ||
|
||
To deploy a minimal API once project generated open Meta-information/api.yaml and edit | ||
|
||
- apiName : Must not include spaces (i.e. MyAPI) | ||
- version : A simple version string (i.e. v1.0.0) | ||
- context : Context of API (i.e. /MyAPI) | ||
|
||
`Meta-information/swagger.yaml` contains a default swagger generated by tool. | ||
Replace `Meta-information/swagger.yaml` **with your swagger file** (JSON also supported). | ||
|
||
Edit `api_params.yaml` and add your endpoint specific URLs there. | ||
|
||
import api as usual with | ||
`apictl import-api [directory path]` | ||
|
||
## Publishing API Project | ||
|
||
Change status field in `api.yaml` from `CREATED` to `PUBLISHED` and import it |
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
environments: | ||
- name: default | ||
endpoints: | ||
production: | ||
sandbox: |
Oops, something went wrong.