Skip to content

Add experimental 'local-deploy' command group to Bicep CLI - #14243

Merged
Anthony Martin (anthony-c-martin) merged 5 commits into
mainfrom
ant/local_cli
Jun 7, 2024
Merged

Anthony Martin (anthony-c-martin) merged 5 commits into
mainfrom
ant/local_cli

Conversation

@anthony-c-martin

@anthony-c-martin Anthony Martin (anthony-c-martin) commented Jun 5, 2024 •

Copy link
Copy Markdown
Member

This change brings in the following:

  • New local-deploy command group to deploy a Bicep file using the local extensibility preview.
  • Additions to publish-provider command group to allow publishing a binary extension to an ACR or to file system.

To test it out (see "Test this change out" comment below first):

  • bicepconfig.json:
    {
      "experimentalFeaturesEnabled": {
        "extensibility": true,
        "localDeploy": true,
        "providerRegistry": true
      }
    }
  • main.bicep:
    provider 'br:biceplocaldeploy.azurecr.io/providers/http:0.1.9'
    
    param coords {
      lattitude: string
      longitude: string
    }
    
    resource gridpointsReq 'HttpRequest' = {
      uri: 'https://api.weather.gov/points/${coords.lattitude},${coords.longitude}'
      format: 'raw'
    }
    
    var gridpoints = json(gridpointsReq.body).properties
    
    resource forecastReq 'HttpRequest' = {
      uri: 'https://api.weather.gov/gridpoints/${gridpoints.gridId}/${gridpoints.gridX},${gridpoints.gridY}/forecast'
      format: 'raw'
    }
    
    var forecast = json(forecastReq.body).properties
    
    type forecastType = {
      name: string
      temperature: int
    }
    
    output forecast forecastType[] = map(forecast.periods, p => {
      name: p.name
      temperature: p.temperature
    })
  • main.bicepparam:
    using 'main.bicep'
    
    param coords = {
      lattitude: '47.6363726'
      longitude: '-122.1357068'
    }
  • CLI command:
    ~/.azure/bin/bicep local-deploy ~/path/to/main.bicepparam
Microsoft Reviewers: Open in CodeFlow

@github-actions

github-actions Bot commented Jun 5, 2024 •

Copy link
Copy Markdown
Contributor

Test this change out locally with the following install scripts (Action run 9421684319)

VSCode
  • Mac/Linux
    bash <(curl -Ls https://aka.ms/bicep/nightly-vsix.sh) --run-id 9421684319
  • Windows
    iex "& { $(irm https://aka.ms/bicep/nightly-vsix.ps1) } -RunId 9421684319"
Azure CLI
  • Mac/Linux
    bash <(curl -Ls https://aka.ms/bicep/nightly-cli.sh) --run-id 9421684319
  • Windows
    iex "& { $(irm https://aka.ms/bicep/nightly-cli.ps1) } -RunId 9421684319"

@github-actions

github-actions Bot commented Jun 5, 2024 •

Copy link
Copy Markdown
Contributor

Dotnet Test Results

    72 files   -     36      72 suites   - 36   23m 12s ⏱️ - 9m 3s
10 878 tests  -     19  10 877 ✅  -     19  1 💤 ±0  0 ❌ ±0 
25 652 runs   - 12 819  25 650 ✅  - 12 818  2 💤  - 1  0 ❌ ±0 

Results for commit df86f76. ± Comparison against base commit 664d4db.

♻️ This comment has been updated with latest results.

@anthony-c-martin
Anthony Martin (anthony-c-martin) force-pushed the ant/local_cli branch 8 times, most recently from e3f9cb7 to 608232b Compare June 6, 2024 18:03
@anthony-c-martin

Copy link
Copy Markdown
Member Author

The VS test failure appears to be caused by microsoft/vstest-action#31 - not a problem with the PR.

}

await dispatcher.PublishProvider(targetReference, new(tgzData));
await dispatcher.PublishProvider(targetReference, new(tgzData, false, []));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is not using named args in bicep repo the norm? In this case I had to look into what argument - in PublishProvider -corresponds to a record and find its bool argument, which corresponds to LocalDeployEnabled.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, my personal style is to avoid named args by default. I will sometimes use them if I feel like they add clarity, but IMO they often get in the way of code readability without adding any useful context.

@StephenWeatherford Stephen Weatherford (StephenWeatherford) Jun 7, 2024 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

IMHO I'd argue that having a naked "false" or "true" argument is much less readable. When possible I prefer to redesign the API (e.g. use an enum), but otherwise I like using named args or inline comments for this case.

Not that this is a big deal...

this.moduleDispatcher = moduleDispatcher;
this.providerFactory = providerFactory;
// Built in provider for handling nested deployments
RegisteredProviders[new("LocalNested", "0.0.0")] = new AzExtensibilityProvider(this);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Don't recall if we have a way to load nested deployments provider version, I think it might be good to let users decide which version to use rather than picking a specific version?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Bicep doesn't expose the nested deployment API version to end users in the module syntax, so it's not possible to pick a different version. This is by design - Bicep should be in control of the behavior; if we need to opt-in to new behavior, then we will do so in a new Bicep release.

}

return new(
Types: dataDict["types.tgz"],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is types.tgz going to contain types + providers right?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

also, is it possible for types.tgz to not be present in the dict and a key not found exception to be thrown?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, the error handling here could use some work before we remove the "experimental" feature flag.

@anthony-c-martin
Anthony Martin (anthony-c-martin) force-pushed the ant/local_cli branch 3 times, most recently from ee3d413 to dac6641 Compare June 7, 2024 13:34
@anthony-c-martin
Anthony Martin (anthony-c-martin) force-pushed the ant/local_cli branch 4 times, most recently from 3c86a4f to 21eb401 Compare June 7, 2024 15:38

@shenglol Shenglong Li (shenglol) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

:shipit:

return null;
}

var data = BinaryData.FromStream(fileSystem.FileStream.New(PathHelper.ResolvePath(binaryPath), FileMode.Open, FileAccess.Read, FileShare.Read));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"using" to close the stream?


this.EmitDependsOn(emitter, module.DependsOn);

// Since we don't want to be mutating the body of the original ObjectSyntax, we create an placeholder body in place

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit

Suggested change
// Since we don't want to be mutating the body of the original ObjectSyntax, we create an placeholder body in place
// Since we don't want to be mutating the body of the original ObjectSyntax, we create a placeholder body in place

{
if (SupportedArchitectures.TryGetCurrent() is not {} architecture)
{
throw new InvalidOperationException($"Unsupported architecture: {RuntimeInformation.ProcessArchitecture}");

@StephenWeatherford Stephen Weatherford (StephenWeatherford) Jun 7, 2024 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Probably these error messages should be different, different causes.

@@ -0,0 +1,102 @@
// Copyright (c) Microsoft Corporation.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I didn't see this documented for --help. I assume that's intentional for now?

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.

4 participants