|
| 1 | +name: Configure Azure environment |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [labeled] |
| 6 | + |
| 7 | +env: |
| 8 | + PACKAGES_TOKEN: ${{secrets.PACKAGES_TOKEN}} |
| 9 | + AZURE_RESOURCE_GROUP: cd-with-actions |
| 10 | + AZURE_APP_PLAN: actions-ttt-deployment |
| 11 | + AZURE_LOCATION: '"Central US"' |
| 12 | + ################################################# |
| 13 | + ### USER PROVIDED VALUES ARE REQUIRED BELOW ### |
| 14 | + ################################################# |
| 15 | + ################################################# |
| 16 | + ### REPLACE USERNAME WITH GH USERNAME ### |
| 17 | + AZURE_WEBAPP_NAME: larsbj-ttt-app |
| 18 | + ################################################# |
| 19 | + |
| 20 | +jobs: |
| 21 | + setup-up-azure-resources: |
| 22 | + runs-on: ubuntu-latest |
| 23 | + |
| 24 | + if: contains(github.event.pull_request.labels.*.name, 'spin up environment') |
| 25 | + |
| 26 | + steps: |
| 27 | + - name: Checkout repository |
| 28 | + uses: actions/checkout@v2 |
| 29 | + |
| 30 | + - name: Azure login |
| 31 | + uses: azure/login@v1 |
| 32 | + with: |
| 33 | + creds: ${{ secrets.AZURE_CREDENTIALS }} |
| 34 | + |
| 35 | + - name: Create Azure resource group |
| 36 | + if: success() |
| 37 | + run: | |
| 38 | + az group create --location ${{env.AZURE_LOCATION}} --name ${{env.AZURE_RESOURCE_GROUP}} --subscription ${{secrets.AZURE_SUBSCRIPTION_ID}} |
| 39 | +
|
| 40 | + - name: Create Azure app service plan |
| 41 | + if: success() |
| 42 | + run: | |
| 43 | + az appservice plan create --resource-group ${{env.AZURE_RESOURCE_GROUP}} --name ${{env.AZURE_APP_PLAN}} --is-linux --sku F1 --subscription ${{secrets.AZURE_SUBSCRIPTION_ID}} |
| 44 | +
|
| 45 | + - name: Create webapp resource |
| 46 | + if: success() |
| 47 | + run: | |
| 48 | + az webapp create --resource-group ${{ env.AZURE_RESOURCE_GROUP }} --plan ${{ env.AZURE_APP_PLAN }} --name ${{ env.AZURE_WEBAPP_NAME }} --deployment-container-image-name nginx --subscription ${{secrets.AZURE_SUBSCRIPTION_ID}} |
| 49 | +
|
| 50 | + - name: Configure webapp to use GitHub Packages |
| 51 | + if: success() |
| 52 | + run: | |
| 53 | + az webapp config container set --docker-custom-image-name nginx --docker-registry-server-password ${{secrets.GITHUB_TOKEN}} --docker-registry-server-url https://docker.pkg.github.com --docker-registry-server-user ${{github.actor}} --name ${{ env.AZURE_WEBAPP_NAME }} --resource-group ${{ env.AZURE_RESOURCE_GROUP }} --subscription ${{secrets.AZURE_SUBSCRIPTION_ID}} |
| 54 | +
|
| 55 | + destroy-azure-resources: |
| 56 | + runs-on: ubuntu-latest |
| 57 | + |
| 58 | + if: contains(github.event.pull_request.labels.*.name, 'destroy environment') |
| 59 | + |
| 60 | + steps: |
| 61 | + - name: Checkout repository |
| 62 | + uses: actions/checkout@v2 |
| 63 | + |
| 64 | + - name: Azure login |
| 65 | + uses: azure/login@v1 |
| 66 | + with: |
| 67 | + creds: ${{ secrets.AZURE_CREDENTIALS }} |
| 68 | + |
| 69 | + - name: Destroy Azure environment |
| 70 | + if: success() |
| 71 | + run: | |
| 72 | + az group delete --name ${{env.AZURE_RESOURCE_GROUP}} --subscription ${{secrets.AZURE_SUBSCRIPTION_ID}} --yes |
0 commit comments