-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d0c6543
commit dd14d51
Showing
9 changed files
with
240 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
| ||
using Amazon; | ||
using Amazon.EC2.Model; | ||
using Amazon.SimpleEmailV2; | ||
using Amazon.SimpleEmailV2.Model; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
using ServiceMonitor.AWS; | ||
using ServiceMonitor.Cloud; | ||
using System.Text; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
IConfiguration config = new ConfigurationBuilder() | ||
.SetBasePath(Directory.GetCurrentDirectory()) | ||
.AddJsonFile("appsettings.json", true) | ||
.AddEnvironmentVariables() | ||
.Build(); | ||
|
||
var serviceCollection = new ServiceCollection(); | ||
serviceCollection.AddSingleton(config); | ||
serviceCollection.AddLogging(configure => | ||
{ | ||
configure.ClearProviders(); | ||
configure.AddConfiguration(config.GetSection("Logging")); | ||
configure.AddConsole(); | ||
}); | ||
serviceCollection.AddAWSService<IAmazonSimpleEmailServiceV2>(); | ||
serviceCollection.AddScoped<IAppRunner, AppRunner>(); | ||
serviceCollection.AddScoped<IInstance, AWSInstance>(); | ||
serviceCollection.AddScoped<IFunction, Lambda>(); | ||
serviceCollection.AddScoped<IImage, ECR>(); | ||
serviceCollection.AddScoped<IBucket, S3>(); | ||
|
||
var serviceProvider = serviceCollection.BuildServiceProvider(); | ||
|
||
var logger = serviceProvider.GetRequiredService<ILoggerFactory>().CreateLogger<Program>(); | ||
logger.LogDebug("Starting application"); | ||
|
||
var regions = new List<string> | ||
{ | ||
"ap-southeast-1", | ||
"ap-southeast-3", | ||
}; | ||
|
||
var containerImages = serviceProvider.GetRequiredService<IImage>(); | ||
foreach (var region in regions) | ||
{ | ||
var images = await containerImages.GetImagesAsync(region); | ||
foreach (var image in images) | ||
{ | ||
var tags = await containerImages.GetTags(region, image.Name); | ||
var (success, failure) = await containerImages.DeleteTags(region, image.Name, tags); | ||
logger.LogInformation("{}:{}:{}", image.Name, JsonSerializer.Serialize(success, new JsonSerializerOptions | ||
{ | ||
WriteIndented = true, | ||
}), | ||
JsonSerializer.Serialize(failure, new JsonSerializerOptions | ||
{ | ||
WriteIndented = true, | ||
})); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="AWSSDK.Extensions.NETCore.Setup" Version="3.7.7" /> | ||
<PackageReference Include="AWSSDK.SimpleEmailV2" Version="3.7.200.26" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="7.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\ServiceMonitor.AWS\ServiceMonitor.AWS.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using System.Threading; | ||
using ServiceMonitor.Cloud.Model; | ||
|
||
namespace ServiceMonitor.Cloud | ||
{ | ||
public interface IImage | ||
{ | ||
Task<ICollection<BasicProperty>> GetImagesAsync(string region, CancellationToken cancellationToken = default); | ||
Task<ICollection<TagItem>> GetTags(string region, string repoName, CancellationToken cancellationToken = default); | ||
Task<(List<string>, List<string>)> DeleteTags(string region, string repoName, ICollection<TagItem> tags, CancellationToken cancellationToken = default); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Text; | ||
|
||
namespace ServiceMonitor.Cloud.Model | ||
{ | ||
public class TagItem | ||
{ | ||
public IReadOnlyCollection<string> Tags { get; set; } | ||
public DateTime CreatedTime { get; set; } | ||
public string ImageDigest { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters