Skip to content

Latest commit

 

History

History
86 lines (49 loc) · 4.34 KB

README.md

File metadata and controls

86 lines (49 loc) · 4.34 KB

CI/CD

CI/CD is demonstrated using Jenkins and Tyk Sync. These provide an automated way of pushing API Definitions and Policies to different Tyk environments.

Setup

This feature depends on the Tyk Environment 2 deployment, so the two must be deployed together. The tyk2 parameter should be provided before the cicd parameter, as the the CI/CD deployment requires some information from the Tyk Environment 2 deployment:

./up.sh tyk2 cicd

The bootstrap process installs the necessary plugins, adds a job and imports environment credentials into Jenkins. It also installs Gitea and restores a 'tyk-data' repo which Jenkins will use to push deploy Tyk configuration across environments.

⚠️ The CICD bootstrap process can take a long time to complete the first time it is run. This is due to the having the download the Jenkins plugins. These are then cached locally to speed up the process for subsequent deployments.

Usage

After the bootstrap process is complete, the CI/CD functionality can be demonstrated.

Demo steps

1. Check that Tyk Environment 2 has no APIs or Policies

Log into the Tyk environment 2 Dashboard (using credentials shown in bootstrap output, and a private browser session to avoid invalidating your session cookie for the default Dashboard). The Dashboard will not contain any data, so there will be no APIs or Policies shown.

Also, because there are no APIs available, the Tyk environment 2 Gateway will return 404 responses.

In the 'tyk-data' repo on Gitea, you will see that no Tyk data is present.

In the 'Tyk APIs and Policies' job in Jenkins, you will see that the job has run, but nothing has happened because no Tyk data is present in the repository.

2. Extract API and Policy definitions from Environment 1 using Tyk Sync

Run the dump-tyk.sh script:

./deployments/cicd/scripts/dump-tyk.sh

This script uses Tyk Sync to extract the API and Policy definitions, and write them to the tyk-data git repository directory. This data is then ready to be added, committed and pushed to Gitea, so it can then be consumed by Jenkins.

The tyk-data local repository directory is /tmp/tyk-demo/tyk-data.

3. Push updates to the repository

Run the push-repo-tyk-data.sh script:

./deployments/cicd/scripts/push-repo-tyk-data.sh

This will add, commit and push all the changes to the Gitea server.

Check the 'tyk-data' repo on Gitea. You will see that the Tyk data is now present, which means that Jenkins will be able to process it.

4. Run the Jenkins job to push the data into Tyk Environment 2

Run a build for the 'Tyk APIs and Policies' job in Jenkins.

Now that Tyk data is present, Jenkins will use Tyk Sync to push the APIs and Policies into Tyk Environment 2.

5. Check that Tyk Environment 2 has APIs and Policies

In the Tyk environment 2 Dashboard, the API and Policy definitions will now be available.

The Tyk environment 2 Gateway will have processed the newly imported data, and will now be able to process API requests.

Rerunning the synchronisation process

To further demonstrate this process you can essentially rerun the demo steps, but change the data in Tyk environment 1 first:

  1. Change some API configuration in the Tyk environment 1 Dashboard
  2. Run the dump-tyk.sh script
  3. Run the push-repo-tyk-data.sh script
  4. Run the Jenkins job
  5. Check that the data has updated in the Tyk environment 2 Dashboard

Changing Gitea configuration

Gitea's configuration is restored using a Gitea archive file during the bootstrap process. This is generated by Gitea and contains its configuration and repository data.

The Gitea archive is stored in this repo as deployments/cicd/volumes/gitea/gitea-dump.zip. It can be updated by using the deployments/cicd/scripts/dump-gitea.sh, which will run the necessary command within the Gitea container and copy the resulting archive to overwrite the file in this repo. This updated file can then be committed.