Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public CloudMachineInfrastructure(string? cmId = default)
AddFeature(new ServiceBusSubscriptionFeature("cm_servicebus_subscription_private", sbTopicPrivate)); // TODO: should private connections not be in the Connections collection?
AddFeature(new ServiceBusSubscriptionFeature("cm_servicebus_subscription_default", sbTopicDefault));
var systemTopic = AddFeature(new EventGridSystemTopicFeature(Id, storage, "Microsoft.Storage.StorageAccounts"));
AddFeature(new SystemTopicEventSubscriptionFeature("cm_eventgrid_subscription_blob", systemTopic, sbTopicPrivate, sbNamespace));
AddFeature(new SystemTopicEventSubscriptionFeature("cm-eventgrid-subscription-blob", systemTopic, sbTopicPrivate, sbNamespace));
}

public T AddFeature<T>(T feature) where T: CloudMachineFeature
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Azure.Provisioning.Primitives;
using Azure.Provisioning.Resources;
using Azure.Provisioning.Expressions;
using System.Linq;

namespace Azure.CloudMachine;

Expand All @@ -27,7 +28,8 @@ public static void Init(CloudMachineClient client, string? infraDirectory = defa

public static void Init(CloudMachineInfrastructure infra, string? infraDirectory = default)
{
if (infraDirectory == default) infraDirectory = Path.Combine(".", "infra");
if (infraDirectory == default)
infraDirectory = Path.Combine(".", "infra");

Directory.CreateDirectory(infraDirectory);

Expand Down Expand Up @@ -64,6 +66,28 @@ public static void Init(CloudMachineInfrastructure infra, string? infraDirectory

WriteMainParametersFile(infraDirectory);
}

public static void InitDeployment(CloudMachineInfrastructure infra, string? webProjectName)
{
var webCsproj = webProjectName switch
{
null => ".",
_ => webProjectName.EndsWith(".csproj") ? webProjectName : $"{webProjectName}.csproj"
};
var webProjDirectory = webCsproj switch
{
"." => null,
_ => Directory
.GetFiles(Directory.GetCurrentDirectory(), "*" + webCsproj, SearchOption.AllDirectories)
.SingleOrDefault()
};
if (webProjDirectory != null)
{
webProjDirectory = Path.GetDirectoryName(webProjDirectory)?.Replace(Directory.GetCurrentDirectory(), ".");
}
WriteAzureYamlFile(webProjDirectory ?? "./", infra.Id);
}

private static void WriteMainParametersFile(string infraDirectory)
{
File.WriteAllText(Path.Combine(infraDirectory, $"{MainBicepName}.parameters.json"),
Expand All @@ -85,4 +109,23 @@ private static void WriteMainParametersFile(string infraDirectory)
}
""");
}

private static void WriteAzureYamlFile(string webProjDirectory, string cmId, string? hostType = "appservice")
{
if (webProjDirectory == ".")
{
webProjDirectory = "./";
}

File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "azure.yaml"),
$"""
name: {cmId}
resourceGroup: {cmId}
services:
{cmId}:
project: {webProjDirectory} # path to your web project
language: csharp # one of the supported languages
host: {hostType} # one of the supported Azure services
""");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ public static bool Execute(string[] args, Action<CloudMachineInfrastructure>? co
return Handled(exitProcessIfHandled);
}

if (args[0] == "-init")
{
Azd.Init(cmi);

string? projName = default;
if (args.Length > 1)
{
projName = args[1];
}
Azd.InitDeployment(cmi, projName);
return Handled(exitProcessIfHandled);
}

if (args[0] == "-tsp")
{
GenerateTsp(cmi.Endpoints);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@ public void ListModels()
{
CloudMachineCommands.Execute(["-ai", "chat"], exitProcessIfHandled: false);
}

[Test]
public void DoInit()
{
CloudMachineCommands.Execute(["-init", "demo.csproj"], exitProcessIfHandled: false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ resource cm_eventgrid_topic 'Microsoft.EventGrid/systemTopics@2022-06-15' = {
}

resource cm_eventgrid_subscription_blob 'Microsoft.EventGrid/systemTopics/eventSubscriptions@2022-06-15' = {
name: 'cm_eventgrid_subscription_blob'
name: 'cm-eventgrid-subscription-blob'
properties: {
deliveryWithResourceIdentity: {
identity: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ resource cm_eventgrid_topic 'Microsoft.EventGrid/systemTopics@2022-06-15' = {
}

resource cm_eventgrid_subscription_blob 'Microsoft.EventGrid/systemTopics/eventSubscriptions@2022-06-15' = {
name: 'cm_eventgrid_subscription_blob'
name: 'cm-eventgrid-subscription-blob'
properties: {
deliveryWithResourceIdentity: {
identity: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ resource cm_eventgrid_topic 'Microsoft.EventGrid/systemTopics@2022-06-15' = {
}

resource cm_eventgrid_subscription_blob 'Microsoft.EventGrid/systemTopics/eventSubscriptions@2022-06-15' = {
name: 'cm_eventgrid_subscription_blob'
name: 'cm-eventgrid-subscription-blob'
properties: {
deliveryWithResourceIdentity: {
identity: {
Expand Down