dotnet / docs-aspire

This repository contains .NET Aspire documentation.
https://learn.microsoft.com/dotnet/aspire
MIT License
87 stars 113 forks source link

Issue in documentation for Deploying Aspire via AZDO #983

Open joseph-hungerman opened 6 months ago

joseph-hungerman commented 6 months ago

I am attempting to deploy an Aspire app to Azure. I followed the documentation and everything went as expected until I reached the provisioning step of the Pipeline. I get an error back that says: ERROR: no project exists; to create a new project, run azd init. I ran this command as stated within the documentation, which creates a set of documents that are ignored by the repo. I am assuming this config is set within the connection of the pipeline workflow and creating the pipeline using bicep. I tried running the following pwsh command, but there is a prompt to continue that has no default, so this option didn't work. I then tried exposing the .azure folder to git and that didn't work either. Some help troubleshooting this would be great. I would also expect this to be covered within the documentation.

- pwsh: | azd init --environment $(AZURE_ENV_NAME) --location $(AZURE_LOCATION) --subscription $(AZURE_SUBSCRIPTION_ID) --from-code --no-prompt

alexwolfmsft commented 6 months ago

Hello, if you run azd pipeline config before azd init it does produce the error "no project exists; to create a new project, run azd init". Did you try to run azd init before you run azd pipeline config after creating a new starter project? To complete the default flow of the tutorial you shouldn't have to run azd init with any parameters.

joseph-hungerman commented 6 months ago

This isn't for the starter project, this is for a real world project. I have 4 environments (test, dev, stg, \?\$\?\@). My command workflow:

  1. azd init (set environment to Testing during prompt) a. This created a bunch of hidden files in the .azure folder with a .gitignore for all of them Screenshot 2024-05-30 092520

  2. Created azure-dev.yml as described Screenshot 2024-05-30 092641

  3. azd pipeline config --provider azdo (set to my org with PAT)

  4. Pipeline was created in AZDO with variables, resulting file created by azd in AZDO: `trigger:

    • feature/*

pool: vmImage: ubuntu-latest

steps:

ERROR: no project exists; to create a new project, run azd init

[error]Script failed with exit code: 1

/usr/bin/az account clear Finishing: Provision Infrastructure

joseph-hungerman commented 6 months ago

Another annoyance: AZD_INITIAL_ENVIRONMENT_CONFIG is set to secret when the pipeline is pushed to my project. I can't validate whether anything in this variable is correct. This would be less problematic if it was pushed as a normal var and let the user set it as secret. Once it's a secret it can't be viewed.

IEvangelist commented 5 months ago

Hey @alexwolfmsft - any chance you could look into this one?

Moristar commented 2 months ago

I have the same issue. Set everything up with azd init. Created DEV environment and pushing to it successfully with azd up. When development got to the point we wanted to add CI/CD we just faced a wall. Documentation prescribed steps produce a pipeline in our Azure DevOps organization, but when the pipeline is running - it just returns:

Provision infrastructure step ... /usr/bin/az account set --subscription /usr/bin/bash /home/vsts/work/_temp/azureclitaskscript1725931063275.sh

ERROR: no project exists; to create a new project, run azd init


I can only assume that developers are not using Azure DevOps themselves and documentation is even contains an image with a sample of the setup command using GitHub actions for Azure DevOps section: https://learn.microsoft.com/en-us/dotnet/aspire/deployment/azure/aca-deployment-github-actions?tabs=windows&pivots=azure-pipelines#create-the-azure-devops-repository-and-pipeline

It's not a "sample app" for some of us. We're trying to get to market fast with a small team, however we're stumbling over smallest things all the time, because Aspire is not treated as an enterprise level solution it seems.

joseph-hungerman commented 1 month ago

So is no one going to look at this? I put it aside for a while because I was solo so I could just manually deploy, but now I'm building an MVP. I brought on a 20+ year .NET developer / architect and he can't get it to work either. My initial message was almost 6 months ago!

davidfowl commented 1 month ago

cc @vhvb1989

vhvb1989 commented 1 month ago

@joseph-hungerman , since you ran azd init from inside the AppHost folder, the azure.yaml is created there. Azure.yaml defines where is the azd project root.

On your pipeline, either use the cwd for the step where you are running azd provision or manually cd into your AppFolder before running azd provision.

You are not expected to run azd init on CI/CD

Lmk if this works for you.

(Optionally, you can use the root of your repo to run azd init and then you wouldn't need to cd to the AppHost folder on CI/CD)

joseph-hungerman commented 1 month ago

So moving azure.yaml to the root of the solution worked, after I updated the directory. All of the documentation I have see says to run azd init on the project. So that probably needs to be looked at.

Now I am facing an issue in deploy pulling env vars I have setup in the .env file for the Testing environment. I have all of the files as secure files, and the variables are setup in a group within the library. I have checked and the file is being downloaded to where I expect. Here is my pipeline and the error:

` trigger:

pool: vmImage: ubuntu-latest

variables:

steps:

ERROR: failed deploying service 'cache': failed executing template file: template: manifest template:2:17: executing "manifest template" at <.Env.AZURE_LOCATION>: map has no entry for key "AZURE_LOCATION"

Cache template:

` 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: false targetPort: 6379 transport: tcp allowInsecure: false registries:

joseph-hungerman commented 1 month ago

I did try updating my pipeline to the following based on some of your other resolutions, but still getting the same error:

joseph-hungerman commented 1 month ago

@joseph-hungerman , since you ran azd init from inside the AppHost folder, the azure.yaml is created there. Azure.yaml defines where is the azd project root.

On your pipeline, either use the cwd for the step where you are running azd provision or manually cd into your AppFolder before running azd provision.

You are not expected to run azd init on CI/CD

Lmk if this works for you.

(Optionally, you can use the root of your repo to run azd init and then you wouldn't need to cd to the AppHost folder on CI/CD)

OK, so I have most of it done. But, I cannot get the pipeline to setup the ingress. It does ok for imported containers (Redis, Prometheus, Grafana), but it does not set-up the ingress for custom .NET services. The ASPNETCORE_ENVIRONMENT is also populating as an empty string during deployment.

` 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 fqdn: "ui-server.proudisland-31f1f5e2.centralus.azurecontainerapps.io" targetPort: {{ targetPortOrDefault 8080 }} transport: http allowInsecure: false customDomains:

`

` trigger:

pool: vmImage: ubuntu-latest

variables:

steps:

Deploying service ui-server Deploying service ui-server (Logging in to registry) Deploying service ui-server (Pushing container image) Deploying service ui-server (Updating container app) Deploying service ui-server (Fetching endpoints for container app service) (✓) Done: Deploying service ui-server