Skip to content

Instantly share code, notes, and snippets.

@Levvy055
Created September 17, 2025 18:34
Show Gist options
  • Select an option

  • Save Levvy055/43ab6c6170148b7e672956f5ed0524f8 to your computer and use it in GitHub Desktop.

Select an option

Save Levvy055/43ab6c6170148b7e672956f5ed0524f8 to your computer and use it in GitHub Desktop.
Aspire project template (mysql, phpmyadmin, redis, rabbitmq, seq) with secret parameters
#region Builder configuration
using TemplateNamespace.AppHost.Extensions;
using Scalar.Aspire;
var builder = DistributedApplication.CreateBuilder(args);
#region Parameters
var db_password = builder.AddParameter("db-password", secret: true);
var rdPassword = builder.AddParameter("rd-password", secret: true);
var rUsername = builder.AddParameter("rmq-username");
var rPassword = builder.AddParameter("rmq-password", secret: true);
var idUsername = builder.AddParameter("id-username");
var idPassword = builder.AddParameter("id-password", secret: true);
string apiPort = (int.TryParse(Environment.GetEnvironmentVariable("API_PORT"), out var parsedApiPort) ? parsedApiPort : 95).ToString();
var proxyApiPort = builder.AddParameter("api-port", apiPort, publishValueAsDefault: true);
var webPort = (int.TryParse(Environment.GetEnvironmentVariable("WEB_PORT"), out var parsedWebPort) ? parsedWebPort : 90).ToString();
var proxyWebPort = builder.AddParameter("web-port", webPort, publishValueAsDefault: true);
var seqPort = int.TryParse(Environment.GetEnvironmentVariable("PROXY_SEQ_PORT"), out var parsedProxySeqPort) ? parsedProxySeqPort : 17202;
#endregion
var mariadb = builder.AddMySql("template-mysql", db_password)
.WithDataBindMount("data/mysql")
.WithLifetime(ContainerLifetime.Persistent)
.WithPhpMyAdmin(o => o.WithLifetime(ContainerLifetime.Persistent), "template-phpmyadmin")
;
var db = mariadb.AddDatabase("template-db", "templateapp.db")
;
var seq = builder.AddSeq("template-seq", seqPort)
.WithDataBindMount("data/seq")
.WithEnvironment("ACCEPT_EULA", "Y")
.WithLifetime(ContainerLifetime.Persistent)
;
var cache = builder.AddRedis("template-redis", 6379, rdPassword)
.WithDataBindMount("data/redis")
.WithPersistence(interval: TimeSpan.FromMinutes(5), keysChangedThreshold: 100)
.WithLifetime(ContainerLifetime.Persistent)
.WithRedisInsight(o => o.WithLifetime(ContainerLifetime.Persistent), "template-redis-insight")
.WithRedisCommander(o => o.WithLifetime(ContainerLifetime.Persistent), "template-redis-commander")
;
var rabbitmq = builder.AddRabbitMQ("template-rabbitmq", rUsername, rPassword)
.WithDataBindMount("data/rabbitmq")
.WithLifetime(ContainerLifetime.Persistent)
.WithManagementPlugin()
;
var apiService = builder.AddProject<Projects.TemplateApp_ApiService>("template-apiservice")
.WithExternalHttpEndpoints()
.WithHttpHealthCheck("/health")
.WithReference(seq).WaitFor(seq)
.WithReference(cache).WaitFor(cache)
.WithReference(db).WaitFor(db)
.WithReference(rabbitmq).WaitFor(rabbitmq)
.PublishAsDockerComposeService((sr, s) =>
{
})
;
var webProject = builder.AddProject<Projects.TemplateApp_Web>("template-webfrontend")
.WithExternalHttpEndpoints()
.WithUrlForEndpoint("https", url =>
{
url.Url = "https://template-dev.example.com";
url.DisplayText = "TemplateApp Web";
})
.WithHttpsEndpoint(port: 7110, name: "https2")
.WithUrlForEndpoint("https2", url =>
{
url.Url = "https://192.168.0.10:7110";
url.DisplayText = "TemplateApp Direct";
})
.WithHttpHealthCheck("/health", endpointName: "https2")
.WithReference(seq).WaitFor(seq)
.WithReference(apiService).WaitFor(apiService)
.WithReference(rabbitmq).WaitFor(rabbitmq)
.WithReference(cache).WaitFor(cache)
.PublishAsDockerComposeService((sr, s) =>
{
})
;
var scalar = builder.AddScalarApiReference("template-api-docs", options =>
{
options
.WithDarkModeToggle(true)
.WithTheme(ScalarTheme.Default)
.WithSidebar(true)
.WithDefaultHttpClient(ScalarTarget.CSharp, ScalarClient.AsyncHttp)
.WithOperationSorter(OperationSorter.Method)
;
})
.WithApiReference(apiService, options =>
{
options
.AddDocument("v1", "API documentation for the template application")
;
})
;
builder.AddDashboard();
#endregion
var app = builder.Build();
app.Run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment