|
| 1 | +--- |
| 2 | +title: "Self Host on Azure" |
| 3 | +--- |
| 4 | + |
| 5 | +This guide will show you how to set up digger orchestrator on azure and setup your github workflow to trigger workflow on azure\! This guide assumes that you are using github actions for CI. Lets get started |
| 6 | + |
| 7 | +# Installing the orchestrator |
| 8 | + |
| 9 | +The easiest way to install the orchestrator is via helmchart in kubernetes. The deployed service needs to be able to listen to webhooks from github for using github actions |
| 10 | + |
| 11 | +## Install the helm chart |
| 12 | + |
| 13 | +Install the `digger-backend` helm chart from [**https://diggerhq.github.io/helm-charts/**](https://diggerhq.github.io/helm-charts/**), leaving empty all the data related to the GitHub App. You can also use the postgres database defined within the helmchart or define your own. Here’s a good starter set for my-values.yml: |
| 14 | + |
| 15 | +``` |
| 16 | +digger: |
| 17 | + image: |
| 18 | + repository: registry.digger.dev/diggerhq/digger_backend |
| 19 | + tag: v0.6.101 |
| 20 | + service: |
| 21 | + type: NodePort |
| 22 | + port: 3000 |
| 23 | + ingress: |
| 24 | + enabled: true |
| 25 | + host: mo-digger-test.ngrok.app |
| 26 | +
|
| 27 | + secret: |
| 28 | + useExistingSecret: false |
| 29 | + existingSecretName: "" |
| 30 | +
|
| 31 | + httpBasicAuthUsername: "admin" |
| 32 | + httpBasicAuthPassword: "abc123" |
| 33 | + bearerAuthToken: "salkfjadslkfj" # You should generate |
| 34 | + hostname: "<https://mo-digger-test.ngrok.app>" |
| 35 | + githubOrg: "diggerhq" # replace with org for digger |
| 36 | + githubAppID: "" |
| 37 | + githubAppClientID: "" |
| 38 | + githubAppClientSecret: "" |
| 39 | + githubAppKeyFile: "" #base64 encoded file |
| 40 | + githubWebhookSecret: "" |
| 41 | +
|
| 42 | +postgres: |
| 43 | + enabled: true |
| 44 | + secret: |
| 45 | + useExistingSecret: false |
| 46 | +``` |
| 47 | + |
| 48 | +you can save this file in a file like `mydigger.yml` and run the following helm commands to install it in your k8s cluster: |
| 49 | + |
| 50 | +``` |
| 51 | +$ helm repo add digger <https://diggerhq.github.io/helm-charts/> |
| 52 | +$ helm repo update |
| 53 | +$ helm install mydigger digger/digger-backend -f mydigger.yml |
| 54 | +``` |
| 55 | + |
| 56 | +This will be: using the latest tag as of this guide v0.6.101. It will also use a NodePort, you can use Loadbalancer or ClusterIP instead if relevant. It will enable http basic auth for the service, make sure to change the password\! It will also launch a postgres instance as a continaer for your quick test. In prod we advice launching a managed postgres instance for persistence. |
| 57 | + |
| 58 | +If all goes well you will see this fancy welcome screen when you visit the endpoint |
| 59 | + |
| 60 | + |
| 61 | + |
| 62 | +Now you can visit /github/setup endpoint and you will be greeted with this setup wizard for creation of a digger github app with the right settings |
| 63 | + |
| 64 | + |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | +After successful installation you will see all the github credentials in the redirect including ID, webhook secret, private key and so on |
| 69 | + |
| 70 | + |
| 71 | + |
| 72 | +Now we need to update the values from mydigger.yml above for these secrets: |
| 73 | + |
| 74 | +``` |
| 75 | + githubAppID: "add" |
| 76 | + githubAppClientID: "add" |
| 77 | + githubAppClientSecret: "add" |
| 78 | + githubAppKeyFile: "add" |
| 79 | + githubWebhookSecret: "add" |
| 80 | +``` |
| 81 | + |
| 82 | +Next is to update the helmchart: |
| 83 | + |
| 84 | +``` |
| 85 | +$ helm upgrade mydigger digger/digger-backend -f digger.yml |
| 86 | +``` |
| 87 | + |
| 88 | +Now we can install the newly created github app into the org and if all goes well we should see a succesful installation (pick the test repo where you have terraform in)\! |
| 89 | + |
| 90 | + |
| 91 | + |
| 92 | +Perfect, with all these steps we are finally ready to create the digger configuration in the repo and perform our first PR deployment to azure\! |
| 93 | + |
| 94 | +# Configuring Azure terraform repo |
| 95 | + |
| 96 | +## Configure OIDC credentials for actions |
| 97 | + |
| 98 | +We can configure OIDC access using a registration app and subscription ID access. |
| 99 | + |
| 100 | +To get these Azure OIDC authentication values, you'll need to set up an Azure App Registration and gather the required identifiers. Here's how to obtain each value: |
| 101 | + |
| 102 | +## Azure Client ID |
| 103 | + |
| 104 | +1. Go to the Azure Portal ([portal.azure.com](http://portal.azure.com)) |
| 105 | +2. Navigate to **Azure Active Directory** \> **App registrations** |
| 106 | +3. Create a new app registration or select an existing one |
| 107 | +4. On the app's **Overview** page, copy the **Application (client) ID** |
| 108 | + |
| 109 | +## Azure Tenant ID |
| 110 | + |
| 111 | +1. In the same app registration's **Overview** page, copy the **Directory (tenant) ID** |
| 112 | +2. Alternatively, go to **Azure Active Directory** \> **Overview** and find the **Tenant ID** |
| 113 | + |
| 114 | +## Azure Subscription ID |
| 115 | + |
| 116 | +1. Go to **Subscriptions** in the Azure Portal |
| 117 | +2. Select the subscription you want to use |
| 118 | +3. Copy the **Subscription ID** from the overview page |
| 119 | + |
| 120 | +## Setting up for GitHub Actions OIDC |
| 121 | + |
| 122 | +For GitHub Actions with OIDC (which is likely what you're setting up), you'll also need to: |
| 123 | + |
| 124 | +1. **Configure the App Registration for OIDC:** |
| 125 | + - In your app registration, go to **Certificates & secrets** |
| 126 | + - Under **Federated credentials**, add a new credential |
| 127 | + - Choose **GitHub Actions deploying Azure resources** |
| 128 | + - Set the organization, repository, and environment/branch details |
| 129 | +2. **Add secrets to your GitHub repository:** |
| 130 | + - Go to your GitHub repo \> **Settings** \> **Secrets and variables** \> **Actions** |
| 131 | + - Add these as repository secrets: |
| 132 | + - `AZURE_CLIENT_ID` |
| 133 | + - `AZURE_TENANT_ID` |
| 134 | + - `AZURE_SUBSCRIPTION_ID` |
| 135 | + |
| 136 | +## Configure Github workflow: |
| 137 | + |
| 138 | +create this github workflow in your repository under `.github/workflow/digger_workflow.yml` |
| 139 | + |
| 140 | +``` |
| 141 | +name: Digger Workflow |
| 142 | +
|
| 143 | +on: |
| 144 | + workflow_dispatch: |
| 145 | + inputs: |
| 146 | + spec: |
| 147 | + required: true |
| 148 | + run_name: |
| 149 | + required: false |
| 150 | +
|
| 151 | +run-name: '${{inputs.run_name}}' |
| 152 | +
|
| 153 | +jobs: |
| 154 | + digger-job: |
| 155 | + runs-on: ubuntu-latest |
| 156 | + permissions: |
| 157 | + contents: write # required to merge PRs |
| 158 | + actions: write # required for plan persistence |
| 159 | + id-token: write # required for workload-identity-federation |
| 160 | + pull-requests: write # required to post PR comments |
| 161 | + issues: read # required to check if PR number is an issue or not |
| 162 | + statuses: write # required to validate combined PR status |
| 163 | +
|
| 164 | + steps: |
| 165 | + - uses: actions/checkout@v4 |
| 166 | + - name: ${{ fromJSON(github.event.inputs.spec).job_id }} |
| 167 | + run: echo "job id ${{ fromJSON(github.event.inputs.spec).job_id }}" |
| 168 | + - uses: diggerhq/digger@vLatest |
| 169 | + with: |
| 170 | + digger-spec: ${{ inputs.spec }} |
| 171 | + setup-azure: true |
| 172 | + azure-client-id: ${{ secrets.AZURE_CLIENT_ID }} |
| 173 | + azure-tenant-id: ${{ secrets.AZURE_TENANT_ID }} |
| 174 | + azure-subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} |
| 175 | + setup-terraform: true |
| 176 | + env: |
| 177 | + GITHUB_CONTEXT: ${{ toJson(github) }} |
| 178 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 179 | + ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} |
| 180 | + ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} |
| 181 | + ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} |
| 182 | +``` |
| 183 | + |
| 184 | +Create a digger.yml in the root of the repository with one project as follows: |
| 185 | + |
| 186 | +``` |
| 187 | +projects: |
| 188 | + - name: myapp-dev-eastus |
| 189 | + dir: path/to/terraform/dir |
| 190 | +``` |
| 191 | + |
| 192 | +Here is some some sample terraform for you to try: |
| 193 | + |
| 194 | +``` |
| 195 | +provider "azurerm" { |
| 196 | + features {} |
| 197 | +} |
| 198 | +
|
| 199 | +resource "azurerm_resource_group" "rg" { |
| 200 | + name = "rg-myapp-dev-eastus" |
| 201 | + location = "eastus" |
| 202 | +} |
| 203 | +
|
| 204 | +resource "azurerm_storage_account" "storage" { |
| 205 | + name = "mystorageaccount" |
| 206 | + resource_group_name = azurerm_resource_group.rg.name |
| 207 | + location = azurerm_resource_group.rg.location |
| 208 | + account_tier = "Standard" |
| 209 | + account_replication_type = "LRS" |
| 210 | +} |
| 211 | +
|
| 212 | +resource "azurerm_storage_container" "container" { |
| 213 | + name = "mycontainer" |
| 214 | + storage_account_name = azurerm_storage_account.storage.name |
| 215 | + container_access_type = "private" |
| 216 | +} |
| 217 | +
|
| 218 | +``` |
| 219 | + |
| 220 | +you can commit that to main, and after that you can create a pull request to see digger start planning your changes: |
| 221 | + |
| 222 | + |
| 223 | + |
| 224 | +Excellent\! finally you can comment “digger apply” to apply the changes, congratulations you have setup digger successfully for azure\! This include PR level locks, planning on PR and commenting to apply. |
0 commit comments