skip to Main Content

curious, is it possible to deploy to azure app service or azure function app using bicep. That is, when creating app service in the bicep, we add the deployment of the app or function in the same template.

I have seen the sourcecontrol resources (see below) but it looks like it only support external git (github). my code is in azuredevops.

Microsoft.Web/sites/sourcecontrols@2021-01-01.

Background: Every time I run a bicep template all the function apps are redeployed and we lose all the functions they have already been deployed. I want to make sure that when the bicep is run, it redeploy the function app with the functions by pull them from the SCM.

Every time I run a bicep template all the function apps are redeployed and I lose all the functions they have already been deployed. I want to make sure that when the bicep is run, it redeploy the function app with the functions by pull them from the SCM.

2

Answers


  1. Deploying the app code itself directly within the Bicep template is not supported. Bicep is primarily used for infrastructure deployment and management, whereas the app code deployment typically happens through CI/CD pipelines or external sources.

    To ensure your application is not erased while deploying, follow these steps:

    1. Ensure to use incremental mode

    To avoid losing existing functions, always use incremental mode when deploying Bicep templates. This ensures only the changes are applied, and existing resources are not deleted unless explicitly defined.

    az deployment group create 
      --name MyDeployment 
      --resource-group MyResourceGroup 
      --template-file main.bicep 
      --mode Incremental
    

    Reference: Azure Resource Manager Deployment Modes

    2. Zip deploy + WEBSITE_RUN_FROM_PACKAGE = 1

    To ensure that when you deploy a Bicep file to an Azure Function, the application itself is not removed, set the WEBSITE_RUN_FROM_PACKAGE application setting to 1. This ensures that the function app runs from a package file instead of from the local file system, which helps to maintain the application state during deployments.

    Reference: Run functions from Deployment Package

    3. Use deployment slots (optional)

    When possible, use deployment slots to swap between a new build, this will reduce the downtime.

    Reference: Set up staging environments with azure app service

    Login or Signup to reply.
  2. Background: Every time I run a bicep template all the function apps are redeployed, and we lose all the functions they have already been deployed.

    If you want to avoid redeploying all the function apps every time you run the Bicep template, you can consider using Conditional deployments in Bicep with the if expression.

    With conditional deployments, you can specify a condition that determines whether to create a new function app or use an existing one.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search