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 experimental 'local-deploy' command group to Bicep CLI #14243

Merged
merged 5 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add e2e CLI test for local-deploy
  • Loading branch information
anthony-c-martin committed Jun 7, 2024
commit df86f76aebbcf72bbba0a709509d9c3069374dca
8 changes: 8 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,9 @@ jobs:
fetch-depth: 0 # avoid shallow clone so nbgv can do its work.
submodules: true

- name: Setup .NET Core
uses: actions/setup-dotnet@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
Expand Down Expand Up @@ -600,6 +603,7 @@ jobs:
entrypoint: sh
args: -c "apk add --update nodejs npm && npm ci --prefix ./src/Bicep.Cli.E2eTests && npm test --prefix ./src/Bicep.Cli.E2eTests"
env:
BICEP_CLI_DOTNET_RID: ${{ matrix.runtime.rid }}
BICEP_CLI_EXECUTABLE: ../../../Bicep.Cli.E2eTests/src/temp/bicep-cli/bicep

test-dotnet:
Expand Down Expand Up @@ -762,6 +766,9 @@ jobs:
with:
node-version: 18

- name: Setup .NET Core
uses: actions/setup-dotnet@v4

- name: Download Bicep CLI
uses: actions/download-artifact@v4
with:
Expand Down Expand Up @@ -829,5 +836,6 @@ jobs:
- name: Run Bicep Live E2E Tests (${{ matrix.environment }})
run: npm ci && npm run test:live:${{ matrix.environment }}
env:
BICEP_CLI_DOTNET_RID: ${{ matrix.runtime.rid }}
BICEP_CLI_EXECUTABLE: ../../../Bicep.Cli.E2eTests/src/temp/bicep-cli/bicep
working-directory: ./src/Bicep.Cli.E2eTests
7 changes: 7 additions & 0 deletions Bicep.sln
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bicep.Local.Deploy", "src\B
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bicep.Local.Deploy.IntegrationTests", "src\Bicep.Local.Deploy.IntegrationTests\Bicep.Local.Deploy.IntegrationTests.csproj", "{3F25D072-7A7E-419D-8425-6F2C7CF42BFD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bicep.Local.Extension.Mock", "src\Bicep.Local.Extension.Mock\Bicep.Local.Extension.Mock.csproj", "{A7D359D9-654A-4FAF-9BC2-DA9667EF8756}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -189,6 +191,10 @@ Global
{3F25D072-7A7E-419D-8425-6F2C7CF42BFD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3F25D072-7A7E-419D-8425-6F2C7CF42BFD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3F25D072-7A7E-419D-8425-6F2C7CF42BFD}.Release|Any CPU.Build.0 = Release|Any CPU
{A7D359D9-654A-4FAF-9BC2-DA9667EF8756}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A7D359D9-654A-4FAF-9BC2-DA9667EF8756}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A7D359D9-654A-4FAF-9BC2-DA9667EF8756}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A7D359D9-654A-4FAF-9BC2-DA9667EF8756}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -217,6 +223,7 @@ Global
{E84C0368-0D02-4284-A3CB-110B14FA8314} = {8F8DCFBC-A0DC-4E40-93C8-B4FB99FBD757}
{3F3A6387-DD5F-40A6-89D1-92653E4872D3} = {8F8DCFBC-A0DC-4E40-93C8-B4FB99FBD757}
{3F25D072-7A7E-419D-8425-6F2C7CF42BFD} = {8F8DCFBC-A0DC-4E40-93C8-B4FB99FBD757}
{A7D359D9-654A-4FAF-9BC2-DA9667EF8756} = {8F8DCFBC-A0DC-4E40-93C8-B4FB99FBD757}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {21F77282-91E7-4304-B1EF-FADFA4F39E37}
Expand Down
4 changes: 2 additions & 2 deletions src/Bicep.Cli.E2eTests/src/examples/101/aks.prod/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.23.35.39852",
"templateHash": "6457398673135247172"
"version": "0.28.8.24706",
"templateHash": "13279681427225276221"
}
},
"parameters": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"experimentalFeaturesEnabled": {
"extensibility": true,
"providerRegistry": true,
"localDeploy": true
}
}
9 changes: 9 additions & 0 deletions src/Bicep.Cli.E2eTests/src/examples/local-deploy/main.bicep
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using 'main.bicep'

param payload = 'Hello, World!'
91 changes: 91 additions & 0 deletions src/Bicep.Cli.E2eTests/src/localDeploy.test.ts
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);
}
2 changes: 1 addition & 1 deletion src/Bicep.Cli.E2eTests/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"moduleResolution": "node",
"esModuleInterop": true,
"outDir": "out",
"lib": ["es2016"],
"lib": ["es2019"],
"sourceMap": true,
"skipLibCheck": true,
"strict": true,
Expand Down
4 changes: 2 additions & 2 deletions src/Bicep.Cli/Commands/LocalDeployCommand.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) Microsoft Corporation.
Copy link
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?

// Licensed under the MIT License.

using Azure.Bicep.Local.Deploy;
using Azure.Bicep.Local.Deploy.Extensibility;
using Bicep.Local.Deploy;
using Bicep.Local.Deploy.Extensibility;
using Azure.Deployments.Core.Json;
using Bicep.Cli.Arguments;
using Bicep.Cli.Helpers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
using Bicep.Core.UnitTests.Assertions;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Azure.Bicep.Local.Deploy.Extensibility;
using Azure.Bicep.Local.Deploy;
using Bicep.Local.Deploy.Extensibility;
using Bicep.Local.Deploy;
using Bicep.Core.UnitTests.Utils;
using Azure.Deployments.Core.Definitions;
using Bicep.Local.Extension;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
using Microsoft.WindowsAzure.ResourceStack.Common.Json;
using Newtonsoft.Json.Linq;

namespace Azure.Bicep.Local.Deploy.Extensibility;
namespace Bicep.Local.Deploy.Extensibility;

public class AzExtensibilityProvider : LocalExtensibilityProvider
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
using Data = Azure.Deployments.Extensibility.Data;
using Rpc = Bicep.Local.Extension.Rpc;

namespace Azure.Bicep.Local.Deploy.Extensibility;
namespace Bicep.Local.Deploy.Extensibility;

public class GrpcExtensibilityProvider : LocalExtensibilityProvider
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
using Microsoft.WindowsAzure.ResourceStack.Common.Utilities;
using IAsyncDisposable = System.IAsyncDisposable;

namespace Azure.Bicep.Local.Deploy.Extensibility;
namespace Bicep.Local.Deploy.Extensibility;

public class LocalExtensibilityHandler : IAsyncDisposable
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Azure.Deployments.Extensibility.Contract;
using Azure.Deployments.Extensibility.Messages;

namespace Azure.Bicep.Local.Deploy.Extensibility;
namespace Bicep.Local.Deploy.Extensibility;

public abstract class LocalExtensibilityProvider : IExtensibilityProvider, IAsyncDisposable
{
Expand Down
4 changes: 2 additions & 2 deletions src/Bicep.Local.Deploy/IServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
using Microsoft.WindowsAzure.ResourceStack.Common.EventSources;
using Microsoft.WindowsAzure.ResourceStack.Common.Storage.Volatile;
using Azure.Deployments.Extensibility.Contract;
using Azure.Bicep.Local.Deploy.Extensibility;
using Bicep.Local.Deploy.Extensibility;

namespace Azure.Bicep.Local.Deploy;
namespace Bicep.Local.Deploy;

public static class IServiceCollectionExtensions
{
Expand Down
4 changes: 2 additions & 2 deletions src/Bicep.Local.Deploy/LocalDeployment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
using System.Collections.Immutable;
using System.Threading;
using System.Threading.Tasks;
using Azure.Bicep.Local.Deploy.Extensibility;
using Bicep.Local.Deploy.Extensibility;
using Azure.Deployments.Core.Definitions;
using Microsoft.Azure.Deployments.Service.Shared.Jobs;
using Microsoft.Extensions.DependencyInjection;

namespace Azure.Bicep.Local.Deploy;
namespace Bicep.Local.Deploy;

public static class LocalDeployment
{
Expand Down
2 changes: 1 addition & 1 deletion src/Bicep.Local.Deploy/LocalDeploymentConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using Azure.Deployments.Engine.Host.Azure.Interfaces;
using Azure.Deployments.Engine;

namespace Azure.Bicep.Local.Deploy;
namespace Bicep.Local.Deploy;

public class LocalDeploymentConfiguration : IAzureDeploymentConfiguration
{
Expand Down
4 changes: 2 additions & 2 deletions src/Bicep.Local.Deploy/LocalDeploymentEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using Azure.Bicep.Local.Deploy.Extensibility;
using Bicep.Local.Deploy.Extensibility;
using Azure.Deployments.Core.Definitions;
using Azure.Deployments.Core.Definitions.Schema;
using Azure.Deployments.Core.Entities;
Expand All @@ -29,7 +29,7 @@
using Microsoft.WindowsAzure.ResourceStack.Common.Instrumentation;
using Microsoft.WindowsAzure.ResourceStack.Common.Json;

namespace Azure.Bicep.Local.Deploy;
namespace Bicep.Local.Deploy;

internal class LocalDeploymentEngine
{
Expand Down
4 changes: 2 additions & 2 deletions src/Bicep.Local.Deploy/LocalDeploymentEngineHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;
using Azure.Bicep.Local.Deploy.Extensibility;
using Bicep.Local.Deploy.Extensibility;
using Azure.Deployments.Core.Definitions;
using Azure.Deployments.Core.Definitions.Identifiers;
using Azure.Deployments.Core.Definitions.Resources;
Expand Down Expand Up @@ -40,7 +40,7 @@
using Microsoft.WindowsAzure.ResourceStack.Common.Services.ADAuthentication;
using Newtonsoft.Json.Linq;

namespace Azure.Bicep.Local.Deploy;
namespace Bicep.Local.Deploy;

#nullable disable

Expand Down
2 changes: 1 addition & 1 deletion src/Bicep.Local.Deploy/LocalDeploymentSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Collections.Immutable;
using Azure.Deployments.Engine.Host.Azure.Interfaces;

namespace Azure.Bicep.Local.Deploy;
namespace Bicep.Local.Deploy;

public class LocalDeploymentSettings : IAzureDeploymentSettings
{
Expand Down
2 changes: 1 addition & 1 deletion src/Bicep.Local.Deploy/LocalKeyVaultDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using Azure.Deployments.Core.Entities;
using Azure.Deployments.Engine.Interfaces;

namespace Azure.Bicep.Local.Deploy;
namespace Bicep.Local.Deploy;

public class LocalKeyVaultDataProvider : IKeyVaultDataProvider
{
Expand Down
2 changes: 1 addition & 1 deletion src/Bicep.Local.Deploy/LocalRequestContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Azure.Deployments.Core.Helpers;
using Azure.Deployments.Engine.Host.External;

namespace Azure.Bicep.Local.Deploy;
namespace Bicep.Local.Deploy;

public class LocalRequestContext : IDeploymentsRequestContext
{
Expand Down
2 changes: 1 addition & 1 deletion src/Bicep.Local.Deploy/TraceEventSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
using Microsoft.WindowsAzure.ResourceStack.Common.EventSources;
using Newtonsoft.Json.Linq;

namespace Azure.Bicep.Local.Deploy;
namespace Bicep.Local.Deploy;

#nullable disable

Expand Down
17 changes: 17 additions & 0 deletions src/Bicep.Local.Extension.Mock/Bicep.Local.Extension.Mock.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<RootNamespace>Bicep.Local.Extension.Mock</RootNamespace>
<StartupObject>Bicep.Local.Extension.Mock.Program</StartupObject>
<AssemblyName>bicep-ext-mock</AssemblyName>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<PublishSingleFile>true</PublishSingleFile>
<InvariantGlobalization>true</InvariantGlobalization>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="../Bicep.Local.Extension/Bicep.Local.Extension.csproj" />
<ProjectReference Include="../Bicep.Core/Bicep.Core.csproj" />
<PackageReference Include="Grpc.AspNetCore" Version="2.63.0" />
</ItemGroup>
</Project>
Loading
Loading