Coder Social home page Coder Social logo

apigee-cicd's Introduction

CICD Demo - Apigee API Management Platform - v2

This repository includes the instructions and pipeline definition for CI/CD using Jenkins, Apigee Lint, Apickli, Cucumber Reports, Slack & Apigee Maven Deploy plugin on Apigee.

Often the most difficult and confusing aspect of application development is figuring out how to build a common framework for creating/deploying new applications. Over time, development teams have started using tools like Maven to automate some of these functions. This repository uses various tools/plugins for deploying Apigee bundles to the Edge platform.

Pipeline

Flow

Introduction

On every pipeline execution, the code goes through the following steps:

  1. Develop an API Proxy in test environment Apigee Edge UI, Download the proxy and push to Github.
  2. In Jenkins, Apigee Proxy bundle is cloned from Github.
  3. Code Analysis is done using Apigee Lint.
  4. Any Javascript files from apiproxy directory goes through Unit Tests done using mocha.
  5. Code coverage is done by Istanbul/nyc and reports are generated by Cobertura.
  6. Using edge.json configurations is created/updated and a new revision is published in prod environment using Apigee Maven Build Plugin.
  7. The newly deployed prod environment goes through Integration tests using Apickli.
  8. Apickli produced Cucumber Reports are displayed in Jenkins.
  9. If the test FAILS, current revision is undeployed and a stable revision is re-deployed.
  10. Build Success/Fail notification along with Cucumber reports are sent to Slack Room.

Prerequisites

Demo Guide

  1. HR API - A simple API to perform CRUD operations on employee records. For backend I am using Firestore DB.
  2. Download HR-API.zip proxy bundle from this repo/bundles & deploy to test env or create an sample API Proxy.
  3. Download CiCd-Security.zip proxy bundle from this repo/bundles & deploy to both prod & test environments.
  4. Fork this repo & create a directory structure as per HR-API directory & place your apiproxy folder.
  5. I am using an Parameterzied Build to pass the Apigee username, password and base64encoded string.
  6. ApigeeLint will go through the apiproxy folder,
apigeelint -s HR-API/apiproxy/ -f codeframe.js

Apigeelint

  1. Unit test any custom code within the proxy like Javascript in our case. But it can be NodeJS as well.
npm test test/unit/*.js
npm run coverage test/unit/*.js

Mocha

Istanbul

  1. Using Cobertura Plugin in try-catch-finally block to generate reports in Jenkins.
cd coverage && cp cobertura-coverage.xml $WORKSPACE
step([$class: 'CoberturaPublisher', coberturaReportFile: 'cobertura-coverage.xml'])

Cobertura

  1. Build & Deploy happens through Apigee Maven Plugin (update pom and edge.json files with appropiate details),
mvn -f HR-API/pom.xml install -Pprod -Dusername=${apigeeUsername} -Dpassword=${apigeePassword} -Dapigee.config.options=update

Maven

  1. Integration tests happen through Apickli - Cucumber - Gherkin Tests,
cd $WORKSPACE/test/integration && npm install
cd $WORKSPACE/test/integration && npm test
  1. Cucumber Reports plugin in Jenkins will use the reports.json file to create HTML Reports & statistics.

Cucumber-Reports

Cucumber-Reports

  1. If Integration tests fail, then through a undeploy.sh shell script I am undoing Step 9. Through Jenkins Environment variable I am getting the current deployed revision and storing it as Stable revision. Within Shell Script I am using this value to re-deploy in case of Failure.
curl -X DELETE --header "Authorization: Basic $base64encoded" "https://api.enterprise.apigee.com/v1/organizations/$org_name/environments/$env_name/apis/$api_name/revisions/$rev_num/deployments"
curl -X DELETE --header "Authorization: Basic $base64encoded" "https://api.enterprise.apigee.com/v1/organizations/$org_name/apis/$api_name/revisions/$rev_num"
curl -X POST --header "Content-Type: application/x-www-form-urlencoded" --header "Authorization: Basic $base64encoded" "https://api.enterprise.apigee.com/v1/organizations/$org_name/environments/$env_name/apis/$api_name/revisions/$stable_revision/deployments"
  1. To send cucumber-reports to Slack I used cucumber-slack-notifier, but the pipeline cmd is not working as expected/documented. So for the time being I am running a separate FreeStyle project >> Build >> Send Cucumber Report to Slack and point it to the reports.json in this pipeline directory.
build job: 'cucumber-report'
  1. When Build Starts/Ends & At any step if a Failure occurs, a notification is sent to Slack Room along with cucumber reports.

Slack

Things to do in upcoming versions

  1. Update Developer Portal.
    • After successful Integration Test, we can add another Stage to Update Developer Portal Docs.
    • Currently we have plugin/apis for updating Apigee Drupal based portal.
    • We do not have any APIs for updating Apigee Integrated Developer Portal as of 14th July 2019.
  2. Add Performace/Load Tests after Integrated Tests
  3. Use Git Branches/Projects for dev >> uat >> prod environments and use Jenkins to Merge and Commit updates.
  4. Use OAS and use Apigee Management APIs to create and deploy a proxy through Pipeline.

References

  1. Apigee - maven-jenkins-ci-demo

LICENSE

See the MIT LICENSE file.

Older Version - v1

v1

apigee-cicd's People

Contributors

sidd-harth avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.