Skip to content

Sample pipeline code for CI/CD pipelines in gopaddle using Azure DevOps

License

Notifications You must be signed in to change notification settings

gopaddle-io/azure-devops-pipeline

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 

Repository files navigation

Sample pipeline template for Azure DevOps

Sample pipeline template to be used with Azure DevOps to trigger an automated container build and a rolling update for applications managed by gopaddle.

Pre-requisite

As a pre-requisite, an application must be deployed in gopaddle. Below flow chart gives the step by step process to be followed before creating a Azure DevOps pipeline.

Since we are building a pipeline for an application deployed in gopaddle, we must first initialize and deploy an application in gopaddle before we move on to creating the pipeline in Azure DevOps.

  • Subscribe to gopaddle - If you do not have a gopaddle subscription yet, subscribe to the gopaddle portal
  • Provision K8s in gopaddle
  • Add a Container Registry - Add a Container registry to gopaddle, to push or pull Docker images
  • Clone the project locally - Clone the GitHub project to be containerized.
  • Initialize and deploy the project using gopaddle
    • Download and install gpctl - Now, from your local desktop, download and install gpctl command line utility.
    • Perform gpctl init - Auto-generate the Dockerfile and Kubernetes YAML, build docker images, and deploy the application.
    • capture the .gp file with the resource IDs - Once the application is onboarded using gopaddle, gpctl init creates a .gp file in the project folder which contains the apiToken, containerID, serviceID, applicationID, projectID, releaseID and the distributionID. Make a note of these IDs, as we will be using these in the Azure DevOps pipeline script.

Getting started

Create a pipeline in Azure DevOps.

  1. Select the GitHub repository and branch used while initializing the gopaddle application

  1. Select the starter pipeline config

  1. Grant the permission for branches to allow the access to the GitHub reposiory
  2. Once the pipeline is created, Azure DevOps creates a azure-pipelines.yml file in the project root folder in GitHub repository. Replace this default template with the contents from the azure-pipelines.yml from this sample template.
  3. Create secure variable to access the gopaddle API token by creating a varaible group by name gp-api-key under the Library option in Azure DevOps portal. Store the gopaddle API token under this group with the variable key as GP_API_TOKEN and the value as the API token from the gpctl init output.

  1. Edit the contents of the azure-pipelines.yml file and replace the IDs with the IDs gathered during the gpctl init process.

Pipeline Script explained

  • trigger: master Branch to be monitored for code commits. Any change that is committed to this branch will trigger the Azure DevOps pipeline.

  • pool

vmImage: ubuntu-latest

Build environment where the container build has to be triggered.

  • variables The set of variables used by the pipeline. The values of these variables are derived from the .gp file generated during the gptcl init process.
Variable Purpose
gp-api-token Variable group under Azure DevOps pipeline where the gopaddle API token is stored
containerID Container ID of the project onboarded in gopaddle
serviceID Service ID under which the container is added
applicationID ID of the application launched in gopaddle
projectID Project ID under which the resources are onboarded. If no project ID is specified during the gpctl init process, the default project will be assumed.
releaseID Release ID under which the container is onboarded. If no release ID is specified during the gpctl init process, the default release will be assumed.
distributionID Distribution ID under which the container image is built. If no distribution ID is specified during the gpctl init process, the default distribution will be assumed.
endPoint gopaddle access URL. If no endPoint is specified during the gpctl init process, the endpoint portal.gopaddle.io will be assumed by default. In case of gopaddle Enterprise Edition, this endpoint can configured to point to the on-premise gopaddle access URL
  • steps

Defines the different stages of the DevOps pipeline. The template has two steps:

  • Step-1: Leverages gopaddle APIs to initiate the Container build within gopaddle as soon as the code is committed. Below is the API request that is used to initiate a build in gopaddle.

API: https://$endPoint/gateway/v1/$(projectID)/build

Method: POST

Payload:

{
 "serviceID":"$(containerID)",
 "releaseID":"$(releaseID)",
 "distributionID":"$(distributionID)"
}

Once the build is triggered, the pipeline script polls for the build status and waits until the build completes. Below is the API call to get the build information based on build ID.

API: https://$endPoint/gateway/v1/$(projectID)/build/$buildid

Method: GET

  • Step-2 : Leverages gopaddle APIs to update the application managed by gopaddle. Below is the API request that is used to initiate a build in gopaddle.

API: https://$endPoint/gateway/v1/$(projectID)/application/$(applicationID)

Method: PUT

Payload:

    {
 "serviceGroups":[
    {
       "services":[
          {
             "id":"$(containerID)",
             "serviceVersion":"draft",
             "releaseConfig":{
                "buildID":"'""$buildid""'",
                "version":"'""$buildVersion""'"
             }
          }
       ],
       "id":"$(serviceID)",
       "name":"eshoponweb",
       "version":"draft",
       "description":"'""$commitMessage""'"
    }
 ],
 "deploymentTemplateVersion":"draft",
 "updateType":"buildUpdate"
}

Sequence of pipeline steps

Maintainers

This sample template is maintained by the gopaddle.io team.