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
388 stars 177 forks source link

Azd CLI Extensibility #810

Open rajeshkamal5050 opened 1 year ago

rajeshkamal5050 commented 1 year ago

Spike to investigate on extensibility in Azd

Use Cases

The following are a list of use cases to explore during this spike

See details below on each use case

Customer Scenarios

Subscribe to azd command hooks

For some applications it is a requirements that developers be able to run custom scripts either before or after azd commands.

This would enable many different scenarios. For example azd does not enforce any tests to be run between provision and deploy. Using pre/post command hooks would allow custom scripts to run to validate the state of an environment before moving on to deploy commands or additional stages.

Within the azure.yaml introduce a scripts section similar to that of Node applications. Scripts could either be a single, multiline script of a reference to a script that exists within the same repo.

Configuration based approach

Script section can either be defined at the root of azure.yaml or within a single service.

Root configuration

#azure.yaml 
scripts:
  preprovision: preprovision.sh      # Run terratest script to validate resources
  postprovision: postprovision.sh    # Run script to validate state of azure infra
  postdeploy: postdeploy.sh          # Run smoke tests like playwright to validate app(s) are working as expected

Service configuration

#azure.yaml 
services:
  app1:
    scripts:
      preprovision: preprovision.sh      # Run terratest script to validate resources
      postprovision: postprovision.sh    # Run script to validate state of azure infra
      postdeploy: postdeploy.sh          # Run smoke tests like playwright to validate app(s) are working as expected

Convention based approach

Another option is to use a convention based approach where we automatically look for files within the .azure/hooks folder. If we find a file called predeploy.sh we automatically wire it up as a pre deploy command hook and execute it accordingly.

Override built-in commands

This would enable more complex use cases where azd doesn't have support for a particular service target, language or similar and the dev wants to take more granular control of the workflow.


# azure.yaml
services:
  app1:
    scripts:
      provision: ./scripts/provision.sh   #custom provision script or reference to script file
      package: ./scripts/package.sh       #custom package script or reference to script file
      deploy: ./scripts/deploy.sh         #custom deploy script or reference to script file

Define custom commands

Ability to define custom commands and execute them through azd. A dev organization likely had a bunch of other scripts involved in their products that may relate to their overall platform or a specific service. It would be good for devs to be able to define their own custom azd command groups that execute scripts against their apps & infra.

More TBD.

Plugin Model

How do we allow external contributions into AZD for things like language/framework services, application targets, provisioning/pipeline providers etc?

Options

If we develop our own plug-in model the leading method for cross process communication in go is to leverage gRPC & protocol buffers. This is the same implementation used under the covers for tools like Terraform.

Protobuf establishes the interface between the client & server and communication happens via gRPC. There are well established go modules.

gRPC Go Quickstart

Technical Details

We should support a variety of script options including shell scripts & powershell.

Inputs

All scripts should be executed from azd with all values from local .env file made available.

Questions

  1. Do we need to expose any project configuration data?
  2. Can we simply leverage exit codes to dictate overall success or failure of an operation?
  3. Do we need to support output schema that is required?
anevjes commented 1 year ago

DO we know if the above extensibility model will allow us to use the logged in identity context to pass to the custom scripts?

wbreza commented 1 year ago

DO we know if the above extensibility model will allow us to use the logged in identity context to pass to the custom scripts?

@anevjes - could you give us an example of what types of calls you would like to make? REST API calls to ARM control plan or MS Graph? az cli commands or other?

rajeshkamal5050 commented 1 year ago

Moving to Gallium cc @savannahostrowski

rajeshkamal5050 commented 3 months ago

Moving this to backlog for now. We can pull this back in when we have more use-cases for core command extensibility.

Addressed - Hooks, Customizable up workflow (also enables skipping commands) Pending - Defining custom commands, Plugin model

@wbreza @kristenwomack