This example demonstrate a sample CI/CD pipeline for API Management using WSO2 API Management solution combined with Travis CI and Newman.
Check out the Travis build here to understand pipeline further.
-
Sign up to WSO2 API Cloud at https://wso2.com/api-management/cloud/
-
Upon signup, you will have following details with you.
Username - [email protected]
Password - xxx
Organization - DevMyOrg
-
Login to WSO2 Cloud and create another organization. Each environment is represented as an organization. For example, you will have DevMyOrg and StagingMyOrg organizations. You can find instruction on creating new organization here.
-
Fork this git repository.
-
Configure Dev environment.
-
Update DevEnvironment/backendService.properites file to set the correct git repository path. DEPLOYABLE_ARTIFACT_PATH=/home/travis/build/YourGitHubOrganizationName/API-Management-CI-CD-Example/BackendServiceImpl/Hello-Service/target
-
Update DevEnvironment/Development.postman_environment.json to set your organization name.
{ "enabled": true, "key": "tenantDomain", "value": "**YourWSO2CloudDevOrganizationKey**", "type": "text" } { "enabled": true, "key": "backendAPIEndpoint", "value": "https://<**YourWSO2CloudDevOrganizationKey**>-helloservice-1-0-0.wso2apps.com", "type": "text" }
-
-
Configure Staging environment.
-
Update StagingEnvironment/backendService.properites file to set the correct git repository path. DEPLOYABLE_ARTIFACT_PATH=/home/travis/build/YourGitHubOrganizationName/API-Management-CI-CD-Example/BackendServiceImpl/Hello-Service/target
-
Update StagingEnvironment/Staging.postman_environment.json to set your organization name.
{ "enabled": true, "key": "tenantDomain", "value": "YourWSO2CloudStagingOrganizationKey", "type": "text" } { "enabled": true, "key": "backendAPIEndpoint", "value": "https://<YourWSO2CloudStagingOrganizationKey>-helloservice-1-0-0.wso2apps.com", "type": "text" }
-
-
Commit and push above changes to git repository.
-
Configure Travis
-
Go to https://travis-ci.org/ and sign in with Github.
-
Allow permissions to let travis to access your forked repository.
-
Go to your profile and select the GitHub account and the forked repository to enable building your repository.
-
Add following environment variables from More Options -> Settings. Below credentials are the credentials you use to login to WSO2 Cloud.
devclouduser=[email protected]@DevMyOrg
devclouduserpass=xxx
stagingclouduser=[email protected]@StagingMyOrg
stagingclouduserpass=xxx
-
If the build is not started yet, commit a minor change to your git repository to start it.
-
That is it. Now you can refer the build log to understand the execution flow. Note that this is a very simple .travis.yml configuration and you may use advanced features of travis to configure different states etc.
Once you have successfully completed the above tasks, login to WSO2 API Cloud to view the APIs published as well as to WSO2 Integration Cloud to view the micro service deployed.
By now, you have successfully deployed an micro service and exposed it as a API in WSO2 Cloud. Let’s consider updating the micro service and propagating those changes to Dev, Staging environments to see your changes are getting reflected correctly.
-
Modify the source of BackendServiceImpl/Hello-Service/src/main/java/org/example/service/HelloService.java to include additional resource paths. You can refer to WSO2 Microservices Framework for Java(MSF4J) to learn more about microservices.
-
Update the swagger file at DeployAPI/swagger.json. Note that you need to have info section in swagger file.
-
Update the postman script at TestAPI/WSO2_API_STORE_TESTS.postman_collection.json to reflect your changes.
-
Commit and push all above changes and monitor the travis build.