|
| 1 | + |
| 2 | +# Deploy infrastructure using GitHub Actions |
| 3 | + |
| 4 | +!!! info "Module Duration" |
| 5 | + 30 minutes |
| 6 | + |
| 7 | +Azure Devops pipeline is another great way to automate your workflow. In this section, we will create a Azure Devops Pipeline to |
| 8 | +deploy the infrastructure components of our application. |
| 9 | + |
| 10 | +The workshop repository contains a Azure Devops Pipeline yaml file that will be used to deploy the infrastructure |
| 11 | +components of our application. Follow the steps below to create a devops pipeline to deploy the |
| 12 | +infrastructure components of our application. |
| 13 | + |
| 14 | +### Fork the GitHub repository |
| 15 | + |
| 16 | +Start by forking the workshop repository to your GitHub account. Follow the steps below to fork the workshop: |
| 17 | + |
| 18 | +1. Navigate to the workshop repository at [:material-github: Azure/aca-dotnet-workshop](https://github.com/Azure/aca-dotnet-workshop){target=_blank} |
| 19 | +2. Click the **Fork** button in the top-right corner of the page. |
| 20 | +3. Select your GitHub account to fork the repository to. |
| 21 | +4. Wait for the repository to be forked. |
| 22 | + |
| 23 | +### Configure Service Connection for GitHub and Azure Subscription |
| 24 | + |
| 25 | +Before we start with creating pipeline, we need to configure service connection for GitHub and Azure Subscription. You can do this in either existing or new project. |
| 26 | + |
| 27 | +#### Create Service Connection for GitHub |
| 28 | + |
| 29 | +Provide access to the repository forked above by creating a service connection to GitHub. You create a new pipeline |
| 30 | +by first selecting a GitHub repository and then a YAML file in repository at path [.ado/infra-deploy.yml](https://raw.githubusercontent.com/Azure/aca-dotnet-workshop/main/.ado/infra-deploy.yml){target=_blank}. |
| 31 | + |
| 32 | +The repository in which the YAML file is present is called self repository. By default, this is the repository that your pipeline builds. |
| 33 | + |
| 34 | +There are three authentication types for granting Azure Pipelines access to your GitHub repositories while creating |
| 35 | +a pipeline. Follow guide at [this link](https://learn.microsoft.com/en-us/azure/devops/pipelines/repos/github?view=azure-devops&tabs=yaml#access-to-github-repositories){target=_blank} |
| 36 | +to create service connection for GitHub. |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | +#### Create Service Connection for Azure Subscription |
| 42 | + |
| 43 | +Create new service connection to your azure subscription by following steps at [this link](https://docs.microsoft.com/en-us/azure/devops/pipelines/library/service-endpoints?view=azure-devops&tabs=yaml#create-a-service-connection){target=_blank} |
| 44 | + |
| 45 | +!!! note |
| 46 | + Update the created service connection role to have **[User Access Administrator](https://learn.microsoft.com/en-us/azure/role-based-access-control/built-in-roles#user-access-administrator)** role. |
| 47 | + This is required for pipeline to be able to perform role assignments in the infrastructure components deployed. |
| 48 | + |
| 49 | +### Configure Variable group under Library |
| 50 | + |
| 51 | +Create a variable group named **AcaApp** under Library in your Azure Devops project. Make sure the pipeline has |
| 52 | +permissions to access the created variable group under **Pipeline permissions**. |
| 53 | + |
| 54 | +This variable group will be used to store below details: |
| 55 | + |
| 56 | +```bash |
| 57 | +# AZURE_SUBSCRIPTION: Name of the service connection created for Azure Subscription |
| 58 | +AZURE_SUBSCRIPTION=<service connection name> |
| 59 | + |
| 60 | +# LOCATION: Azure region where resources will be deployed |
| 61 | +LOCATION=<location> |
| 62 | + |
| 63 | +# RESOURCE_GROUP: Name of the resource group which will be created and resources will be deployed |
| 64 | +RESOURCE_GROUP=<resource group name> |
| 65 | + |
| 66 | +# (OPTIONAL)CONTAINER_REGISTRY_NAME: Unique name of the container registry which will be created and where images will be imported |
| 67 | +CONTAINER_REGISTRY_NAME=<container registry name> |
| 68 | +``` |
| 69 | + |
| 70 | +!!! note |
| 71 | + |
| 72 | + Repository variables `CONTAINER_REGISTRY_NAME` is only needed by pipeline, if you wish the images to be deployed from private ACR. |
| 73 | + |
| 74 | + You may chose to skip defining this variable and the pipeline will use the [public github container registry images](https://github.com/orgs/Azure/packages?repo_name=aca-dotnet-workshop) to deploy the images. |
| 75 | + |
| 76 | +### Trigger Azure Devops Pipeline |
| 77 | + |
| 78 | +With these steps completed, you are now ready to trigger the Pipeline. |
| 79 | + |
| 80 | +!!! success |
| 81 | + |
| 82 | + Your Pipeline should be triggered and the infrastructure components of our application should be deployed successfully. |
| 83 | + |
| 84 | +  |
| 85 | + |
| 86 | + |
| 87 | +??? info "Want to delete the resources deployed by the pipeline?" |
| 88 | + |
| 89 | + Trigger the pipeline again select **checkbox** option named **Should teardown infrastructure?**. |
| 90 | + |
| 91 | +  |
0 commit comments