Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<PackageVersion Include="Spectre.Console" Version="0.49.1" />
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageVersion Include="System.CommandLine.NamingConventionBinder" Version="2.0.0-beta4.22272.1" />
<PackageVersion Include="System.Management" Version="9.0.3" />
<PackageVersion Include="YamlDotNet" Version="15.1.2" />
<PackageVersion Include="TestableIO.System.IO.Abstractions.TestingHelpers" Version="21.0.2" />
<PackageVersion Include="TestableIO.System.IO.Abstractions.Wrappers" Version="21.0.2" />
Expand Down
12 changes: 6 additions & 6 deletions src/Aspirate.Cli/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"init": {
"commandName": "Project",
"commandLineArgs": "init",
"workingDirectory": "/Users/prom3theu5/git/test-compose/AspireSample/AspireSample.AppHost",
"workingDirectory": "C:\\Users\\MKvamm\\source\\repos\\RIS\\src\\Ris.AppHost",
"hotReloadEnabled": false
},
"init-non-interactive": {
Expand All @@ -14,8 +14,8 @@
},
"generate": {
"commandName": "Project",
"commandLineArgs": "generate --skip-build --output-format compose",
"workingDirectory": "/Users/prom3theu5/git/tests/new-test/AspireSample/AspireSample.AppHost",
"commandLineArgs": "generate --skip-build",
"workingDirectory": "C:\\Users\\MKvamm\\source\\repos\\RIS\\src\\Ris.AppHost",
"hotReloadEnabled": false
},
"generate-non-interactive": {
Expand Down Expand Up @@ -51,7 +51,7 @@
"apply": {
"commandName": "Project",
"commandLineArgs": "apply",
"workingDirectory": "/Users/prom3theu5/git/tests/new-test/AspireSample/AspireSample.AppHost",
"workingDirectory": "C:\\Users\\MKvamm\\source\\repos\\RIS\\src\\Ris.AppHost",
"hotReloadEnabled": false
},
"apply-non-interactive": {
Expand All @@ -63,7 +63,7 @@
"destroy": {
"commandName": "Project",
"commandLineArgs": "destroy",
"workingDirectory": "/Users/prom3theu5/git/test-compose/AspireSample/AspireSample.AppHost",
"workingDirectory": "C:\\Users\\MKvamm\\source\\repos\\RIS\\src\\Ris.AppHost",
"hotReloadEnabled": false
},
"destroy-non-interactive": {
Expand All @@ -73,4 +73,4 @@
"hotReloadEnabled": false
}
}
}
}
2 changes: 1 addition & 1 deletion src/Aspirate.Cli/Templates/deployment.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ spec:
{{#each bindMounts}}
- name: bindmount-{{@index}}
hostPath:
path: {{source}}
path: /mnt{{target}}
type: DirectoryOrCreate
{{/each}}
{{/if}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System.Reflection.Metadata.Ecma335;
using Aspirate.Shared.Models.AspireManifests.Components.Common;
using Aspirate.Shared.Models.AspireManifests.Components.Common.Container;
using Microsoft.Extensions.DependencyInjection;

namespace Aspirate.Commands.Actions.BindMounts;
public sealed class ApplyMinikubeMountsAction(
IServiceProvider serviceProvider,
IMinikubeCliService minikubeCliService) : BaseAction(serviceProvider)
{
public override async Task<bool> ExecuteAsync()
{
Logger.WriteRuler("[purple]Handling minikube mounts[/]");
await Task.Run(HandleMinikubeMounts);

return true;
}
private void HandleMinikubeMounts()
{
if (CurrentState.KubeContext != "minikube" || CurrentState.DisableMinikubeMountAction.Equals(true))
{
return;
}

Logger.MarkupLine("Applying volume mounts to minikube...");

var minikubeCliInstalled = minikubeCliService.IsMinikubeCliInstalledOnMachine();

if (!minikubeCliInstalled)
{
Logger.MarkupLine("[yellow]Minikube cli is required to perform Minikube volume mounts.[/]");
Logger.MarkupLine("[yellow]Please install minikube cli following the guide here:[blue]https://minikube.sigs.k8s.io/docs/start/?arch=%2Fwindows%2Fx86-64%2Fstable%2F.exe+download/[/][/]");
Logger.MarkupLine("[yellow]Manifest deployment will continue, but Minikube volume mounts will not be applied by aspirate.[/]");
return;
}

minikubeCliService.ActivateMinikubeMount(CurrentState);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Reflection.Metadata.Ecma335;
using Aspirate.Shared.Models.AspireManifests.Components.Common;
using Aspirate.Shared.Models.AspireManifests.Components.Common.Container;
using Microsoft.Extensions.DependencyInjection;

namespace Aspirate.Commands.Actions.BindMounts;
public sealed class KillMinikubeMountsAction(
IServiceProvider serviceProvider,
IMinikubeCliService minikubeCliService) : BaseAction(serviceProvider)
{
public override async Task<bool> ExecuteAsync()
{
Logger.WriteRuler("[purple]Handling minikube mounts[/]");

await Task.Run(HandleMinikubeMounts);

return true;
}
private void HandleMinikubeMounts()
{
if (minikubeCliService.IsMinikubeCliInstalledOnMachine() && (CurrentState.DisableMinikubeMountAction.Equals(false) || !CurrentState.DisableMinikubeMountAction.HasValue))
{
minikubeCliService.KillMinikubeMounts(CurrentState);
Logger.MarkupLine($"[green]({EmojiLiterals.CheckMark}) Done:[/] Killed minikube mount processes [blue][/]");
}
}
}
42 changes: 42 additions & 0 deletions src/Aspirate.Commands/Actions/BindMounts/SaveBindMountsAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System.Reflection.Metadata.Ecma335;
using Aspirate.Shared.Models.AspireManifests.Components.Common;
using Aspirate.Shared.Models.AspireManifests.Components.Common.Container;
using Microsoft.Extensions.DependencyInjection;

namespace Aspirate.Commands.Actions.BindMounts;
public sealed class SaveBindMountsAction(
IServiceProvider serviceProvider) : BaseAction(serviceProvider)
{
public override Task<bool> ExecuteAsync()
{
if (CurrentState.DisableMinikubeMountAction.Equals(false) || !CurrentState.DisableMinikubeMountAction.HasValue)
{
var values = new Dictionary<string, Dictionary<string, int?>>();
foreach (var resource in CurrentState.AllSelectedSupportedComponents)
{
var resourceWithBindMounts = resource.Value as IResourceWithBindMounts;

if (resourceWithBindMounts?.BindMounts.Count > 0)
{
foreach (var bindMount in resourceWithBindMounts.BindMounts)
{
if (!values.ContainsKey(bindMount.Source))
{
values[bindMount.Source] = [];
}
values[bindMount.Source].TryAdd(bindMount.Target, null);
}

//values.Add(resourceWithBindMounts.Name, resourceWithBindMounts.BindMounts);
}
}

if (values.Count > 0)
{
CurrentState.BindMounts = values;
}
}

return Task.FromResult(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public sealed class RemoveManifestsFromClusterAction(
IServiceProvider serviceProvider,
IFileSystem fileSystem,
IDaprCliService daprCliService,
IMinikubeCliService minikubeCliService,
ISecretProvider secretProvider) :
BaseActionWithNonInteractiveValidation(serviceProvider)
{
Expand All @@ -20,6 +21,7 @@ public override async Task<bool> ExecuteAsync()

CreateEmptySecretFiles(secretFiles);
await kubeCtlService.RemoveManifests(CurrentState.KubeContext, CurrentState.InputPath);

Logger.MarkupLine(
$"[green]({EmojiLiterals.CheckMark}) Done:[/] Deployments removed from cluster [blue]'{CurrentState.KubeContext}'[/]");

Expand Down
1 change: 1 addition & 0 deletions src/Aspirate.Commands/Commands/Apply/ApplyCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ public ApplyCommand() : base("apply", "Apply the generated kustomize manifest to
AddOption(KubernetesContextOption.Instance);
AddOption(SecretPasswordOption.Instance);
AddOption(RollingRestartOption.Instance);
AddOption(DisableMinikubeMountActionOption.Instance);
}
}
3 changes: 3 additions & 0 deletions src/Aspirate.Commands/Commands/Apply/ApplyCommandHandler.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using Aspirate.Commands.Actions.BindMounts;

namespace Aspirate.Commands.Commands.Apply;

public sealed class ApplyCommandHandler(IServiceProvider serviceProvider) : BaseCommandOptionsHandler<ApplyOptions>(serviceProvider)
{
public override Task<int> HandleAsync(ApplyOptions optionses) =>
ActionExecutor
.QueueAction(nameof(ApplyMinikubeMountsAction))
.QueueAction(nameof(ApplyManifestsToClusterAction))
.ExecuteCommandsAsync();
}
3 changes: 2 additions & 1 deletion src/Aspirate.Commands/Commands/Apply/ApplyOptions.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
namespace Aspirate.Commands.Commands.Apply;

public sealed class ApplyOptions : BaseCommandOptions, IKubernetesOptions, IApplyOptions
public sealed class ApplyOptions : BaseCommandOptions, IKubernetesOptions, IApplyOptions, IMinikubeOptions
{
public string? InputPath { get; set; }
public string? KubeContext { get; set; }
public bool? RollingRestart { get; set; }
public bool? DisableMinikubeMountAction { get; set; }
}
1 change: 1 addition & 0 deletions src/Aspirate.Commands/Commands/Destroy/DestroyCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ public DestroyCommand() : base("destroy", "Removes the manifests from your clust
{
AddOption(InputPathOption.Instance);
AddOption(KubernetesContextOption.Instance);
AddOption(DisableMinikubeMountActionOption.Instance);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using Aspirate.Commands.Actions.BindMounts;

namespace Aspirate.Commands.Commands.Destroy;

public sealed class DestroyCommandHandler(IServiceProvider serviceProvider) : BaseCommandOptionsHandler<DestroyOptions>(serviceProvider)
{
public override Task<int> HandleAsync(DestroyOptions options) =>
ActionExecutor
.QueueAction(nameof(RemoveManifestsFromClusterAction))
.QueueAction(nameof(KillMinikubeMountsAction))
.ExecuteCommandsAsync();
}
3 changes: 2 additions & 1 deletion src/Aspirate.Commands/Commands/Destroy/DestroyOptions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
namespace Aspirate.Commands.Commands.Destroy;

public sealed class DestroyOptions : BaseCommandOptions, IKubernetesOptions
public sealed class DestroyOptions : BaseCommandOptions, IKubernetesOptions, IMinikubeOptions
{
public string? InputPath { get; set; }
public string? KubeContext { get; set; }
public bool? DisableMinikubeMountAction { get; set; }
}
1 change: 1 addition & 0 deletions src/Aspirate.Commands/Commands/Generate/GenerateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ public GenerateCommand() : base("generate", "Builds, pushes containers, generate
AddOption(ComposeBuildsOption.Instance);
AddOption(ReplaceSecretsOption.Instance);
AddOption(ParameterResourceValueOption.Instance);
AddOption(DisableMinikubeMountActionOption.Instance);
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Aspirate.Commands.Actions.BindMounts;

namespace Aspirate.Commands.Commands.Generate;

public sealed class GenerateCommandHandler(IServiceProvider serviceProvider) : BaseCommandOptionsHandler<GenerateOptions>(serviceProvider)
Expand Down Expand Up @@ -30,7 +32,8 @@ private ActionExecutor BaseGenerateActionSequence() =>
.QueueAction(nameof(PopulateContainerDetailsForProjectsAction))
.QueueAction(nameof(BuildAndPushContainersFromProjectsAction))
.QueueAction(nameof(BuildAndPushContainersFromDockerfilesAction))
.QueueAction(nameof(SaveSecretsAction));
.QueueAction(nameof(SaveSecretsAction))
.QueueAction(nameof(SaveBindMountsAction));

private ActionExecutor BaseKubernetesActionSequence() =>
BaseGenerateActionSequence()
Expand Down
4 changes: 3 additions & 1 deletion src/Aspirate.Commands/Commands/Generate/GenerateOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ public sealed class GenerateOptions : BaseCommandOptions,
IGenerateOptions,
IPrivateRegistryCredentialsOptions,
IDashboardOptions,
ISecretState
ISecretState,
IMinikubeOptions
{
public string? ProjectPath { get; set; }
public string? AspireManifest { get; set; }
Expand All @@ -34,4 +35,5 @@ public sealed class GenerateOptions : BaseCommandOptions,
public bool? WithPrivateRegistry { get; set; }
public bool? IncludeDashboard { get; set; }
public bool? ReplaceSecrets { get; set; }
public bool? DisableMinikubeMountAction { get; set; }
}
1 change: 1 addition & 0 deletions src/Aspirate.Commands/Commands/Run/RunCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ public RunCommand() : base("run", "Builds, pushes containers, and runs the curre
AddOption(PrivateRegistryEmailOption.Instance);
AddOption(IncludeDashboardOption.Instance);
AddOption(AllowClearNamespaceOption.Instance);
AddOption(DisableMinikubeMountActionOption.Instance);
}
}
4 changes: 4 additions & 0 deletions src/Aspirate.Commands/Commands/Run/RunCommandHandler.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Aspirate.Commands.Actions.BindMounts;

namespace Aspirate.Commands.Commands.Run;

public sealed class RunCommandHandler(IServiceProvider serviceProvider) : BaseCommandOptionsHandler<RunOptions>(serviceProvider)
Expand All @@ -16,7 +18,9 @@ public override Task<int> HandleAsync(RunOptions options) =>
.QueueAction(nameof(BuildAndPushContainersFromDockerfilesAction))
.QueueAction(nameof(AskImagePullPolicyAction))
.QueueAction(nameof(SaveSecretsAction))
.QueueAction(nameof(SaveBindMountsAction))
.QueueAction(nameof(CustomNamespaceAction))
.QueueAction(nameof(ApplyMinikubeMountsAction))
.QueueAction(nameof(RunKubernetesObjectsAction))
.ExecuteCommandsAsync();
}
4 changes: 3 additions & 1 deletion src/Aspirate.Commands/Commands/Run/RunOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ public sealed class RunOptions : BaseCommandOptions,
IAspireOptions,
IPrivateRegistryCredentialsOptions,
IDashboardOptions,
IRunOptions
IRunOptions,
IMinikubeOptions
{
public string? ProjectPath { get; set; }
public string? AspireManifest { get; set; }
Expand All @@ -26,4 +27,5 @@ public sealed class RunOptions : BaseCommandOptions,
public string? PrivateRegistryEmail { get; set; }
public bool? WithPrivateRegistry { get; set; }
public bool? IncludeDashboard { get; set; }
public bool? DisableMinikubeMountAction { get; set; }
}
3 changes: 3 additions & 0 deletions src/Aspirate.Commands/Commands/Stop/StopCommandHandler.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using Aspirate.Commands.Actions.BindMounts;

namespace Aspirate.Commands.Commands.Stop;

public sealed class StopCommandHandler(IServiceProvider serviceProvider) : BaseCommandOptionsHandler<StopOptions>(serviceProvider)
{
public override Task<int> HandleAsync(StopOptions options) =>
ActionExecutor
.QueueAction(nameof(StopDeployedKubernetesInstanceAction))
.QueueAction(nameof(KillMinikubeMountsAction))
.ExecuteCommandsAsync();
}
21 changes: 21 additions & 0 deletions src/Aspirate.Commands/Options/DisableMinikubeMountActionOption.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace Aspirate.Commands.Options;
public sealed class DisableMinikubeMountActionOption : BaseOption<bool?>
{
private static readonly string[] _aliases =
[
"-dm",
"--disable-minikube-mount"
];

private DisableMinikubeMountActionOption() : base(_aliases, "ASPIRATE_DISABLE_MINIKUBE_MOUNT_ACTION", null)
{
Name = nameof(IMinikubeOptions.DisableMinikubeMountAction);
Description = "Disables minikube mount actions";
Arity = ArgumentArity.ZeroOrOne;
IsRequired = false;
}

public static DisableMinikubeMountActionOption Instance { get; } = new();

public override bool IsSecret => false;
}
7 changes: 6 additions & 1 deletion src/Aspirate.Commands/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Aspirate.Commands;
using Aspirate.Commands.Actions.BindMounts;

namespace Aspirate.Commands;

/// <summary>
/// Extension methods for IServiceCollection to register services for AspirateState and AspirateActions.
Expand Down Expand Up @@ -40,11 +42,14 @@ public static IServiceCollection AddAspirateActions(this IServiceCollection serv
.RegisterAction<ApplyDaprAnnotationsAction>()
.RegisterAction<PopulateInputsAction>()
.RegisterAction<SaveSecretsAction>()
.RegisterAction<SaveBindMountsAction>()
.RegisterAction<AskPrivateRegistryCredentialsAction>()
.RegisterAction<IncludeAspireDashboardAction>()
.RegisterAction<GenerateHelmChartAction>()
.RegisterAction<CustomNamespaceAction>()
.RegisterAction<RunKubernetesObjectsAction>()
.RegisterAction<ApplyMinikubeMountsAction>()
.RegisterAction<KillMinikubeMountsAction>()
.RegisterAction<StopDeployedKubernetesInstanceAction>();

/// <summary>
Expand Down
1 change: 1 addition & 0 deletions src/Aspirate.Services/Aspirate.Services.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<PackageReference Include="CliWrap" />
<PackageReference Include="KubernetesClient" />
<PackageReference Include="NuGet.Protocol" />
<PackageReference Include="System.Management" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading
Loading