Skip to content

Commit

Permalink
Merge pull request #17669 from abpframework/cli-prerequirements
Browse files Browse the repository at this point in the history
Check Redis server when creating project.
  • Loading branch information
EngincanV authored Sep 20, 2023
2 parents bbbadf6 + dd8c389 commit 30bcc7b
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 7 deletions.
1 change: 1 addition & 0 deletions framework/src/Volo.Abp.Cli.Core/Volo.Abp.Cli.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<PackageReference Include="Polly" Version="$(PollyPackageVersion)" />
<PackageReference Include="Polly.Extensions.Http" Version="3.0.0" />
<PackageReference Include="LibGit2Sharp" Version="0.26.2" />
<PackageReference Include="StackExchange.Redis" Version="2.6.122" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using StackExchange.Redis;
using Volo.Abp.Cli.Args;
using Volo.Abp.Cli.Bundling;
using Volo.Abp.Cli.Commands.Services;
using Volo.Abp.Cli.LIbs;
using Volo.Abp.Cli.ProjectBuilding;
using Volo.Abp.Cli.ProjectBuilding.Building;
using Volo.Abp.Cli.ProjectBuilding.Templates.App;
using Volo.Abp.Cli.ProjectModification;
using Volo.Abp.Cli.Utils;
using Volo.Abp.DependencyInjection;
Expand Down Expand Up @@ -89,6 +91,8 @@ public async Task ExecuteAsync(CommandLineArgs commandLineArgs)

var projectArgs = await GetProjectBuildArgsAsync(commandLineArgs, template, projectName);

await CheckCreatingRequirements(projectArgs);

var result = await TemplateProjectBuilder.BuildAsync(
projectArgs
);
Expand All @@ -97,6 +101,8 @@ public async Task ExecuteAsync(CommandLineArgs commandLineArgs)

Logger.LogInformation($"'{projectName}' has been successfully created to '{projectArgs.OutputFolder}'");

await CheckCreatedRequirements(projectArgs);

ConfigureNpmPackagesForTheme(projectArgs);
await CreateOpenIddictPfxFilesAsync(projectArgs);
await RunGraphBuildForMicroserviceServiceTemplate(projectArgs);
Expand All @@ -120,6 +126,46 @@ public async Task ExecuteAsync(CommandLineArgs commandLineArgs)
OpenRelatedWebPage(projectArgs, template, isTiered, commandLineArgs);
}

private Task CheckCreatingRequirements(ProjectBuildArgs projectArgs)
{
return Task.CompletedTask;
}

private async Task CheckCreatedRequirements(ProjectBuildArgs projectArgs)
{
var errors = new List<string>();

if (projectArgs.ExtraProperties.ContainsKey("PreRequirements:Redis"))
{
var isConnected = false;
try
{
var redis = await ConnectionMultiplexer.ConnectAsync("127.0.0.1", options => options.ConnectTimeout = 3000);
isConnected = redis.IsConnected;
}
catch (Exception e)
{
// ignored
}
finally
{
if (!isConnected)
{
errors.Add("\t* Redis is not installed or not running on your computer.");
}
}
}

if (errors.Any())
{
Logger.LogWarning("NOTICE: The following tools are required to run your solution.");
foreach (var error in errors)
{
Logger.LogWarning(error);
}
}
}

public string GetUsageInfo()
{
var sb = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using JetBrains.Annotations;
using Volo.Abp.Cli.ProjectBuilding.Templates;

namespace Volo.Abp.Cli.ProjectBuilding.Building;

Expand Down Expand Up @@ -28,7 +29,14 @@ protected TemplateInfo(

public virtual IEnumerable<ProjectBuildPipelineStep> GetCustomSteps(ProjectBuildContext context)
{
return Array.Empty<ProjectBuildPipelineStep>();
var steps = new List<ProjectBuildPipelineStep>();
ConfigureCheckPreRequirements(context, steps);
return steps;
}

protected void ConfigureCheckPreRequirements(ProjectBuildContext context, List<ProjectBuildPipelineStep> steps)
{
steps.Add(new CheckRedisPreRequirements());
}

public bool IsPro()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using Volo.Abp.Cli.ProjectBuilding.Building;
using Volo.Abp.Cli.ProjectBuilding.Building.Steps;

Expand All @@ -20,7 +21,7 @@ public static bool IsAppNoLayersTemplate(string templateName)

public override IEnumerable<ProjectBuildPipelineStep> GetCustomSteps(ProjectBuildContext context)
{
var steps = new List<ProjectBuildPipelineStep>();
var steps = base.GetCustomSteps(context).ToList();

switch (context.BuildArgs.DatabaseProvider)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static bool IsAppTemplate(string templateName)

public override IEnumerable<ProjectBuildPipelineStep> GetCustomSteps(ProjectBuildContext context)
{
var steps = new List<ProjectBuildPipelineStep>();
var steps = base.GetCustomSteps(context).ToList();

ConfigureTenantSchema(context, steps);
SwitchDatabaseProvider(context, steps);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Linq;
using Volo.Abp.Cli.ProjectBuilding.Building;

namespace Volo.Abp.Cli.ProjectBuilding.Templates;

public class CheckRedisPreRequirements : ProjectBuildPipelineStep
{
public override void Execute(ProjectBuildContext context)
{
var modules = context.Files.Where(f => f.Name.EndsWith("Module.cs", StringComparison.OrdinalIgnoreCase));
if (modules.Any(module => module.Content.Contains("Redis:Configuration")))
{
context.BuildArgs.ExtraProperties["PreRequirements:Redis"] = "true";
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using JetBrains.Annotations;
using Volo.Abp.Cli.ProjectBuilding.Building;
using Volo.Abp.Cli.ProjectBuilding.Building.Steps;
Expand Down Expand Up @@ -33,14 +34,14 @@ public static string CalculateTargetFolder(string mainSolutionFolder, string ser

public override IEnumerable<ProjectBuildPipelineStep> GetCustomSteps(ProjectBuildContext context)
{
var steps = new List<ProjectBuildPipelineStep>();
var steps = base.GetCustomSteps(context).ToList();

DeleteUnrelatedUiProject(context, steps);
SetRandomPortForHostProject(context, steps);
RandomizeStringEncryption(context, steps);
RandomizeAuthServerPassPhrase(context, steps);
ChangeConnectionString(context, steps);

return steps;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using Volo.Abp.Cli.ProjectBuilding.Building;
using Volo.Abp.Cli.ProjectBuilding.Building.Steps;
Expand All @@ -19,7 +20,7 @@ public static bool IsMicroserviceTemplate(string templateName)

public override IEnumerable<ProjectBuildPipelineStep> GetCustomSteps(ProjectBuildContext context)
{
var steps = new List<ProjectBuildPipelineStep>();
var steps = base.GetCustomSteps(context).ToList();

DeleteUnrelatedProjects(context, steps);
RandomizeStringEncryption(context, steps);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using Volo.Abp.Cli.ProjectBuilding.Building;
using Volo.Abp.Cli.ProjectBuilding.Building.Steps;
Expand All @@ -21,7 +22,7 @@ public static bool IsModuleTemplate(string templateName)

public override IEnumerable<ProjectBuildPipelineStep> GetCustomSteps(ProjectBuildContext context)
{
var steps = new List<ProjectBuildPipelineStep>();
var steps = base.GetCustomSteps(context).ToList();

DeleteUnrelatedProjects(context, steps);
RandomizeSslPorts(context, steps);
Expand Down

0 comments on commit 30bcc7b

Please sign in to comment.