The continuous integration and continuous deployment (CI/CD) enables developers to deliver application changes frequently and reliably without error. Changes made to the applications in one environment can be automatically compiled and deployed to another environment in a seamless manner.
- CI establishes a consistent and automated way to build, package, and test applications.
- CD picks up where CI ends by automating the delivery of applications to selected infrastructure environments.
The following guide explains how API projects created in the Development environment can be moved to production and deploy it automatically. For this CICD, we will be using GIT as source control and Jenkins to configure the CICD pipeline. We will be having a central Git repository which will store the API projects. Once the API projects are created in the dev environment, the user will commit the projects to the central git repository. Jenkins will detect the change in the GIT repository and execute the commands in the CICD pipeline to fetch the projects, save them in the production environment and deploy them.
- Creating a central repository in Github
- Setting up the Jenkins Machine
- Configuring Jenkins
- Creating a new Jenkins Job
- Configuring Git in Jenkins machine by creating a local Git repository
- Making changes in the local repository and deploying it to the central repository
- Testing the deployment
- Jenkins Flow
- Build Script
Creating a central repository in Github
Open github using the URL www.github.com and click the New button on the left navigation panel to create a new repository In Github for the developer to push the flows from the development machine.
Provide an appropriate name for the repository in the Repository name text box and click the Create repository button.
Setting up the Jenkins Machine
Install the following on the Jenkins system:
- JENKINS
- GIT
- CURL
Configuring Jenkins
- Install HTTP Plugins on JENKINS dashboard (localhost:8080) and restart JENKINS server.
Go to Jenkins Dashboard >> Manage Jenkins >> Global Tool Configuration.
- APPLY and then SAVE.
Creating a new Jenkins Job
To automate the deployment process, create a project in the Jenkins account.
- Open the Jenkins account and provide a name for the jenkins project and click OK.
- Click the General tab and add a description.
- Click the Source Code Management tab and provide the Repository URL under the Git option.
- Click the Build Triggers tab, select the Poll SCM option and specify a time interval (every minute or every hour) the Schedule text area.
In the Build script choose the script type (Batch or Linux shell) and accordingly put the contents of the CI-CD script present in <FIORANO_HOME>/esb/samples/scripts. You may want to modify it according to your requirements. You can write a sample script of your own. Here is an example of a bash script:
Configure other features like post build actions based on your requirements.
Configuring Git in Jenkins machine by creating a local Git repository
Clone github repository to the system in which Jenkins is installed by providing the path in the Jenkins pipeline shell script:
Clone the local apiproject repository with Github (/test_jenkins/fiorano-api/apiprojects/) using the command as below:
Making changes in the local repository and deploying it to the central repository
- Edit the apiproject in one of the following ways and save it:
- from the dashboard.
- change the apiproject by opening file /test_jenkins/fiorano-api/apiprojects/testgit/1.0/policies/bmp/Development.xml and edit the payload tag.
- Commit the changes to the central repository.
- Push to apply the changes in the central repository.
Testing the deployment
To check if the change is automatically deployed, open the apiproject URL below in the browser:
http://192.168.2.134:1860/testgit/1.0/
Jenkins Flow
- Detect any change in the GIT repository.
- Clone the repository in the workspace path specified in the script.
- Zip the directories (API Projects / Event Processes) inside it.
- Undeploy/ stop the API Projects / Event Processes if running.
- Import the zipped contents in step 3.
- Deploy/ start the API Projects / Event Processes.
- If any API Project / Event Process is deleted from the GIT repository, then after step 4, invoke the "delete call".
Build Script
- The script (CI-CD.bat and CI-CD.sh) are present inside <FIORANO_HOME>/esb/samples/scripts.
- Provide WORKSPACE_PATH, CURL_PATH, REPO_NAME and github link to be cloned till .git.
- Sample CI/CD scripts across all platforms are provided to automate the deployment of Event Processes. In order to do the same for APIProjects, simply provide the correct CURLs.
- The scripts are created and tested for Linux and Windows. In order to zip the contents in Windows, we are using Powershell Compress-Archive. You may change it accordingly.