diff --git a/docs/test-ghcr-tag-aspire/AppHost.cs b/docs/test-ghcr-tag-aspire/AppHost.cs new file mode 100644 index 0000000000..ec52e46461 --- /dev/null +++ b/docs/test-ghcr-tag-aspire/AppHost.cs @@ -0,0 +1,51 @@ +#:sdk Aspire.AppHost.Sdk@13.4.0 +#:package Particular.Aspire.Hosting.ServicePlatform@1.* +#:package Aspire.Hosting.RabbitMQ@13.4.0 + +using Aspire.Hosting; +using Particular.Aspire.Hosting.ServicePlatform.Transport; + +var builder = DistributedApplication.CreateBuilder(args); + +var transportUserName = builder.AddParameter("transportUserName", "guest", secret: true); +var transportPassword = builder.AddParameter("transportPassword", "guest", secret: true); + +var transport = builder.AddRabbitMQ("transport", transportUserName, transportPassword) + .WithManagementPlugin(15672) + .WithUrlForEndpoint("management", url => url.DisplayText = "RabbitMQ Management"); + +builder + .AddParticularPlatform("particular") + .WithTransportRabbitMQ(RabbitMqRouting.QuorumConventionalRouting, transport) + .AddDefaultComponents(); + +//using positional param for now since there's only one +if (args.Length > 1) +{ + UsePrereleaseImage(builder, args[1]); +} else { + Console.WriteLine("No arguments provided, defaulting to published 'latest' images'"); +} + +var app = builder.Build(); + +await app.RunAsync(); + +static void UsePrereleaseImage(IDistributedApplicationBuilder builder, string tag) +{ + Console.WriteLine($"Using prerelease image tag: {tag}"); + foreach (var c in builder.Resources.OfType()) + { + if (!c.TryGetLastAnnotation(out var image)) + { + continue; + } + + if (image.Image.StartsWith("particular/servicecontrol")) + { + builder + .CreateResourceBuilder(c) + .WithImage($"ghcr.io/{image.Image}", tag); + } + } +} \ No newline at end of file diff --git a/docs/test-ghcr-tag-aspire/aspire.config.json b/docs/test-ghcr-tag-aspire/aspire.config.json new file mode 100644 index 0000000000..09075c45d9 --- /dev/null +++ b/docs/test-ghcr-tag-aspire/aspire.config.json @@ -0,0 +1,5 @@ +{ + "appHost": { + "path": "AppHost.cs" + } +} \ No newline at end of file diff --git a/docs/testing.md b/docs/testing.md index eccdd7bc79..62bb10ec96 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -63,3 +63,22 @@ Containers built by a PR and stored on GitHub Container Registry can be tested l * [Monitoring API](http://localhost:33633) * [ServicePulse (latest from Docker Hub)](http://localhost:9090) 6. Tear down services using `docker compose down`. + + +## Container tests using Aspire + +The [Particular.Aspire.Hosting.ServicePlatform](https://github.com/Particular/Particular.Aspire.Hosting.ServicePlatform) package integrates the Particular Platform with the Aspire hosting platform. This package configures environment variables to attach the platform. There is a single file apphost in [`test-ghcr-tag-aspire`](/docs/test-ghcr-tag-aspire) to start up serviceconrol from a prerelease container image. + +Containers built by a PR and stored on GitHub Container Registry can be tested locally: + +1. Set up your github container registry credentials as described in the [Container tests](#container-tests) section above. +2. Make sure you have the [Aspire CLI installed](https://aspire.dev/get-started/install-cli/). +3. Run `aspire run docs/test-ghcr-tag-aspire/AppHost.cs -- tag` to start the application, where `tag` is the PR-based tag (in the form `pr-####`) to test. If no tag is provided, it will default to the `latest` tag. +4. Once running you can open the dashboard from the link in the terminal, this dashboard will provide the assigned ports for each service. + * RabbitMQ Management (Login: `guest`/`guest`) + * RavenDB + * ServiceControl API + * Audit API + * Monitoring API + * ServicePulse (latest from Docker Hub) +5. Aspire will automatically tear down the application when you exit the CLI process. \ No newline at end of file