Azure / azure-dev

A developer CLI that reduces the time it takes for you to get started on Azure. The Azure Developer CLI (azd) provides a set of developer-friendly commands that map to key stages in your workflow - code, build, deploy, monitor, repeat.
https://aka.ms/azd
MIT License
410 stars 198 forks source link

azd init -t is not compatible with Aspire templates w/o azure.yaml on the root #4171

Open vhvb1989 opened 3 months ago

vhvb1989 commented 3 months ago

Issue: running azd init -t repo-url clones the repo with an empty azure.yaml file at the root.

When: When a repository has an AppHost project which contains azure.yaml inside the AppHost (instead of the root of the project)

Expected: azd should detect if there is an app host with azure.yaml and skip creating azure.yaml on the root.

pbusfield commented 3 months ago

@vhvb1989 Actually the AppHost doesnt have an azure.yaml file after running azd init -t repo-url. The azure.yaml file is only created in the root, and it is empty. And there is no next-steps.md created.

If I now delete all files in the root, and then clone the repo using VS, (and not running azd init -t repo-url), it clones the repo, and then I run azd init from the root, I then select 'Current Directory' and hit 'Confirm', and give in an Environment name. It then creates the azure.yaml file in the root successfully'. It also creates the next-steps.md file.

This is the confirmation I get when running the above commands:

Detected services:

  .NET (Aspire)
  Detected in: C:\ORG\APPNAME\APPNAME.AppHost\APPNAME.AppHost.csproj

azd will generate the files necessary to host your app on Azure using Azure Container Apps.
. Contents:

This is now the contents of the azure.yaml (which is now correct):

# yaml-language-server: $schema=https://raw.githubusercontent.com/Azure/azure-dev/main/schemas/v1.0/azure.yaml.json

name: APPNAME
services:  
  app:
    language: dotnet
    project: .\APPNAME.AppHost\APPNAME.AppHost.csproj
    host: containerapp

azd infra synth works. azd up works.

I then run into problems from my first comment in issue 3037 where I say the issue still exists under https when I run azd pipeline config -e dev

So I just cannot get the azd pipeline config -e dev to run successfully, no matter which direction I take.

Thanks

vhvb1989 commented 3 months ago

@pbusfield , there is an issue with azd init -t repo-url for Aspire projects. azd is creating an empty azure.yaml instead of detecting the AppHost.

The workaround for you case is:

After that, you can run azd pipeline config

pbusfield commented 3 months ago

@vhvb1989 Thanks Victor. I tried the method of cloning the repo via VS, then running git remote remove origin I then run: azd init = Success (giving it an environment name of 'test' when prompted) azd infra synth = success (Infra folders created) azd up = Error:

ERROR: error executing step command 'deploy --all': getting resource group name: getting default resource groups for environment: test: resource not found: 0 resource groups with prefix or suffix with value: 'test' PS C:\YourITTeam\Eq

Do I have to create the Resource Group named 'rg-test' manually? before runningh azd up ?

vhvb1989 commented 3 months ago

Can you share the generated content from the infra folders?

I was under the idea that you wanted to run azd pipeline config. Are you running infra synth to make some changes to your infrastructure before deploying?

pbusfield commented 3 months ago

My ultimate goal is the run azd pipeline config, after I run azd up .

I actually thought that the whole process included running azd infra synth ? Which created the infra folder in the root, which contains the main.bicep file used for the azd up process? I tried running azd up last week without running the azd infra synth command, and it errored saying it couldn't find the infra/main.bicep file.

There are 6 generated tmpl.yaml files in the infra folder inside the AppHost holder. The first one, which causes the error, its content is:

api-version: 2024-02-02-preview
location: {{ .Env.AZURE_LOCATION }}
identity:
  type: UserAssigned
  userAssignedIdentities:
    ? "{{ .Env.AZURE_CONTAINER_REGISTRY_MANAGED_IDENTITY_ID }}"
    : {}
properties:
  environmentId: {{ .Env.AZURE_CONTAINER_APPS_ENVIRONMENT_ID }}
  configuration:
    activeRevisionsMode: single
    runtime:
      dotnet:
        autoConfigureDataProtection: true
    ingress:
      external: true
      targetPort: {{ targetPortOrDefault 8080 }}
      transport: http
      allowInsecure: false
    registries:
      - server: {{ .Env.AZURE_CONTAINER_REGISTRY_ENDPOINT }}
        identity: {{ .Env.AZURE_CONTAINER_REGISTRY_MANAGED_IDENTITY_ID }}
  template:
    containers:
      - image: {{ .Image }}
        name: invoice-api
        env:
          - name: AZURE_CLIENT_ID
            value: {{ .Env.MANAGED_IDENTITY_CLIENT_ID }}
          - name: ASPNETCORE_FORWARDEDHEADERS_ENABLED
            value: "true"
          - name: Invitation--BaseUrl
            value: http://localhost:3000
          - name: KeyVault--Name
            value: inflow-kv-dev
          - name: OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EVENT_LOG_ATTRIBUTES
            value: "true"
          - name: OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES
            value: "true"
          - name: OTEL_DOTNET_EXPERIMENTAL_OTLP_RETRY
            value: in_memory
    scale:
      minReplicas: 1
tags:
  azd-service-name: invoice-api
  aspire-resource-name: invoice-api

Hope that helps?

rajeshkamal5050 commented 2 months ago

@pbusfield could be that your previous runs weren't successfully deleted properly. How did you delete resources? cc @weikanglim @hemarina

Does your azd up report something like this?

(-) Skipped: Didn't find new changes. SUCCESS: There are no changes to provision for your application.

Refer to these issues https://github.com/Azure/azure-dev/issues/3771 https://github.com/Azure/azure-dev/issues/3559 which had similar error.

ERROR: error executing step command 'deploy --all': getting resource group name: getting default resource groups for environment: test: resource not found: 0 resource groups with prefix or suffix with value: 'test'

weikanglim commented 1 month ago

azd should detect if there is an app host with azure.yaml and skip creating azure.yaml on the root.

I wonder if we should provide user recommendation for template authors to move azure.yaml to the root before publishing templates? If so, we can make documentation improvements here. I would love to get user feedback on how well this system works, and if this is also a workable solution long-term.

azd supports both azure.yaml at the root and at the app host level. In Visual Studio, we default to the app host directory. However, it still works equally at the root except when you have multiple Visual Studio projects within a solution.

ERROR: error executing step command 'deploy --all': getting resource group name: getting default resource groups for environment: test: resource not found: 0 resource groups with prefix or suffix with value: 'test'

@pbusfield Thank you for reporting this issue. My apologies that we're behind on catching up with you on this conversation. If you are still experiencing issues, would you be able to create a new issue with the repro steps? It would make it easier to have a dedicated conversation -- and we'll see to it that you get the help you need.

pbusfield commented 1 month ago

@weikanglim Yes I am still experiencing this same issue:

ERROR: error executing step command 'deploy --all': getting resource group name: getting default resource groups for environment: test: resource not found: 0 resource groups with prefix or suffix with value: 'test'

I will start a new thread and give you steps to reproduce and tag you in it.

Thanks