Skip to main content

Overview

This guide shows you how to automatically deploy your APIs to Apinizer using a modern CI/CD pipeline. The example scenario covers building Docker images with GitHub Actions, Kubernetes deployment with Jenkins, and API proxy management on Apinizer.

Technologies and Versions Used

Pipeline Flow

Architecture Overview

This integration scenario uses the following components:
  • GitHub Actions: Docker image build and versioning operations are handled on the GitHub side.
  • Jenkins: Orchestration and deployment management runs on your Jenkins server.
  • Kubernetes: Runs on your container orchestration cluster.
  • Apinizer: API Gateway and API proxy management is handled through your Apinizer instance.

1. GitHub Actions Workflow

On every push to the main branch, GitHub Actions automatically:
  • Creates a new semantic version
  • Builds a Docker image and pushes it to Docker Hub
  • Triggers the Jenkins pipeline

Workflow File

The workflow file must be located in your project’s GitHub repository. Create the following file path in your local development environment (IDE or text editor) and push it to your repository: .github/workflows/docker-build-push.yml

GitHub Secrets Configuration

Add the following secrets from Repository Settings > Secrets and Variables > Actions:

2. Jenkins Pipeline Configuration

The Jenkins pipeline performs the following stages:
  1. K8s Deploy: Deploys the new Docker image to Kubernetes
  2. Health Check: Verifies the API is running correctly
  3. Sync Apinizer API Proxy: Updates or creates the API Proxy
  4. Deploy to Apinizer: Deploys the proxy to the specified environment

Jenkinsfile

The Jenkins pipeline can be defined by creating a new Pipeline job through the Jenkins UI. You can use the following content in the Pipeline script field in the Jenkins UI. Jenkinsfile

Jenkins Credentials Configuration

Add the following credential from Manage Jenkins > Credentials:
For detailed information on creating an Apinizer API token, refer to the Token Retrieval Methods documentation.

3. Pipeline Stage Details

Stage 1: Kubernetes Deployment

This stage runs on the Jenkins server. The Docker image built by GitHub Actions is deployed to the Kubernetes cluster. The deployment is updated using the kubectl set image command and the rollout status is monitored.

Stage 2: Health Check

The health endpoint is checked to verify that the API was deployed successfully. This step is critical to ensure the API is running before deploying to Apinizer. The API_HEALTH_ENDPOINT variable specifies the health check endpoint of the application you are deploying. This address is specific to your application, for example:
If your application uses a different health check endpoint, update the API_HEALTH_ENDPOINT variable accordingly.

Stage 3: Apinizer API Proxy Synchronization

In this critical stage:
  1. Proxy Check: Verifies whether the relevant API Proxy exists
  2. Update or Create:
    • If proxy exists: Updates the OpenAPI spec (PUT request)
    • If proxy doesn’t exist: Creates a new proxy (POST request)

Updating a Proxy (PUT)

When updating an existing proxy, the OpenAPI specification is re-parsed using the reParse: true parameter:
For detailed information, refer to the Update API Proxy API reference.

Creating a New Proxy (POST)

When creating a new proxy, backend routing information is also defined:
For detailed information, refer to the Create API Proxy from URL API reference.
With the deploy: false parameter, the proxy is not automatically deployed. This ensures a controlled deployment in the next stage.

Stage 4: Deploy to Apinizer Environment

In the final stage, the updated or newly created proxy is deployed to the specified environment using Apinizer’s deployment API:
For detailed information, refer to the Deploy API Proxy API reference.

Configuration Parameters

Environment Variables

Key environment variables used in the pipeline:

Apinizer API Endpoints

Apinizer API endpoints used in this pipeline:
For detailed information about the Apinizer Management API, refer to the API Overview documentation.

Adapting the Pipeline for Your Own Use

This example scenario is designed for an API running on Kubernetes. To adapt it to your own infrastructure:
1

Deployment Mechanism

If you use a different orchestrator instead of Kubernetes or direct VM deployment, replace the K8s Deploy stage with your own deployment method.
2

Health Check

If your API uses a different health check mechanism, update the API_HEALTH_ENDPOINT variable with the relevant endpoint.
3

OpenAPI Spec

Make sure your API’s OpenAPI specification is available at an accessible URL. This URL must be reachable by Apinizer.
4

Environment

Specify the environment you want to use in Apinizer (dev, test, prod, etc.) in the APINIZER_ENVIRONMENT variable.
5

Security

Managing your credentials through Jenkins Credentials Manager is a more appropriate approach from a pipeline security standpoint.

Conclusion

This guide has demonstrated how to set up a fully automated CI/CD pipeline using GitHub Actions, Jenkins, and Apinizer. Every code change is automatically built and deployed to Apinizer. This approach minimizes manual operations, speeds up your deployment process, and reduces the likelihood of errors.