microsoft / azure-pipelines-tasks

Tasks for Azure Pipelines
https://aka.ms/tfbuild
MIT License
3.51k stars 2.62k forks source link

[BUG]: AzureContainerApps@1 Ignoring Location option #18680

Closed dombarnes closed 1 year ago

dombarnes commented 1 year ago

Task name

AzureContainerApps@1

Task version

1.225.0

Environment type (Please select at least one enviroment where you face this issue)

Azure DevOps Server type

dev.azure.com (formerly visualstudio.com)

Azure DevOps Server Version (if applicable)

No response

Operation system

Ubuntu 22.04.2 LTS

Task log

Starting: AzureContainerApps
==============================================================================
Task         : Azure Container Apps Deploy
Description  : An Azure DevOps Task to build and deploy Azure Container Apps.
Version      : 1.225.0
Author       : Microsoft Corporation
Help         : [Learn more about this task](http://github.com/microsoft/azure-pipelines-tasks/blob/master/Tasks/AzureContainerAppsV1/README.md)
==============================================================================
/usr/bin/az login --service-principal -u *** --password=*** --tenant XXXXXXX --allow-no-subscriptions
/usr/bin/az account set --subscription XXXXXXXX
/usr/bin/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
/usr/bin/az containerapp show -n <container-app-name> -g <resource-group> -o none
WARNING: The command requires the extension containerapp. It will be installed first.
WARNING: The installed extension 'containerapp' is in preview.
/usr/bin/az containerapp up -n <container-app-name> -g <resource-group> -i myacr.azurecr.io/myimage:dev --ingress external
ERROR: Location 'uk-west' is not currently supported. To get list of supported locations, run `az provider show -n Microsoft.App --query "resourceTypes[?resourceType=='managedEnvironments'].locations"`

Relevant log output

ERROR: Location 'uk-west' is not currently supported. To get list of supported locations, run `az provider show -n Microsoft.App --query "resourceTypes[?resourceType=='managedEnvironments'].locations"`

Starting: Initialize job
Agent name: 'Hosted Agent'
Agent machine name: 'fv-az710-733'
Current agent version: '3.220.5'
Operating System
Ubuntu
22.04.2
LTS
Runner Image
Image: ubuntu-22.04
Version: 20230716.1.0
Included Software: https://github.com/actions/runner-images/blob/ubuntu22/20230716.1/images/linux/Ubuntu2204-Readme.md
Image Release: https://github.com/actions/runner-images/releases/tag/ubuntu22%2F20230716.1
Runner Image Provisioner
2.0.238.1
Current image version: '20230716.1.0'
Agent running as: 'vsts'
Prepare build directory.
Set build variables.
Download all required tasks.
Downloading task: AzureContainerApps (1.225.0)
Checking job knob settings.
   Knob: DockerActionRetries = true Source: $(VSTSAGENT_DOCKER_ACTION_RETRIES) 
   Knob: AgentToolsDirectory = /opt/hostedtoolcache Source: ${AGENT_TOOLSDIRECTORY} 
   Knob: AgentPerflog = /home/vsts/perflog Source: ${VSTS_AGENT_PERFLOG} 
   Knob: ContinueAfterCancelProcessTreeKillAttempt = true Source: $(VSTSAGENT_CONTINUE_AFTER_CANCEL_PROCESSTREEKILL_ATTEMPT) 
Finished checking job knob settings.
Start tracking orphan processes.
Finishing: Initialize job

Aditional info

I am running this as part of a step in my CI template. However, it seems to be ignoring the location option, and as a result, giving me an error that it can't be run in UK West. The command runs as expected when run on my local development machine adding the -l uksouth argument to the same command line: az containerapp up -n my-app-name -g my-resource-group -i myacr.azurecr.io/myimage:dev --ingress external -l uksouth

azure-pipelines.yml

steps:
  - checkout: none
  - ${{ each site in parameters.containerAppNames }}:
    - task: AzureContainerApps@1
      inputs:
        azureSubscription: 'my-service-connection'
        imageToDeploy: 'my-acr.azurecr.io/$(dockerAppName):$(buildName)'
        location: 'uksouth'
        containerAppName: ${{ site }}  
        resourceGroup: 'my-resource-group'
        ingress: 'external'
        containerAppEnvironment: 'ttv-cae-01'
cormacpayne commented 1 year ago

@dombarnes Hey Dom, thanks for filing this issue -- I just want to confirm the behavior that you're seeing with this task:

The step you've provided at the end of your issue (under the azure-pipelines.yml text) is what you're providing that results in the error message saying that 'uk-west' is not currently supported?

The location of a Container App is tied to the location of the managed environment that the Container App was created in, so if you're using an existing managed environment and provide a location, that location will be ignored in favor of the location associated with the managed environment. (There is currently no way for a Container App managed environment to migrate regions)

dombarnes commented 1 year ago

I did some further testing and think I found the solution. Unfortunately my code of azure-pipelines.yml above was misleading. My project actually had a repo checkout stage because my deploy step is not in a deploy strategy block (In my actual pipeline, i am doing a DockerC. My project also has a .azure/config file which specifies a default location for the azure CLI (guess where - UK West). Once I removed the checkout stage, the AzureContainerApp stage proceeded.

The command az containerapp up -n my-app-name -g my-resource-group -i myacr.azurecr.io/myimage:dev --ingress external does not pass the location as an argument so it defaults back to the .azure/config setting. Location 'uk-west' is not currently supported. To get list of supported locations, run 'az provider show -n Microsoft.App --query "resourceTypes[?resourceType=='managedEnvironments'].locations"' I can also assume that by checking out the repo, your working directory is moved from Pipeline.Workspace to DefaultWorkingDirectory

So by setting checkout: none in my pipeline (contradictory to my snippet above) this solved the issue. This seems like an undocumented fact, and if you are using this task and are required to build a Docker file in the process (i.e setting imageToBuild) then you are going to checkout your required repo, and if that were to contain an azure CLI config file, then this would being applied in the background.

cormacpayne commented 1 year ago

@dombarnes Hey Dom, thanks for the update -- I'm glad to hear that you were able to resolve your issue, and thanks for providing the additional context on what you found.

To follow-up on this, is there anything actionable on our side that you need from us? We can look at updating the documentation to call out the notes you made, but if there's anything else, please feel free to let me know.

I'm going to close this issue since it seems to be resolved, but we can continue discussing any follow-up items here and I'd be happy to reopen the issue if necessary.

dombarnes commented 1 year ago

The only follow up I would say is to clarify how location may be overwritten or ignored such as this case. My original assumption was that location was location was passed with a command line flag, which presumably takes priority over the .config file. So I was expecting to see the flag in my DevOps logs.

Secondary comment is that it was unusual that this action would try to create the resources needed when this isn't my experience with other Azure tasks. Most other deploy tasks I've used would just fail on missing resources.