|
| 1 | +# Continuos Integration and Continuos Deployment using Azure DevOps |
| 2 | + |
| 3 | +The following instructions demonstrate how to deploy the contents of this example repository using Azure DevOps Repos and Azure DevOps Pipelines. |
| 4 | + |
| 5 | +## Pre-reqs |
| 6 | + |
| 7 | +To execute this solution you will need: |
| 8 | + |
| 9 | +- Azure DevOps Account |
| 10 | +- An Azure DevOps Repo configured ([how to configure an Azure DevOps Repo](https://docs.microsoft.com/en-us/azure/devops/repos/get-started/sign-up-invite-teammates?view=azure-devops)) |
| 11 | +- Three API Management deployed (DEV, QA and PROD) ([how to deploy a Create a new Azure API Management service instance](https://docs.microsoft.com/en-us/azure/api-management/get-started-create-service-instance)) |
| 12 | +- Some API(s) on your API Management ([Add an API manually](https://docs.microsoft.com/en-us/azure/api-management/add-api-manually)) |
| 13 | + |
| 14 | +## Architecture |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | +This is one example of how to use Azure DevOps Repo and Azure DevOps Pipelines to enable a Continuous Integration and Continuous Deployment (CI/CD) for API\'s on an Azure API Management Service. There're other ways to do this, but this is a \"Keep it Simple\" to help you start.(Planning to have another version using Github and Github Actions soon). |
| 19 | + |
| 20 | +This is our Development API management. In general, developers will create their API\'s in one instance of APIM to test it. |
| 21 | + |
| 22 | +Create your API's on API Management Development environment. ([How to create API's on API Management](https://docs.microsoft.com/en-us/azure/api-management/import-and-publish)) |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | +## APIM DevOps Toolkit |
| 27 | + |
| 28 | +**Running the Extractor** |
| 29 | + |
| 30 | +After a developer creates and tests APIs in API management, it is time to extract those APIs using this DevOps Resource Kit. |
| 31 | + |
| 32 | +Below are the steps to run the extractor from source code: |
| 33 | + |
| 34 | +- Clone this repository and navigate to {path\_to\_folder}/src/APIM\_ARMTemplate/apimtemplate |
| 35 | +- Restore its packages using |
| 36 | + |
| 37 | +``` |
| 38 | +dotnet restore |
| 39 | +``` |
| 40 | + |
| 41 | +- Make sure you have signed in using Azure CLI and have switched to the subscription containing the API Management instance from which the configurations will be extracted. |
| 42 | + |
| 43 | +``` |
| 44 | +
|
| 45 | +az login |
| 46 | +
|
| 47 | +az account set \--subscription \<subscription\_id\> |
| 48 | +
|
| 49 | +``` |
| 50 | + |
| 51 | +**Extractor Arguments** |
| 52 | + |
| 53 | +You have two choices when specifying your settings: |
| 54 | + |
| 55 | +1\. By using a json file with key-values where the keys matches the table below. Use the \`extractorConfig\` argument: |
| 56 | + |
| 57 | +\`extract \--extractorConfig c:/temp/extractSettings.json\`. [See more examples.](#extractorParameterFileExamples) |
| 58 | + |
| 59 | +2\. Pass the arguments on the command line. For instance \`extract \--sourceApimName my-feature-apim \--destinationApimName company-stable-apim \--resourceGroup my-feature-rg \--fileFolder c:\\temp\\apim-extract \--apiName MyFeatureV1Api\`. |
| 60 | + |
| 61 | +For this example, we will only use the option \#2 |
| 62 | + |
| 63 | +So, run the application with: |
| 64 | + |
| 65 | +``` |
| 66 | +
|
| 67 | +dotnet run extract --sourceApimName <DEV-APIM-NAME> --destinationApimName <DESTINATION-APIM-NAME> --resourceGroup <RESOURCE-GROUP-NAME> --fileFolder c:\\temp\\apim-extract. |
| 68 | +
|
| 69 | +``` |
| 70 | + |
| 71 | +Where: |
| 72 | + |
| 73 | +**DEV-APIM-NAME:** API Management where you created your API |
| 74 | + |
| 75 | +**DESTINATION-APIM-NAME:** It\'s just a convention to set the DESTINATION-API-NAME in front of the generated files. |
| 76 | + |
| 77 | +**RESOURCE-GROUP-NAME:** Resource group where the DEV-APIM-NAME is hosted. |
| 78 | + |
| 79 | +***For more information on how to run the application and parameters, [go to this page](https://github.com/Azure/azure-api-management-devops-resource-kit/blob/master/src/APIM_ARMTemplate/README.md#extractor).*** |
| 80 | + |
| 81 | +After executing the command above, you will see something similar to this: |
| 82 | + |
| 83 | + |
| 85 | + |
| 86 | +Then you see the json files extracted: |
| 87 | + |
| 88 | + |
| 90 | + |
| 91 | +Now, push them to your Azure DevOps Repo |
| 92 | + |
| 93 | +``` |
| 94 | +git push |
| 95 | +``` |
| 96 | + |
| 97 | +# Build Pipeline |
| 98 | + |
| 99 | +We will use a **Build Pipeline** to pull the extracted files from a repo and put it on Azure DevOps Artefacts Folder. |
| 100 | + |
| 101 | +1 - Add these tasks to your build: |
| 102 | +- Get Sources |
| 103 | +- Copy Publish Artifacts |
| 104 | + |
| 105 | +2 - Configure the fields as show bellow: |
| 106 | + |
| 107 | + |
| 109 | + |
| 110 | + |
| 112 | + |
| 113 | +# Release Pipeline |
| 114 | + |
| 115 | +You can use [this](https://docs.microsoft.com/en-us/azure/devops/pipelines/release/?view=azure-devops) document as a reference on how to create a release pipeline. |
| 116 | + |
| 117 | +1 - Add an [**Azure Deployment tasks**](https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-resource-group-deployment?view=azure-devops) for each file generated by extractor, following the order: |
| 118 | + |
| 119 | +``` |
| 120 | +- Products.template.json |
| 121 | +- Tags.template.json |
| 122 | +- namedValues.template.json |
| 123 | +- apis.template.json |
| 124 | +- globalServicePolice.template.json |
| 125 | +``` |
| 126 | + |
| 127 | +2 - Set "Override template parameters" field with "-ApimServiceName \<QA-APIM-NAME>\" |
| 128 | + |
| 129 | +3 - Set set [Deployment mode to Incremental](https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/deployment-tutorial-pipeline#create-a-devops-project) |
| 130 | + |
| 131 | + |
| 132 | + |
| 133 | +When you finish the steps above, you will see something like this: |
| 134 | + |
| 135 | + |
| 136 | + |
| 137 | +Clone your QA environment and update the **Resource Group** and **ApimServiceName** value on "Override template parameters" field to reflect your "production" APIM. |
| 138 | + |
| 139 | + |
| 140 | + |
| 141 | +Now you will see your Release Pipeline like this: |
| 142 | + |
| 143 | + |
| 144 | + |
| 145 | +By using a combination of manual deployment approvals, gates, and manual intervention within a release pipeline in Azure Pipelines, you can quickly and easily configure a release pipeline with all the control and auditing capabilities you require for your DevOps CI/CD processes. You will find more information on this [link](https://docs.microsoft.com/en-us/azure/devops/pipelines/release/deploy-using-approvals?view=azure-devops). |
0 commit comments