Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for .azdignore #4146

Closed
wants to merge 14 commits into from
Closed

Add support for .azdignore #4146

wants to merge 14 commits into from

Conversation

jongio
Copy link
Member

@jongio jongio commented Jul 24, 2024

Fixes #4142

Summary

This pull request introduces support for .azdignore files in the Initializer component, providing users with the ability to specify files and directories to be excluded during initialization. This functionality mirrors the behavior of .gitignore files, enhancing the flexibility and control over which files are included in the project setup. Additionally, the ability to load a template from a local folder has been added to facilitate ease of end-to-end testing with the init function.

Scenario

A template author needs file in the repo to validate the repo, but doesn't want a consumer of the template to have those files copied when they call azd init.

With the addition of .azdignore support, users can now define ignore patterns upfront, simplifying the initialization process.

New Features

  1. Support for .azdignore Files:

    • Users can create a .azdignore file in the root of the project directory.
    • The .azdignore file uses the same syntax as .gitignore, allowing users to specify patterns for files and directories to be excluded.
  2. Automatic Exclusion of Specified Files:

    • During initialization, the Initializer component will read the .azdignore file and automatically exclude the specified files and directories from being copied to the project directory.
  3. Loading Templates from Local Folders:

    • Users can now specify a local folder path for templates, facilitating easier end-to-end testing and development.

How to Use

  1. Create a .azdignore File:

    • In the root of your project directory, create a file named .azdignore.
    • Add patterns to this file to specify which files and directories should be ignored.

    Example .azdignore file:

    # Ignore all log files
    *.log
    
    # Ignore directories
    tmp/
    build/
    
    # Ignore specific files
    secret.yaml
    
  2. Initialize the Project:

    • Run the initialization process as usual.
    • The files and directories matching the patterns in the .azdignore file will be excluded automatically.
  3. Use Local Templates:

    • Specify a local folder path when initializing with a template to use local template files.
    • Example: azd init --template ./path/to/local/template

To-Do

  • Update Documentation:
    • Update the README.md to include instructions and examples for using .azdignore files.
    • Include information on using local folder paths for templates.

Copy link
Contributor

@wbreza wbreza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good and useful for the scenario that was described.
Would love to see some unit/functional tests to validate the behavior before getting this merged in.

cli/azd/.vscode/launch.json Outdated Show resolved Hide resolved
@jongio jongio force-pushed the azdignore branch 2 times, most recently from fd610e8 to c5d9ddf Compare August 7, 2024 16:01
@jongio jongio requested review from wbreza and ellismg August 7, 2024 16:07
@jongio jongio marked this pull request as ready for review August 7, 2024 16:08
@jongio
Copy link
Member Author

jongio commented Aug 7, 2024

@wbreza - Please also see this update:

3. **Loading Templates from Local Folders**:
   - Users can now specify a local folder path for templates, facilitating easier end-to-end testing and development.

Relevant code:

https://github.com/Azure/azure-dev/pull/4146/files#diff-f2696f08bd2b974155c4e67ee1bf2d84ec43f08596faedb15c5b407d9764caf5

@jongio jongio requested a review from pamelafox August 7, 2024 16:10
@jongio
Copy link
Member Author

jongio commented Aug 7, 2024

@pamelafox - This allows template authors to specify which files should be ignored when a template consumer runs azd init on their template. Can you please review?

Copy link
Member

@ellismg ellismg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .azdignore stuff looks good and I like how we were able to leverage an existing package (and hence file format) that matches .gitignore semantics.

The support for other remote types gave me a bit of pause, just because of all the path mangling going on.

In practice what sort of files are going to be .azdignore'd? Are folks who clone a template that uses this technology setting themselves up for failure later when they create a repository based on the code they got from the template (minus the ignored stuff)?

return path, nil
}

path = strings.TrimRight(path, "/")
// Check if path is a relative or absolute file path
if isRelativePath(path) || isAbsolutePath(path) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was all added so we could support azd init --template <some-local-filesystem-path-that-point-at-a-git-repo>?

I will admit I'm a little nervous about all the path munging here (especially with how we have to handle windows specific drive letter paths, but also even on nix some of the time)?

Is this related to the .azdignore stuff or just another nice to have while you were in the area? Is initializing from a template collocated on your machine a common scenario we want to support?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While writing tests for .azdignore, I wanted to dynamically build templates with various files to test all patterns. Instead of creating physical templates for each scenario, I added the ability to reference a local template. This enhancement allowed me to test the end-to-end process using azd init, ensuring the files were copied correctly according to the .azdignore rules.

The tests now cover both Windows and POSIX environments, ensuring compatibility across different operating systems.

Do you have any suggestions for alternative approaches or improvements to this method?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At a first glance, I wonder with this being a public feature, scoping as an isolated change with a more clear line-of-sight how the feature affects the system as a whole may be helpful.

I believe that the result of this change as-is, based on how this logic is embedded into templates path calculation, is that the upstream template source can now specify relative paths, or drive paths, and azd would gladly process that.

For example, if awesome-azd (or any remote template source) added a new template entry with the RepositoryPath set to a local relative path, I believe azd would honor it.

I tested this by doing the following:

  1. azd template source add local --type file --location cli/azd/resources/templates.json
  2. Added an entry:
{
    "name": "Local template",
    "description": "",
    "repositoryPath": "../../../",
    "tags": [
      "bicep"
    ]
  },
  1. azd init
  2. Chose Local template
  3. azd gladly processed the relative path but would fail if the path isn't a valid git repository.

I don't think this is a huge deal by any means, but I feel that template sources just shouldn't be allowed to do this, but I'm happy to be convinced otherwise.

Overall, I do understand and buy-in to the need here for e2e testing purposes from an authoring perspective. I just wonder if it's more prudent to just add this type of local testing handling to the azd init --template <path> command directly to avoid.

}

switch parsedURL.Scheme {
case "http", "https", "ssh", "git", "file":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We didn't support ssh:// before for templates, are we sure the right thing will happen with respect to auth or are folks going to get stuck being prompted for their passphrase or something if we try to git clone?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I included ssh:// here because I wanted to be inclusive of all git schemes. I'm not stuck on including it. I don't mind pulling it for now if you think that is better.

cli/azd/test/functional/init_test.go Show resolved Hide resolved
@jongio
Copy link
Member Author

jongio commented Aug 7, 2024

In practice what sort of files are going to be .azdignore'd? Are folks who clone a template that uses this technology setting themselves up for failure later when they create a repository based on the code they got from the template (minus the ignored stuff)?

This is the first step towards thinking about 2 personas "template authors" vs "template consumers". A template author would use .azdignore to exclude files they don't want to be used by a template consumer, such as specialized pipeline files, or other eng sys assets that the template consumer wouldn't need.

@pamelafox
Copy link
Member

Hm, so when I saw this PR title, I initially assumed that azdignore would describe files to get ignored by the deployment process. Instead, its describing files to get ignored by init, and doesnt seem to relate to deploy? I usually prefer that people do a git clone, not azd init, so that they can easily pull changes from upstream, so I don't have a huge opinion about the azd init flow.
However, I'm worried other folks might also think its describing files to ignore during deployment, so is there a way to make that clearer?

func Absolute(path string) (string, error) {
// already a git URI, return as-is
if strings.HasPrefix(path, "git") || strings.HasPrefix(path, "http") {
path = strings.TrimRight(path, string(filepath.Separator))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filepath.Separator is the OS-specific separator, on Windows this would be \. I believe with this change, Azure-Samples/todo-python-mongo/ (which we have seen happen on awesome-azd) no longer gets trimmed to Azure-Samples/todo-python-mongo on a Windows machine.

@jongio
Copy link
Member Author

jongio commented Aug 19, 2024

Hm, so when I saw this PR title, I initially assumed that azdignore would describe files to get ignored by the deployment process. Instead, its describing files to get ignored by init, and doesnt seem to relate to deploy? I usually prefer that people do a git clone, not azd init, so that they can easily pull changes from upstream, so I don't have a huge opinion about the azd init flow. However, I'm worried other folks might also think its describing files to ignore during deployment, so is there a way to make that clearer?

@pamelafox

We are considering moving to a model where we have two personas "template authors" and "template consumers". We want all template consumers to use azd init but template authors to use git clone.

That way the template author can include things in the template that are needed for the template to say pass ci or some other validation that is needed for authoring the template.

And the template consumer isn't going to need all of those files. So template author would use .azdignore file to exclude them.

Do you have an example of deployment time azd should ignore that isn't already covered in a platform idiomatic way? .dockerignore etc.

@pamelafox
Copy link
Member

@jongio Two reasons for my interpretation of .azdignore -

  1. To ignore more files: Currently azd always ignores pycache, venv, etc. Sometimes people put tests/ folder directly inside their src/ folder, so it also gets deployed. If there was an azdignore, they could ignore that folder. I try to structure tests/ outside now, but that requires more Python knowledge to deal with path issues.

  2. To ignore lessfiles: There are actually situations where I'd want to include the venv (like if I wanted to do the build locally and skip the Oryx build on App Service). As far as I know, there isn't currently a way to override the default ignored files.

As for your proposal: I guess "azd init" makes sense for templates where you're just getting infra and building on it. I'd still want developers to use "git clone" for repos like azure-search-openai-demo where they're actively pulling updates to a fully functional app. Also, if a dev opens in Codespaces and runs azd init, they'll still have all the original files, right? (Since the old ones dont get deleted, I think?) Or are you imagining a different Codespaces flow?

@jongio
Copy link
Member Author

jongio commented Aug 22, 2024

@pamelafox - For the template author vs template consumer problem "don't give the consumer more files than they need" - do you think that is a real problem or are people okay with getting more files than they need?

I will look into using azdignore for your other scenario.

@vhvb1989
Copy link
Member

@jongio Two reasons for my interpretation of .azdignore -

  1. To ignore more files: Currently azd always ignores pycache, venv, etc. Sometimes people put tests/ folder directly inside their src/ folder, so it also gets deployed. If there was an azdignore, they could ignore that folder. I try to structure tests/ outside now, but that requires more Python knowledge to deal with path issues.
  2. To ignore lessfiles: There are actually situations where I'd want to include the venv (like if I wanted to do the build locally and skip the Oryx build on App Service). As far as I know, there isn't currently a way to override the default ignored files.

As for your proposal: I guess "azd init" makes sense for templates where you're just getting infra and building on it. I'd still want developers to use "git clone" for repos like azure-search-openai-demo where they're actively pulling updates to a fully functional app. Also, if a dev opens in Codespaces and runs azd init, they'll still have all the original files, right? (Since the old ones dont get deleted, I think?) Or are you imagining a different Codespaces flow?

This feels more like service-host specific, @jongio.
Like, when you are working with Azure WebApp (including Azure Functions) + Python, azd runs zip-deploy and has no mechanism for users to customize the list of files to include/ignore for the .zip file.
But, when working ACA + Python, the user has control of what files to include using Dockerfile
For SWA + Python, the user can control the package-deploy using the swa-config.json

So, I would consider adding something unique for Azure WebApp (service host level), as using something like .azdignore for this might have no sense for ACA and/or SWA.

@pamelafox
Copy link
Member

@jongio Its certainly possible that extra files might be overwhelming or folks getting started with templates. In user studies, I think I only saw that once with a developer looking at the notebooks/ folder instead of the src/ folder in azure-search-openai-demo. Maybe devs are used to ignoring stuff like .github, tests, etc.

@jongio jongio force-pushed the azdignore branch 2 times, most recently from 62d8663 to aef9154 Compare August 23, 2024 23:10
@Petermarcu
Copy link
Member

@pamelafox once someone uses and template on starts making it their own we don't really want them working in a branch of the template repo do we? Are you thinking that its a fork and clone and they maintain the upstream relationship throughout the lifecycle of them product work?

@jongio
Copy link
Member Author

jongio commented Aug 24, 2024

@pamelafox - I have added the ability to use .azdignore for package and as well init. Here's an example: https://github.com/Azure/azure-dev/pull/4146/files#diff-893cfb1f27b449737323ce0d029d83b3615ee36aaebeae1f4d9acf663d0a027f

Can you try this out and see if this is what you are looking for?

Right now it defaults to removing the pycache and the venv folders. Are you saying there and some cases where you want azd to package those files/folders?

@pamelafox
Copy link
Member

Yes, we are thinking of disabling the Oryx build on App Service (for security reasons with our Vnet option), which means we'd need to send the whole environment with Python packages up to App Service. Not sure how you could support that in a backward compatible way.. Maybe if there's a .azdignore, it wouldnt default to ignoring anything?

@jongio
Copy link
Member Author

jongio commented Aug 26, 2024

Yes, we are thinking of disabling the Oryx build on App Service (for security reasons with our Vnet option), which means we'd need to send the whole environment with Python packages up to App Service. Not sure how you could support that in a backward compatible way.. Maybe if there's a .azdignore, it wouldnt default to ignoring anything?

@pamelafox

Here's what is excluded by default today.

All:

  • .azure folder

Python:

  • __pycache__
  • any virtual env

Node:

  • node_modules

Will update logic to:

If user has .azdignore, then only ignore .azure by default. Don't ignore __pycache__, venvs, and node_modules, they will need to ignore the folders themselves.

@jongio
Copy link
Member Author

jongio commented Aug 26, 2024

We just had a design discussion for this:

  1. I'm going to follow up with the app service team to see if they support an ignore file for zip deployments.
  2. If not, I will change the impl to support a .zipignore file in the project and honor that during zip packaging.
  3. I'll break the azd init ignore and the azd package ignore into two different efforts.
  4. I'll investigate what will happen if we implement .zipignore and the user uses the GH Action to zip deploy the app service instead of azd.

@azure-sdk
Copy link
Collaborator

Azure Dev CLI Install Instructions

Install scripts

MacOS/Linux

May elevate using sudo on some platforms and configurations

bash:

curl -fsSL https://azuresdkreleasepreview.blob.core.windows.net/azd/standalone/pr/4146/uninstall-azd.sh | bash;
curl -fsSL https://azuresdkreleasepreview.blob.core.windows.net/azd/standalone/pr/4146/install-azd.sh | bash -s -- --base-url https://azuresdkreleasepreview.blob.core.windows.net/azd/standalone/pr/4146 --version '' --verbose --skip-verify

pwsh:

Invoke-RestMethod 'https://azuresdkreleasepreview.blob.core.windows.net/azd/standalone/pr/4146/uninstall-azd.ps1' -OutFile uninstall-azd.ps1; ./uninstall-azd.ps1
Invoke-RestMethod 'https://azuresdkreleasepreview.blob.core.windows.net/azd/standalone/pr/4146/install-azd.ps1' -OutFile install-azd.ps1; ./install-azd.ps1 -BaseUrl 'https://azuresdkreleasepreview.blob.core.windows.net/azd/standalone/pr/4146' -Version '' -SkipVerify -Verbose

Windows

PowerShell install

powershell -c "Set-ExecutionPolicy Bypass Process; irm 'https://azuresdkreleasepreview.blob.core.windows.net/azd/standalone/pr/4146/uninstall-azd.ps1' > uninstall-azd.ps1; ./uninstall-azd.ps1;"
powershell -c "Set-ExecutionPolicy Bypass Process; irm 'https://azuresdkreleasepreview.blob.core.windows.net/azd/standalone/pr/4146/install-azd.ps1' > install-azd.ps1; ./install-azd.ps1 -BaseUrl 'https://azuresdkreleasepreview.blob.core.windows.net/azd/standalone/pr/4146' -Version '' -SkipVerify -Verbose;"

MSI install

powershell -c "irm 'https://azuresdkreleasepreview.blob.core.windows.net/azd/standalone/pr/4146/azd-windows-amd64.msi' -OutFile azd-windows-amd64.msi; msiexec /i azd-windows-amd64.msi /qn"

Standalone Binary

MSI

Documentation

learn.microsoft.com documentation

title: Azure Developer CLI reference
description: This article explains the syntax and parameters for the various Azure Developer CLI commands.
author: alexwolfmsft
ms.author: alexwolf
ms.date: 08/26/2024
ms.service: azure-dev-cli
ms.topic: conceptual
ms.custom: devx-track-azdevcli

Azure Developer CLI reference

This article explains the syntax and parameters for the various Azure Developer CLI commands.

azd

The Azure Developer CLI (azd) is an open-source tool that helps onboard and manage your application on Azure

Options

  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --docs         Opens the documentation for azd in your web browser.
  -h, --help         Gets help for azd.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.

See also

  • azd auth: Authenticate with Azure.
  • azd config: Manage azd configurations (ex: default Azure subscription, location).
  • azd deploy: Deploy the application's code to Azure.
  • azd down: Delete Azure resources for an application.
  • azd env: Manage environments.
  • azd hooks: Develop, test and run hooks for an application. (Beta)
  • azd init: Initialize a new application.
  • azd monitor: Monitor a deployed application. (Beta)
  • azd package: Packages the application's code to be deployed to Azure. (Beta)
  • azd pipeline: Manage and configure your deployment pipelines. (Beta)
  • azd provision: Provision the Azure resources for an application.
  • azd restore: Restores the application's dependencies. (Beta)
  • azd show: Display information about your app and its resources.
  • azd template: Find and view template details. (Beta)
  • azd up: Provision Azure resources, and deploy your project with a single command.
  • azd version: Print the version number of Azure Developer CLI.

azd auth

Authenticate with Azure.

Options

      --docs   Opens the documentation for azd auth in your web browser.
  -h, --help   Gets help for auth.

Options inherited from parent commands

  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.

See also

azd auth login

Log in to Azure.

Synopsis

Log in to Azure.

When run without any arguments, log in interactively using a browser. To log in using a device code, pass
--use-device-code.

To log in as a service principal, pass --client-id and --tenant-id as well as one of: --client-secret,
--client-certificate, or --federated-credential-provider.

To log in using a managed identity, pass --managed-identity, which will use the system assigned managed identity.
To use a user assigned managed identity, pass --client-id in addition to --managed-identity with the client id of
the user assigned managed identity you wish to use.

azd auth login [flags]

Options

      --check-status                           Checks the log-in status instead of logging in.
      --client-certificate string              The path to the client certificate for the service principal to authenticate with.
      --client-id string                       The client id for the service principal to authenticate with.
      --client-secret string                   The client secret for the service principal to authenticate with. Set to the empty string to read the value from the console.
      --docs                                   Opens the documentation for azd auth login in your web browser.
      --federated-credential-provider string   The provider to use to acquire a federated token to authenticate with.
  -h, --help                                   Gets help for login.
      --managed-identity                       Use a managed identity to authenticate.
      --redirect-port int                      Choose the port to be used as part of the redirect URI during interactive login.
      --tenant-id string                       The tenant id or domain name to authenticate with.
      --use-device-code[=true]                 When true, log in by using a device code instead of a browser.

Options inherited from parent commands

  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.

See also

azd auth logout

Log out of Azure.

Synopsis

Log out of Azure

azd auth logout [flags]

Options

      --docs   Opens the documentation for azd auth logout in your web browser.
  -h, --help   Gets help for logout.

Options inherited from parent commands

  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.

See also

azd config

Manage azd configurations (ex: default Azure subscription, location).

Synopsis

Manage the Azure Developer CLI user configuration, which includes your default Azure subscription and location.

Available since azure-dev-cli_0.4.0-beta.1.

The easiest way to configure azd for the first time is to run azd init. The subscription and location you select will be stored in the config.json file located in the config directory. To configure azd anytime afterwards, you'll use azd config set.

The default value of the config directory is:

  • $HOME/.azd on Linux and macOS
  • %USERPROFILE%.azd on Windows

The configuration directory can be overridden by specifying a path in the AZD_CONFIG_DIR environment variable.

Options

      --docs   Opens the documentation for azd config in your web browser.
  -h, --help   Gets help for config.

Options inherited from parent commands

  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.

See also

azd config get

Gets a configuration.

Synopsis

Gets a configuration in the configuration path.

The default value of the config directory is:

  • $HOME/.azd on Linux and macOS
  • %USERPROFILE%\.azd on Windows

The configuration directory can be overridden by specifying a path in the AZD_CONFIG_DIR environment variable.

azd config get <path> [flags]

Options

      --docs   Opens the documentation for azd config get in your web browser.
  -h, --help   Gets help for get.

Options inherited from parent commands

  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.

See also

azd config list-alpha

Display the list of available features in alpha stage.

azd config list-alpha [flags]

Options

      --docs   Opens the documentation for azd config list-alpha in your web browser.
  -h, --help   Gets help for list-alpha.

Options inherited from parent commands

  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.

See also

azd config reset

Resets configuration to default.

Synopsis

Resets all configuration in the configuration path.

The default value of the config directory is:

  • $HOME/.azd on Linux and macOS
  • %USERPROFILE%\.azd on Windows

The configuration directory can be overridden by specifying a path in the AZD_CONFIG_DIR environment variable to the default.

azd config reset [flags]

Options

      --docs    Opens the documentation for azd config reset in your web browser.
  -f, --force   Force reset without confirmation.
  -h, --help    Gets help for reset.

Options inherited from parent commands

  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.

See also

azd config set

Sets a configuration.

Synopsis

Sets a configuration in the configuration path.

The default value of the config directory is:

  • $HOME/.azd on Linux and macOS
  • %USERPROFILE%\.azd on Windows

The configuration directory can be overridden by specifying a path in the AZD_CONFIG_DIR environment variable.

azd config set <path> <value> [flags]

Examples

azd config set defaults.subscription <yourSubscriptionID>
azd config set defaults.location eastus

Options

      --docs   Opens the documentation for azd config set in your web browser.
  -h, --help   Gets help for set.

Options inherited from parent commands

  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.

See also

azd config show

Show all the configuration values.

Synopsis

Show all configuration values in the configuration path.

The default value of the config directory is:

  • $HOME/.azd on Linux and macOS
  • %USERPROFILE%\.azd on Windows

The configuration directory can be overridden by specifying a path in the AZD_CONFIG_DIR environment variable.

azd config show [flags]

Options

      --docs   Opens the documentation for azd config show in your web browser.
  -h, --help   Gets help for show.

Options inherited from parent commands

  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.

See also

azd config unset

Unsets a configuration.

Synopsis

Removes a configuration in the configuration path.

The default value of the config directory is:

  • $HOME/.azd on Linux and macOS
  • %USERPROFILE%\.azd on Windows

The configuration directory can be overridden by specifying a path in the AZD_CONFIG_DIR environment variable.

azd config unset <path> [flags]

Examples

azd config unset defaults.location

Options

      --docs   Opens the documentation for azd config unset in your web browser.
  -h, --help   Gets help for unset.

Options inherited from parent commands

  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.

See also

azd deploy

Deploy the application's code to Azure.

azd deploy <service> [flags]

Options

      --all                   Deploys all services that are listed in azure.yaml
      --docs                  Opens the documentation for azd deploy in your web browser.
  -e, --environment string    The name of the environment to use.
      --from-package string   Deploys the application from an existing package.
  -h, --help                  Gets help for deploy.

Options inherited from parent commands

  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.

See also

azd down

Delete Azure resources for an application.

azd down [flags]

Options

      --docs                 Opens the documentation for azd down in your web browser.
  -e, --environment string   The name of the environment to use.
      --force                Does not require confirmation before it deletes resources.
  -h, --help                 Gets help for down.
      --purge                Does not require confirmation before it permanently deletes resources that are soft-deleted by default (for example, key vaults).

Options inherited from parent commands

  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.

See also

azd env

Manage environments.

Options

      --docs   Opens the documentation for azd env in your web browser.
  -h, --help   Gets help for env.

Options inherited from parent commands

  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.

See also

azd env get-value

Get specific environment value.

azd env get-value <keyName> [flags]

Options

      --docs                 Opens the documentation for azd env get-value in your web browser.
  -e, --environment string   The name of the environment to use.
  -h, --help                 Gets help for get-value.

Options inherited from parent commands

  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.

See also

azd env get-values

Get all environment values.

azd env get-values [flags]

Options

      --docs                 Opens the documentation for azd env get-values in your web browser.
  -e, --environment string   The name of the environment to use.
  -h, --help                 Gets help for get-values.

Options inherited from parent commands

  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.

See also

azd env list

List environments.

azd env list [flags]

Options

      --docs   Opens the documentation for azd env list in your web browser.
  -h, --help   Gets help for list.

Options inherited from parent commands

  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.

See also

azd env new

Create a new environment and set it as the default.

azd env new <environment> [flags]

Options

      --docs                  Opens the documentation for azd env new in your web browser.
  -h, --help                  Gets help for new.
  -l, --location string       Azure location for the new environment
      --subscription string   Name or ID of an Azure subscription to use for the new environment

Options inherited from parent commands

  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.

See also

azd env refresh

Refresh environment settings by using information from a previous infrastructure provision.

azd env refresh <environment> [flags]

Options

      --docs                 Opens the documentation for azd env refresh in your web browser.
  -e, --environment string   The name of the environment to use.
  -h, --help                 Gets help for refresh.
      --hint string          Hint to help identify the environment to refresh

Options inherited from parent commands

  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.

See also

azd env select

Set the default environment.

azd env select <environment> [flags]

Options

      --docs   Opens the documentation for azd env select in your web browser.
  -h, --help   Gets help for select.

Options inherited from parent commands

  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.

See also

azd env set

Manage your environment settings.

azd env set <key> <value> [flags]

Options

      --docs                 Opens the documentation for azd env set in your web browser.
  -e, --environment string   The name of the environment to use.
  -h, --help                 Gets help for set.

Options inherited from parent commands

  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.

See also

azd hooks

Develop, test and run hooks for an application. (Beta)

Options

      --docs   Opens the documentation for azd hooks in your web browser.
  -h, --help   Gets help for hooks.

Options inherited from parent commands

  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.

See also

azd hooks run

Runs the specified hook for the project and services

azd hooks run <name> [flags]

Options

      --docs                 Opens the documentation for azd hooks run in your web browser.
  -e, --environment string   The name of the environment to use.
  -h, --help                 Gets help for run.
      --platform string      Forces hooks to run for the specified platform.
      --service string       Only runs hooks for the specified service.

Options inherited from parent commands

  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.

See also

azd init

Initialize a new application.

azd init [flags]

Options

  -b, --branch string         The template branch to initialize from. Must be used with a template argument (--template or -t).
      --docs                  Opens the documentation for azd init in your web browser.
  -e, --environment string    The name of the environment to use.
  -f, --filter strings        The tag(s) used to filter template results. Supports comma-separated values.
      --from-code             Initializes a new application from your existing code.
  -h, --help                  Gets help for init.
  -l, --location string       Azure location for the new environment
  -s, --subscription string   Name or ID of an Azure subscription to use for the new environment
  -t, --template string       Initializes a new application from a template. You can use Full URI, <owner>/<repository>, or <repository> if it's part of the azure-samples organization.

Options inherited from parent commands

  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.

See also

azd monitor

Monitor a deployed application. (Beta)

azd monitor [flags]

Options

      --docs                 Opens the documentation for azd monitor in your web browser.
  -e, --environment string   The name of the environment to use.
  -h, --help                 Gets help for monitor.
      --live                 Open a browser to Application Insights Live Metrics. Live Metrics is currently not supported for Python apps.
      --logs                 Open a browser to Application Insights Logs.
      --overview             Open a browser to Application Insights Overview Dashboard.

Options inherited from parent commands

  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.

See also

azd package

Packages the application's code to be deployed to Azure. (Beta)

azd package <service> [flags]

Options

      --all                  Packages all services that are listed in azure.yaml
      --docs                 Opens the documentation for azd package in your web browser.
  -e, --environment string   The name of the environment to use.
  -h, --help                 Gets help for package.
      --output-path string   File or folder path where the generated packages will be saved.

Options inherited from parent commands

  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.

See also

azd pipeline

Manage and configure your deployment pipelines. (Beta)

Options

      --docs   Opens the documentation for azd pipeline in your web browser.
  -h, --help   Gets help for pipeline.

Options inherited from parent commands

  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.

See also

azd pipeline config

Configure your deployment pipeline to connect securely to Azure. (Beta)

azd pipeline config [flags]

Options

  -m, --applicationServiceManagementReference string   Service Management Reference. References application or service contact information from a Service or Asset Management database. This value must be a Universally Unique Identifier (UUID). You can set this value globally by running azd config set pipeline.config.applicationServiceManagementReference <UUID>.
      --auth-type string                               The authentication type used between the pipeline provider and Azure for deployment (Only valid for GitHub provider). Valid values: federated, client-credentials.
      --docs                                           Opens the documentation for azd pipeline config in your web browser.
  -e, --environment string                             The name of the environment to use.
  -h, --help                                           Gets help for config.
      --principal-id string                            The client id of the service principal to use to grant access to Azure resources as part of the pipeline.
      --principal-name string                          The name of the service principal to use to grant access to Azure resources as part of the pipeline.
      --principal-role stringArray                     The roles to assign to the service principal. By default the service principal will be granted the Contributor and User Access Administrator roles. (default [Contributor,User Access Administrator])
      --provider string                                The pipeline provider to use (github for Github Actions and azdo for Azure Pipelines).
      --remote-name string                             The name of the git remote to configure the pipeline to run on. (default "origin")

Options inherited from parent commands

  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.

See also

azd provision

Provision the Azure resources for an application.

azd provision [flags]

Options

      --docs                 Opens the documentation for azd provision in your web browser.
  -e, --environment string   The name of the environment to use.
  -h, --help                 Gets help for provision.
      --no-state             Do not use latest Deployment State (bicep only).
      --preview              Preview changes to Azure resources.

Options inherited from parent commands

  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.

See also

azd restore

Restores the application's dependencies. (Beta)

azd restore <service> [flags]

Options

      --all                  Restores all services that are listed in azure.yaml
      --docs                 Opens the documentation for azd restore in your web browser.
  -e, --environment string   The name of the environment to use.
  -h, --help                 Gets help for restore.

Options inherited from parent commands

  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.

See also

azd show

Display information about your app and its resources.

azd show [flags]

Options

      --docs                 Opens the documentation for azd show in your web browser.
  -e, --environment string   The name of the environment to use.
  -h, --help                 Gets help for show.

Options inherited from parent commands

  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.

See also

azd template

Find and view template details. (Beta)

Options

      --docs   Opens the documentation for azd template in your web browser.
  -h, --help   Gets help for template.

Options inherited from parent commands

  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.

See also

azd template list

Show list of sample azd templates. (Beta)

azd template list [flags]

Options

      --docs             Opens the documentation for azd template list in your web browser.
  -f, --filter strings   The tag(s) used to filter template results. Supports comma-separated values.
  -h, --help             Gets help for list.
  -s, --source string    Filters templates by source.

Options inherited from parent commands

  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.

See also

azd template show

Show details for a given template. (Beta)

azd template show <template> [flags]

Options

      --docs   Opens the documentation for azd template show in your web browser.
  -h, --help   Gets help for show.

Options inherited from parent commands

  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.

See also

azd template source

View and manage template sources. (Beta)

Options

      --docs   Opens the documentation for azd template source in your web browser.
  -h, --help   Gets help for source.

Options inherited from parent commands

  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.

See also

azd template source add

Adds an azd template source at the specified key (Beta)

azd template source add <key> [flags]

Options

      --docs              Opens the documentation for azd template source add in your web browser.
  -h, --help              Gets help for add.
  -l, --location string   Location of the template source.
  -n, --name string       Display name of the template source.
  -t, --type string       Kind of the template source.

Options inherited from parent commands

  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.

See also

azd template source list

Lists the configured azd template sources. (Beta)

azd template source list [flags]

Options

      --docs   Opens the documentation for azd template source list in your web browser.
  -h, --help   Gets help for list.

Options inherited from parent commands

  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.

See also

azd template source remove

Removes the specified azd template source (Beta)

azd template source remove <key> [flags]

Options

      --docs   Opens the documentation for azd template source remove in your web browser.
  -h, --help   Gets help for remove.

Options inherited from parent commands

  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.

See also

azd up

Provision Azure resources, and deploy your project with a single command.

azd up [flags]

Options

      --docs                 Opens the documentation for azd up in your web browser.
  -e, --environment string   The name of the environment to use.
  -h, --help                 Gets help for up.

Options inherited from parent commands

  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.

See also

azd version

Print the version number of Azure Developer CLI.

azd version [flags]

Options

      --docs   Opens the documentation for azd version in your web browser.
  -h, --help   Gets help for version.

Options inherited from parent commands

  -C, --cwd string   Sets the current working directory.
      --debug        Enables debugging and diagnostics logging.
      --no-prompt    Accepts the default value instead of prompting, or it fails if there is no default.

See also

@jongio
Copy link
Member Author

jongio commented Aug 29, 2024

.zipignore PR #4258

Copy link
Contributor

@wbreza wbreza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall but have some comments listed below.

Comment on lines +89 to +97
ignoreMatcher, err := azdignore.ReadIgnoreFiles(staging)
if err != nil && !os.IsNotExist(err) {
return fmt.Errorf("reading .azdignore file: %w", err)
}

err = azdignore.RemoveIgnoredFiles(staging, ignoreMatcher)
if err != nil {
return fmt.Errorf("removing ignored files: %w", err)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like the RemoveIgnoredFiles should internally determine the files to ignore from a file path instead of having to read them and pass them in.

}

// RemoveIgnoredFiles removes files and directories based on .azdignore rules using a pre-collected list of paths.
func RemoveIgnoredFiles(staging string, ignoreMatchers []gitignore.GitIgnore) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: consider renaming this to stagingPath to be more clear that it is a file path.

Suggested change
func RemoveIgnoredFiles(staging string, ignoreMatchers []gitignore.GitIgnore) error {
func RemoveIgnoredFiles(stagingPath string, ignoreMatchers []gitignore.GitIgnore) error {

}

// ShouldIgnore checks if a file or directory should be ignored based on a slice of gitignore.GitIgnore structures.
func ShouldIgnore(path string, isDir bool, ignoreMatchers []gitignore.GitIgnore) bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Consider not exporting this function (make lowercase) if its only used internally within the package.

}

// CollectFilePaths collects all file and directory paths under the given root directory.
func CollectFilePaths(root string) ([]string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Same as previous comment about not exporting function.

Comment on lines +86 to +88
if filepath.Base(path) == ".azdignore" {
return true
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we ever land on whether we were going to call this .zipignore or not? Or look into if app service has any existing behavior we could snap to?

"github.com/stretchr/testify/require"
)

func TestAbsolute(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Test function naming.

Suggested change
func TestAbsolute(t *testing.T) {
func Test_Absolute(t *testing.T) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for other unit tests function names.

Comment on lines +222 to +257
files := map[string]string{
"azure.yaml": "azure content",
"infra/main.bicep": "main bicep content",
".azdignore": `*.log
tmp/*
!tmp/important.txt
*.bak
nested/*/
secret.yaml
exactfile.txt
/level1/level2/file.txt
*.hidden
/foo/*
!.gitignore
**/foo/bar
!/foo/bar.baz
abc/**/def
a?c.txt`,
"error.log": "log content",
"tmp/ignored.txt": "should be ignored",
"tmp/important.txt": "should not be ignored",
"backup.bak": "backup content",
"nested/dir1/ignored.file": "should be ignored",
"nested/dir2/ignored.file": "should be ignored",
"nested/dir3/important.txt": "should be ignored",
"secret.yaml": "secret content",
"exactfile.txt": "exact file match",
"level1/level2/file.txt": "specific path match",
"hidden.hidden": "hidden file match",
"foo/ignore.txt": "foo directory ignored",
"foo/bar": "foo/bar file ignored",
"foo/bar.baz": "foo/bar.baz file not ignored",
"abc/some/def/file.txt": "nested match with wildcards",
"acc.txt": "single character wildcard match",
"abc.txt": "single character wildcard match",
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider moving this .azdignore sample to a file.

@Petermarcu
Copy link
Member

Is zip too specific and this is more of a ignore on deploy in azd terms? deployignore? Will we use a similar concept if the output is not in the form of a zip file in the future? Even just a lose folder of files that is ready to deploy?

@jongio
Copy link
Member Author

jongio commented Aug 29, 2024

Focusing on .zipignore in other PR. Closing this for now. #4258

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Issue] azd init should ignore some files
8 participants