Skip to content

Commit 159e4d8

Browse files
committed
Add aspire testing instructions
1 parent dca2a7f commit 159e4d8

3 files changed

Lines changed: 84 additions & 0 deletions

File tree

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#:sdk Aspire.AppHost.Sdk@13.4.0
2+
#:package Particular.Aspire.Hosting.ServicePlatform@1.0.0-alpha.4
3+
#:package Aspire.Hosting.RabbitMQ@13.4.0
4+
5+
using Aspire.Hosting;
6+
using Particular.Aspire.Hosting.ServicePlatform.Transport;
7+
8+
var builder = DistributedApplication.CreateBuilder(args);
9+
10+
var transportUserName = builder.AddParameter("transportUserName", "guest", secret: true);
11+
var transportPassword = builder.AddParameter("transportPassword", "guest", secret: true);
12+
13+
var transport = builder.AddRabbitMQ("transport", transportUserName, transportPassword)
14+
.WithManagementPlugin(15672)
15+
.WithUrlForEndpoint("management", url => url.DisplayText = "RabbitMQ Management");
16+
17+
builder
18+
.AddParticularPlatform("particular")
19+
.WithTransportRabbitMQ(RabbitMqRouting.QuorumConventionalRouting, transport)
20+
.AddDefaultComponents();
21+
22+
//using positional param for now since there's only one
23+
if (args.Length > 1)
24+
{
25+
UsePrereleaseImage(builder, args[1]);
26+
} else {
27+
Console.WriteLine("No arguments provided, defaulting to published 'latest' images'");
28+
}
29+
30+
var app = builder.Build();
31+
32+
await app.RunAsync();
33+
34+
static void UsePrereleaseImage(IDistributedApplicationBuilder builder, string tag)
35+
{
36+
Console.WriteLine($"Using prerelease image tag: {tag}");
37+
foreach (var c in builder.Resources.OfType<ContainerResource>())
38+
{
39+
if (!c.TryGetLastAnnotation<ContainerImageAnnotation>(out var image))
40+
{
41+
continue;
42+
}
43+
44+
if (image.Image.StartsWith("particular/servicecontrol"))
45+
{
46+
builder
47+
.CreateResourceBuilder(c)
48+
.WithImage($"ghcr.io/{image.Image}", tag);
49+
}
50+
}
51+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"appHost": {
3+
"path": "AppHost.cs"
4+
}
5+
}

docs/testing.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,31 @@ Containers built by a PR and stored on GitHub Container Registry can be tested l
6363
* [Monitoring API](http://localhost:33633)
6464
* [ServicePulse (latest from Docker Hub)](http://localhost:9090)
6565
6. Tear down services using `docker compose down`.
66+
67+
68+
## Container tests using Aspire
69+
70+
The https://github.com/Particular/Particular.Aspire.Hosting.ServicePlatform package integrates servicecontrol with the Aspire hosting platform. This package configures environment variables to attach the platform. There is a single file apphost in [`testghcr-tag-aspire`](/docs/testghcr-tag-aspire) to start up serviceconrol from a prerelease container image.
71+
72+
Containers built by a PR and stored on GitHub Container Registry can be tested locally:
73+
74+
1. Make sure you have the [Aspire CLI installed](https://aspire.dev/get-started/install-cli/).
75+
2. [Authenticate to the GitHub Container Registry using a personal access token](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry#authenticating-with-a-personal-access-token-classic).
76+
- Create a [classic token](https://github.com/settings/tokens). Select the scope for `read:packages`
77+
- Copy the newly created token text.
78+
- Run the following command in a terminal:
79+
```shell
80+
docker login ghcr.io
81+
```
82+
you will be prompted for a username (your particular.net email) and a password (the token)
83+
- ensure that you get a successful login message.
84+
- Use `docker logout ghcr.io` once the following steps are complete and consider removing the token from github if its no longer needed.
85+
4. 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.
86+
5. Once running you can open the dashboard from the link in the terminal, this dashboard will provide the assigned ports for each service.
87+
* RabbitMQ Management (Login: `guest`/`guest`)
88+
* RavenDB
89+
* ServiceControl API
90+
* Audit API
91+
* Monitoring API
92+
* ServicePulse (latest from Docker Hub)
93+
6. Aspire will automatically tear down the application when you exit the CLI process.

0 commit comments

Comments
 (0)