-
Notifications
You must be signed in to change notification settings - Fork 757
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add experimental 'local-deploy' command group to Bicep CLI (#14243)
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`: ```json { "experimentalFeaturesEnabled": { "extensibility": true, "localDeploy": true, "providerRegistry": true } } ``` * `main.bicep`: ```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`: ```bicep using 'main.bicep' param coords = { lattitude: '47.6363726' longitude: '-122.1357068' } ``` * CLI command: ```sh ~/.azure/bin/bicep local-deploy ~/path/to/main.bicepparam ``` ###### Microsoft Reviewers: [Open in CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/Azure/bicep/pull/14243)
- Loading branch information
1 parent
664d4db
commit 91b64d4
Showing
85 changed files
with
33,495 additions
and
1,216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/Bicep.Cli.E2eTests/src/examples/local-deploy/bicepconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"experimentalFeaturesEnabled": { | ||
"extensibility": true, | ||
"providerRegistry": true, | ||
"localDeploy": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
provider '../../temp/local-deploy/provider.tgz' | ||
|
||
param payload string | ||
|
||
resource sayHi 'echo' = { | ||
payload: payload | ||
} | ||
|
||
output sayHiResult string = sayHi.payload |
3 changes: 3 additions & 0 deletions
3
src/Bicep.Cli.E2eTests/src/examples/local-deploy/main.bicepparam
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
using 'main.bicep' | ||
|
||
param payload = 'Hello, World!' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
/** | ||
* Tests for "bicep local-deploy". | ||
* | ||
* @group CI | ||
*/ | ||
|
||
import spawn from "cross-spawn"; | ||
import os from "os"; | ||
import path from "path"; | ||
import { invokingBicepCommand } from "./utils/command"; | ||
import { | ||
ensureParentDirExists, | ||
expectFileExists, | ||
pathToExampleFile, | ||
pathToTempFile, | ||
} from "./utils/fs"; | ||
|
||
const itif = (condition: boolean) => condition ? it : it.skip; | ||
const cliDotnetRid = process.env.BICEP_CLI_DOTNET_RID; | ||
// We don't have an easy way of running this test for linux-musl-x64 RID, so skip for now. | ||
const canRunLocalDeploy = () => !cliDotnetRid || architectures.map(x => x.dotnetRid).includes(cliDotnetRid); | ||
|
||
const mockExtensionExeName = 'bicep-ext-mock'; | ||
const mockExtensionProjPath = path.resolve( | ||
__dirname, | ||
"../../Bicep.Local.Extension.Mock" | ||
); | ||
|
||
const architectures = [ | ||
{ dotnetRid: 'osx-arm64', bicepArgs: ['--bin-osx-arm64', `${mockExtensionProjPath}/bin/release/net8.0/osx-arm64/publish/${mockExtensionExeName}`] }, | ||
{ dotnetRid: 'osx-x64', bicepArgs: ['--bin-osx-x64', `${mockExtensionProjPath}/bin/release/net8.0/osx-x64/publish/${mockExtensionExeName}`] }, | ||
{ dotnetRid: 'linux-x64', bicepArgs: ['--bin-linux-x64', `${mockExtensionProjPath}/bin/release/net8.0/linux-x64/publish/${mockExtensionExeName}`] }, | ||
{ dotnetRid: 'win-x64', bicepArgs: ['--bin-win-x64', `${mockExtensionProjPath}/bin/release/net8.0/win-x64/publish/${mockExtensionExeName}.exe`] }, | ||
]; | ||
|
||
describe("bicep local-deploy", () => { | ||
itif(canRunLocalDeploy())("should build and deploy a provider published to the local file system", () => { | ||
|
||
for (const arch of architectures) { | ||
execDotnet(['publish', '--verbosity', 'quiet', '--configuration', 'release', '--self-contained', 'true', '-r', arch.dotnetRid, mockExtensionProjPath]); | ||
} | ||
|
||
const typesIndexPath = pathToTempFile("local-deploy", "types", "index.json"); | ||
const typesDir = path.dirname(typesIndexPath); | ||
ensureParentDirExists(typesIndexPath); | ||
|
||
execDotnet(['run', '--verbosity', 'quiet', '--project', mockExtensionProjPath], { | ||
MOCK_TYPES_OUTPUT_PATH: typesDir, | ||
}); | ||
|
||
const targetPath = pathToTempFile("local-deploy", "provider.tgz"); | ||
|
||
invokingBicepCommand( | ||
"publish-provider", | ||
typesIndexPath, | ||
"--target", | ||
targetPath, | ||
...(architectures.flatMap(arch => arch.bicepArgs)) | ||
) | ||
.shouldSucceed() | ||
.withEmptyStdout(); | ||
|
||
expectFileExists(targetPath); | ||
|
||
const bicepparamFilePath = pathToExampleFile("local-deploy", "main.bicepparam"); | ||
|
||
invokingBicepCommand("local-deploy", bicepparamFilePath) | ||
.shouldSucceed() | ||
.withStdout([ | ||
'Output sayHiResult: "Hello, World!"', | ||
'Resource sayHi (Create): Succeeded', | ||
'Result: Succeeded', | ||
'' | ||
].join(os.EOL)); | ||
}); | ||
}); | ||
|
||
function execDotnet(args: string[], envOverrides?: NodeJS.ProcessEnv) { | ||
const result = spawn.sync('dotnet', args, { | ||
encoding: 'utf-8', | ||
stdio: 'inherit', | ||
env: { | ||
...process.env, | ||
...(envOverrides ?? {}) | ||
} | ||
}); | ||
expect(result.status).toBe(0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.