github-actionscicdazure-appservice

Not able to deploy a modified version of git repo in Azure App Service


I created an azure open ai application and deployed it using the playground. This automatically created a web app and an app service. I found that the code of the application is at https://github.com/microsoft/sample-app-aoai-chatGPT

I want to make a change in the repo and deploy application from the modified repo. So I forked the repo and made change to file frontend-src-pages-layout-layout.tsx. I changed the text “Azure AI” to “Azure AI by me”. Then I disconnected the old repo and created a new connection (with option to use the existing workflow file)

enter image description here

I saw this message

enter image description here

Then I restarted the app. However, I don't see the change. The page still looks like original. I expected the Azure AI text on top left to be Azure AI by me.

enter image description here

What am I missing

update I went to actions in github and saw the message

enter image description here

I enabled workflow.

I didn't see any workflow getting executed

enter image description here

Then I made another change in layout.tsx and directly committed it to main branch. I am making changes directly in github using the edit button for the file.

I see that a workflow execution was attempted but failed.

enter image description here

enter image description here

It is asking for username. I don't know why though. I haven't set up ACR_USERNAME as I thought that because I am changing an existing app service code, i don't need to. Do I and how?

enter image description here

After fixing the ACR issue (thanks to Github workflow failing with error - Error: Error: Input required and not supplied: username and Azure Container Registry and Github actions - denied: requested access to the resource is denied) I was able to execute the workflow. I see that the change to pushed. However, I don't see the change in my app.

enter image description here

Not sure if it is relevant but in the web app deployment, I don't see any logs from the time the workflow was executed.

enter image description here

I thought maybe I need to redeploy but that is failing.

enter image description here

My .github/workflow file is .github/workflows/docker-image.yml.

name: Docker Image CI

on:
  push:
    branches:
    - main

jobs:

  build:

    runs-on: ubuntu-latest

    steps:
    - name: Azure Container Registry Login
      uses: Azure/docker-login@v1
      with:
        # Container registry username
        username: ${{ secrets.ACR_USERNAME }}
        # Container registry password
        password: ${{ secrets.ACR_PASSWORD }}
        # Container registry server url
        login-server: ${{ secrets.ACR_LOGIN_SERVER }}
        
    - uses: actions/checkout@v3
    - name: Build the Docker image
      run:         
        docker build . --file WebApp.Dockerfile --tag craistudiodemoresouce383718707273.azurecr.io/sample-app-aoai-chatgpt:$(date +'%Y-%m-%d')_$GITHUB_RUN_NUMBER;
        docker tag craistudiodemoresouce383718707273.azurecr.io/sample-app-aoai-chatgpt:$(date +'%Y-%m-%d')_$GITHUB_RUN_NUMBER craistudiodemoresouce383718707273.azurecr.io/sample-app-aoai-chatgpt:latest;
        docker push craistudiodemoresouce383718707273.azurecr.io/sample-app-aoai-chatgpt:$(date +'%Y-%m-%d')_$GITHUB_RUN_NUMBER;
        docker push craistudiodemoresouce383718707273.azurecr.io/sample-app-aoai-chatgpt:latest;

I have added the following section in the end

- name: Build and deploy Container App
      uses: azure/container-apps-deploy-action@v1
      with:
        appSourcePath: ${{ github.workspace }}/src
        acrName: craistudiodemoresouce383718707273
        containerAppName: careeradvisorbot
        resourceGroup: rg-aistudiodemoresouce

but I am now getting error

Run azure/container-apps-deploy-action@v1
Run CA_GH_ACTION_START_MILLISECONDS=$(date +%s%N | cut -b1-13)
Run az config set extension.use_dynamic_install=yes_without_prompt
WARNING: Command group 'config' is experimental and under development. Reference and support levels: https://aka.ms/CLI_refstatus
Run CA_GH_ACTION_ACR_ACCESS_TOKEN=$(az acr login --name *** --output json --expose-token | jq -r '.accessToken')
WARNING: Unable to get AAD authorization tokens with message: Please run 'az login' to setup account.
WARNING: Unable to get admin user credentials with message: Please run 'az login' to setup account.
ERROR: Unable to authenticate using AAD or admin login credentials. Please specify both username and password in non-interactive mode.
Error: Process completed with exit code 1.

I later changed workflow.yml to

- uses: azure/webapps-deploy@v2
      with:
        publish-profile: ${{ secrets.AZURE_PUBLISH_PROFILE }}

I saw that the workflow completed successfully

enter image description here

I see the following message in deployment centre

enter image description here

but when I restarted the app, I got error

enter image description here

I guess this is where I need service principal.


Solution

  • I believe you haven't actually executed the workflow. That is, you updated the build and deployment workflow by referencing your forked repo, but you haven't actually executed it.

    From your question I understand that you first made the changes in the forked repo, and then changed app service to point to the new repo. This wouldn't trigger the workflow.

    Because your workflow has a trigger when you push to main branch, you're going to need to make a change, commit it, and then push it to main.

    This should trigger the workflow and update your app.

    EDIT: Once you've correctly executed the basic workflow that builds your new updated docker container and stores it in your registry, you're going to need to actually deploy that to your WebApp. For this, I personally prefer to have a separate CD workflow, but for now, you can easily integrate this into your current workflow and work from there.

    You're going to want to head to the Azure Portal and then download your Publish Profile. This will provide you with a file; the contents of which you're going to want to copy.

    Then, you'll need to head to your repository in GitHub, click on Settings and then Secrets and variables --> Actions. Here, you'll create a New Repository Secret that you can name AZURE_PUBLISH_PROFILE, and where you'll paste the full contents of your Publish Profile from before.

    You are also going to need to follow the same steps as above to store your Azure Credentials as a variable named AZURE_CREDENTIALS. You can follow these instructions to do this.

    Now, you need to open up .github/workflows/{yourworkflow} in a code editor, and add the following:

    deployjob:
      runs-on: ubuntu-latest
      steps:
    
        - name: Log in to Azure
          uses: azure/login@v1
          with:
            creds: ${{ secrets.AZURE_CREDENTIALS }}
    
        - name: Build and deploy Container App
          uses: azure/container-apps-deploy-action@v1
          with:
            appSourcePath: ${{ github.workspace }}/src
            acrName: myregistry
            containerAppName: my-container-app
            resourceGroup: my-rg
    

    Make sure you replace acrName, containerAppName and resourceGroup values to match yours.