Repository navigation
Replies: 1 comment
|
Option 1 doesn't combine with Splitting into separate CLI runs doesn't guarantee it either. What works is scanning inside the same run, between build and push. A failed step blocks its dependents, so no image is pushed and no Container App is updated: #pragma warning disable ASPIREPIPELINES001
using System.Diagnostics;
using Aspire.Hosting.Pipelines;
builder.Pipeline.AddStep("scan-images", async ctx =>
{
foreach (var r in ctx.Model.Resources.Where(r => r.RequiresImageBuildAndPush()))
{
// same local name the push step tags and pushes
var image = r.TryGetContainerImageName(out var n) ? n : r.Name.ToLowerInvariant();
using var p = Process.Start("trivy", ["image", "--exit-code", "1", "--severity", "HIGH,CRITICAL", image]);
await p.WaitForExitAsync(ctx.CancellationToken);
if (p.ExitCode != 0) throw new InvalidOperationException($"Trivy failed for {image}");
}
}, dependsOn: WellKnownPipelineSteps.Build);
builder.Pipeline.AddPipelineConfiguration(ctx =>
{
ctx.GetSteps(WellKnownPipelineTags.PushContainerImage).DependsOn("scan-images");
return Task.CompletedTask;
});Then run one |
Uh oh!
There was an error while loading. Please reload this page.
Hi everyone,
We’re using Aspire to deploy our application to Azure through an Azure DevOps pipeline. Before each deployment, we’d like to scan our container images with Trivy for vulnerabilities and ensure that the exact images we scan are the ones deployed to Azure.
We’re considering two approaches:
ContainerBuildOptions.DestinationtoArchive:Is there a recommended approach for integrating image scanning into an Aspire deployment pipeline? In particular, how do you separate the build, scan, and deployment stages while ensuring that Aspire deploys the exact images that passed the scan?
We’d love to hear how others handle this and any lessons learned.
All reactions