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
402 stars 195 forks source link

Support a way to respond Yes for override files when running azd from CI/CD --no-prompt mode #3493

Open vhvb1989 opened 6 months ago

vhvb1989 commented 6 months ago

When running azd init -t source/template , if there are files in the current folder where azd is running, azd will first ask for a confirmation about using the current folder (as it might override files).

The confirmation is a good way to prevent unwanted scenarios, but it becomes a blocker when users runs azd from CI/CD and they are intentionally running azd init -t template within a folder that contains other files.

azd should allow some flag like azd init -t template --force for pre-approving the prompt for a non-empty folder

image

vaibbavis commented 6 months ago

This enhancement will be useful to us since we are hoping to make the process of deploying samples easier for users using github actions. We use the azd commands as part of a github action to deploy an openAI sample, however we are currently blocked by the prompt regarding if files can be overwritten, since confirmation to an interactive command cannot be provided during CI/CD. It would be great if we could pass in an argument that would default it to overwrite files.

weikanglim commented 6 months ago

This is something azd could support, but I'm not sure about the full scenario yet.

@vaibbavis Were you expecting the files to be there and be overwritten? Like "overlaying" the template on top of some existing base layer?

seesharprun commented 1 month ago

@weikanglim, I can give a sample scenario.

I write code samples using AZD templates. For my code samples, I want the user to be able to use any one of these strategies:

  1. Open the GitHub repository as a devcontainer in Visual Studio Code
  2. Go to GitHub and open the sample repository as a Codespace
  3. Start with an empty folder and get the sample using AZD

Today, I can't provide instructions that support all three scenarios. If I provide these instructions:

azd init --template <name-of-template>

Then, the user is shown a dialog for two of those scenarios asking if they want to overwrite the local files. I had users give feedback that they think the sample is broken when this happens.

If I use these instructions:

azd init

It doesn't support the scenario if the user has an empty directory.

In an ideal world, I would like to give instructions to pull the sample that works in an empty directory or if you already have the sample (ex: GitHub Codespaces).

This command doesn't work because it responds "No":

azd init --template <name-of-template> --no-prompt

Ideally, a flag that responds yes like --confirm-prompt or --yes-prompt could solve the problem for me.

Here's an example of a documentation article where I have a code sample in AZD.

https://learn.microsoft.com/azure/cosmos-db/mongodb/quickstart-dotnet#setting-up

I'm getting feedback from users with both strategies I tried over the last few months:

Strategy Type of user Feedback
azd init --template cosmos-db-mongodb-dotnet-quickstart GitHub Codespace user "Why does it ask me if I want to overwrite the files?"
azd init Uses with an empty folder who don't want to or can't use a devcontainer "It's prompting me for a template. What's the name of the template?"

Ideally, I could have one command that works in all scenarios and overwrites when appropriate. I hope this is useful context.

vhvb1989 commented 1 month ago

@anfibiacreativa , since I think your model also needs this

weikanglim commented 1 month ago

@seesharprun That makes sense, thanks for the feedback.

I think we could indeed add --force as Allows existing files to be overwritten without confirmation.

In that world, the command could be given to initialize the template, regardless of environment setup (based on https://learn.microsoft.com/azure/cosmos-db/mongodb/quickstart-dotnet#setting-up):

Run azd init to initialize the project azd init --template <name-of-template> --force

The things I may worry about in this world: did the user choose the right directory to run azd init in? It will override any existing files if they did not choose correctly. A new template user might also form the impression that --force seems to be the happy pathway.

I wonder if the instructions are calling out to start from dev container, then perhaps we can simply say:

  1. Open a terminal in the root directory of the project. Alternatively, if starting from an empty directory, run azd init --template <name-of-template> to fetch the template files from the GitHub repository.

A good suggestion that @vhvb1989 had is to perhaps pass the -e flag to azd init to specify a default environment, if we intend this document to be read by a user relatively early in the azure dev journey. A critique about this proposal is that the user gets prompted for environment initialization early, which is similar to the DX difficulty that @anfibiacreativa raised.