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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using System.IO.Abstractions;
using Actions.Core.Services;
using Amazon.S3;
using Amazon.S3.Transfer;
Expand All @@ -21,14 +20,15 @@ public class IncrementalDeployService(
AssemblyConfiguration assemblyConfiguration,
IConfigurationContext configurationContext,
ICoreService githubActionsService,
ScopedFileSystem fileSystem
ScopedFileSystem readFileSystem,
ScopedFileSystem writeFileSystem
) : IService
{
private readonly ILogger _logger = logFactory.CreateLogger<IncrementalDeployService>();

public async Task<bool> Plan(IDiagnosticsCollector collector, string environment, string s3BucketName, string @out, float? deleteThreshold, Cancel ctx)
{
var assembleContext = new AssembleContext(assemblyConfiguration, configurationContext, environment, collector, fileSystem, fileSystem, null, null);
var assembleContext = new AssembleContext(assemblyConfiguration, configurationContext, environment, collector, readFileSystem, writeFileSystem, null, null);
var s3Client = new AmazonS3Client();
var planner = new AwsS3SyncPlanStrategy(logFactory, s3Client, s3BucketName, assembleContext);
var plan = await planner.Plan(deleteThreshold, ctx);
Expand All @@ -51,7 +51,7 @@ public async Task<bool> Plan(IDiagnosticsCollector collector, string environment
if (!string.IsNullOrEmpty(@out))
{
var output = SyncPlan.Serialize(plan);
await using var fileStream = fileSystem.File.Create(@out);
await using var fileStream = writeFileSystem.File.Create(@out);
await using var writer = new StreamWriter(fileStream);
await writer.WriteAsync(output);
_logger.LogInformation("Plan written to {OutputFile}", @out);
Expand All @@ -62,19 +62,19 @@ public async Task<bool> Plan(IDiagnosticsCollector collector, string environment

public async Task<bool> Apply(IDiagnosticsCollector collector, string environment, string s3BucketName, string planFile, Cancel ctx)
{
var assembleContext = new AssembleContext(assemblyConfiguration, configurationContext, environment, collector, fileSystem, fileSystem, null, null);
var assembleContext = new AssembleContext(assemblyConfiguration, configurationContext, environment, collector, readFileSystem, writeFileSystem, null, null);
var s3Client = new AmazonS3Client();
var transferUtility = new TransferUtility(s3Client, new TransferUtilityConfig
{
ConcurrentServiceRequests = Environment.ProcessorCount * 2,
MinSizeBeforePartUpload = S3EtagCalculator.PartSize
});
if (!fileSystem.File.Exists(planFile))
if (!readFileSystem.File.Exists(planFile))
{
collector.EmitError(planFile, "Plan file does not exist.");
return false;
}
var planJson = await fileSystem.File.ReadAllTextAsync(planFile, ctx);
var planJson = await readFileSystem.File.ReadAllTextAsync(planFile, ctx);
var plan = SyncPlan.Deserialize(planJson);
_logger.LogInformation("Remote listing completed: {RemoteListingCompleted}", plan.RemoteListingCompleted);
_logger.LogInformation("Total files to sync: {TotalFiles}", plan.TotalSyncRequests);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using System.IO.Abstractions;
using Actions.Core.Services;
using ConsoleAppFramework;
using Elastic.Documentation.Assembler.Deploying;
Expand Down Expand Up @@ -33,8 +32,7 @@ public async Task<int> Plan(string environment, string s3BucketName, string @out
{
await using var serviceInvoker = new ServiceInvoker(collector);

var fs = FileSystemFactory.RealRead;
var service = new IncrementalDeployService(logFactory, assemblyConfiguration, configurationContext, githubActionsService, fs);
var service = new IncrementalDeployService(logFactory, assemblyConfiguration, configurationContext, githubActionsService, FileSystemFactory.RealRead, FileSystemFactory.RealWrite);
serviceInvoker.AddCommand(service, (environment, s3BucketName, @out, deleteThreshold),
static async (s, collector, state, ctx) => await s.Plan(collector, state.environment, state.s3BucketName, state.@out, state.deleteThreshold, ctx)
);
Expand All @@ -51,8 +49,7 @@ public async Task<int> Apply(string environment, string s3BucketName, string pla
{
await using var serviceInvoker = new ServiceInvoker(collector);

var fs = FileSystemFactory.RealWrite;
var service = new IncrementalDeployService(logFactory, assemblyConfiguration, configurationContext, githubActionsService, fs);
var service = new IncrementalDeployService(logFactory, assemblyConfiguration, configurationContext, githubActionsService, FileSystemFactory.RealRead, FileSystemFactory.RealWrite);
serviceInvoker.AddCommand(service, (environment, s3BucketName, planFile),
static async (s, collector, state, ctx) => await s.Apply(collector, state.environment, state.s3BucketName, state.planFile, ctx)
);
Expand Down
Loading