How to deploy blazor server Web App using sourcecontrols resource in bicep?

Siegfried Heintze 1,326 Reputation points

I'm frustrated with the documentation on source controls ... There are some bicep examples but they are all minimal and not helpful (so far... I'm still looking). Is there better description of how this sourcecontrols resource is supposed to work? I cannot find one.

My goal is to deploy blazor server webapp to my website using the sourcecontrols resource in my deploy.bicep (see link below) using the "az.cmd deployment group create" command. Presently I can successfully deploy my web site using a github push that triggers my github workflow.

  1. So the resource name is "sourcecontrols" and I assume from this name that it can use github to deploy a blazor server web app from the C# source. However, I see (in the above link) a reference to "registryInfo" that looks like a reference to a container registry like DockerHub or ACR. Does sourcecontrols work with both dockerhub for dockercontainers and github source control repositories?
  2. So I have a public github source control repository that I am referencing in my sourcecontrols resource in my bicep file. None of the examples referenced in the documentation (above link) use the "gitnubActionConfiguration". Is this required? What would I specify in the clientSecret? Do I need to specify the azure credentials? Where can I learn what all these attributes are for?
  3. I have workflow action file generated by Visual Studio in the .github/workflows directory (see link below) hooked up to the main branch that successfully deploys to the app server when I do a github push. This workflow does not reference any bicep file and does not create a docker container and requires the target web site be already created and configured (usually with my deploy.bicep file). Here is my attempt to use the sourcecontrols resource: deploy.bicep. I figured my sourcecontrols resource would be sufficient and is similar to what I see in the examples. So how does the sourcecontrols work? I figured that when I execute "az.cmd deployment group create" it would create the app service web site and then go to my public github repository and call my .github\workflows\xyfolxgnipoogweb.yml... Sounds logical to me! Is this the way it is supposed to work? Where is the documentation on how it is supposed to work?
  4. So when I use the "az.cmd deployment group create" I get no errors and the deployment looks successful (database is created, web site is created) except the web site does not display my bazor webapp. I go to the portal and look at the log stream and I can find no clues... I try to use the FTP URL in the portal for the website to get the other logs and it acts like I have an invalid password. Then I give up and do a github push and then my github workflow executes and it successfully deploys my sample web site (everything is now working) and then I get the ftp password again (for the log files) and the password starts working and I get the logs and of course I see a successful deployment (in response to my github push)... How do I get some clues on why the sourcecontrols resources is failing?

Wed Jun 22 2022 Evening Update:
5. I have a new project/github-repo that is exclusively for demonstrating the sourceControls feature.
6. The github action script that the (azure) portal's web site deployment center creates is wrong: it does not login to azure with the github secret I configured and it tries to compile in the wrong directory.
7. So I made the appropriate fixes (see where fixed the directory and added the azure/login) and now I can redeploy the sample web site using either a push from Visual Studio or the little sync icon in the deployment center of the web app in the portal. However, I had to data enter a lot of information (see screen capture below) into the portal.
8. However, when I go to "Export Template" to capture my changes to the deployment center in ARM JSON and decompile to bicep, I see the bicep does not include the information I supplied to the portal like the account, organization and branch (see screen capture below). I also see that no sourceControls resources! I do see a lot of Microsoft.Web/sites/deployment resources (apparently it creates a new one every time I click on the sync icon). I also see a couple of 'Microsoft.Web/sites/basicPublishingCredentialsPolicies' that contain no credentials! Nowhere do I see the URL for my github repository!
9. Which URL should I be using for the correct documentation? sourcecontrols with OAuth tokens or this one: sourcecontrols with githubAcountconfig properties? Hmmm... Maybe I should be using this one (sourcecontrols with OAuth tokens) because it allows me to specify a token and a token secret... How do I create these OAuth tokens and token secretes? Is it safe to publish these OAuth tokens in a public github source code repository?
10. Should I be using basicpublishingcredentialspolicies-scm, deployments and hostnamebindings to mimic what the portal does instead of either of the sourceControl resources? If so, why?
11. When I push with visual studio, my deployment is successful (in the sense that it creates a web site) but the sourceControls resource fails with a monster stack trace: deploy-SourceControlBlazorSvrDemo.bicep and my sample blazor app is not deployed. Looks like the reason it is failing is because it does not have proper credentials for my github account. Can I create another github secret or token so it can access my code in the github account? How do I specify this in the sourcecontrols resource?
12. Update Summary: What do I have to do my bicep file so I don't have to manually go to the portal's deployment center for the web site (see screen capture below) every time I want to re-deploy the site? My goal is to have the command "az.cmd deployment group create ---template-file deploy-SourceControlBlazorSvrDemo.bicep" automatically deploy my blazor C# code to the website without having to data enter all that stuff into the portal every time.

I've been experimenting with the portal web site deployment center.

Wed Jun 29 2022 Mid Day Update:

Background: When creating blazor/ASP.NET projects using visual studio or "dotnet new" commands I see an extra (superfluous?) directory that causes problems when having visual studio generate a deployment workflow that is triggered by a push. Here are the changes I need to make for it to work when I type "git push":

WORKING_DIRECTORY: . ->  WORKING_DIRECTORY: ./SourceControlBlazorSvrDemo  

So by default WORKING_DIRECTORY is the default directory and WORKING_DIRECTORY needs to be a child of the default directory. Then I need to add this code:

    - uses: azure/login@v1  
           creds: ${<!-- -->{ secrets.AZURE_CREDENTIALS }}    

This is so I can log into azure...

So I rename the old working yaml file originally generated by visual studio so I would not trigger two yaml files simultaneously and pulled down the newly created yaml file created by the sourcecontrols resource.

New Problem: I'm seeing a similar problem here when using new yaml file generaged by the sourcecontrol resource: It cannot compile because it is in the wrong directory. I tried making similar changes to this new yaml file generated by the source control resource and I'm getting this error:

  There was a conflict. Conflict with existing ScmType: GitHubAction  

This is after I changed true to false in Venkat's ARM json:

  "generateWorkflowFile": false  

So I'm not clear on what to do... Should this be true the first time, then I edit it and set it to false? That is not working... and I think it is because it is ignoring my change to the WORKING_DIRECTORY environment variable (which is no surprise since this new yaml does not use the environment variable).

Question: So how do I tell the sourcecontrols resource to generate a yaml file that goes down a directory to find the source code to compile? Better yet: can I just tell the resourcecontrols resource to use the working yaml that was originally created by visual studio and edited by me that works? How do I do that?

Wed Jun 29 2022 Evening Update:

I'm not sure what I did (I wish I did!), but I succeeded in creating a new blazor project without the superfluous directory and I got Visual Studio and the sourcecontrol resource to generate yaml files (however the latter generated an empty file!). I then copied the contents of the Visual Studio generated yaml file to the sourcecontrol yaml file and added necessary azure login: master_hqdqhengdtz4w-website.yml and then deleted the original Visual Studio generated yaml file (so I won't have simultaneous builds triggered when I push). So now I have "generateWorkflowFile: false" (see deploy-AADAccessAzureSQLBlazorSvr.bicep) and (as you explained previously) it does nothing! When I manually deploy the yaml workflow from github, it works

So apparently I need "generateWorkflowFile: true" but that generated code does not use my github secret to log into azure. So what can I do? I need the yaml workflow to log into azure!

Thu Jun 30 2022 Update:
I have the magic incantation: do not use visual studio to create a new project because it will create a superfluous (and troublesome) directory that is incompatible with the workflow scripts created by visual studio and the source controls resources... Instead just do "dotnet new blazorserver" and then let visual studio read the csproj file and create the sln file in the same directory...

Please see my failed builds.

What does this error mean and how do I correct it?

D:\a\SourceControlsAzureBicepDemo03\SourceControlsAzureBicepDemo03\SourceControlsAzureBicepDemo03.csproj : error MSB4057: The target "pipelinePreDeployCopyAllFilesToOneFolder" does not exist in the project.  

Here is the code generated by the sourcecontrols in my bicep file: main_txtwjhjyzhuua-web-site.yml.

Here is my bicep that I created by decompiling your json: deploy-SourceControlsAzureBicepDemo03.bicep.



P.S. It would be nice if links to my github source code included a git commit SHA... If I push again all those line numbers will be out of sync... Sorry about that.

Azure App Services
Azure App Services
A feature of Azure App Service used to create and deploy scalable, mission-critical web apps.
4,330 questions
No comments
{count} votes

1 answer

Sort by: Most helpful
  1. VenkateshDodda-MSFT 6,336 Reputation points Microsoft Employee

    @Siegfried Heintze Apologies for the inconvenience caused. I have understood that you are trying to deploy Blazor web app using bicep template and enabling the source controls. App service support continuous deployment from various source controls like GitHub,BitBucket,Azure Repos as explained here.

    • If your App service publish method is code then you can use GitHub action configuration as your source control and if publish method is Docker Container then you can use GitHub either Container Registry or Docker Hub .
    • App Service will place a GitHub Actions workflow in your chosen repository to build and deploy your app whenever there is a commit on the chosen branch. If you are using GitHub action configuration in you Bicep file then you need to pass only the Runtime stack and version. gitHubActionConfiguration: {
      codeConfiguration: {
      runtimeStack: 'string'
      runtimeVersion: 'string'