Skip to content

Commit d660794

Browse files
committed
Add lismonk aspire project
1 parent c35edf1 commit d660794

File tree

8 files changed

+213
-0
lines changed

8 files changed

+213
-0
lines changed

ListmonkAspire/.aspire/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"appHostPath": "../ListmonkAspire.csproj"
3+
}

ListmonkAspire/AppHost.cs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
var builder = DistributedApplication.CreateBuilder(args);
2+
3+
// Create these values as secrets
4+
var postgresUser = builder.AddParameter("db-user", secret: true);
5+
var postgresPassword = builder.AddParameter("db-password", secret: true);
6+
7+
// Add a default for the database name
8+
var postgresDbName = builder.AddParameter("db-name", "listmonk", publishValueAsDefault: true);
9+
10+
var listmonkSuperUser = builder.AddParameter("listmonk-admin-user", secret: true);
11+
var listmonkSuperUserPassword = builder.AddParameter("listmonk-admin-password", secret: true);
12+
13+
var dbPort = 5432;
14+
var dbContainerName = "listmonk_db";
15+
var publicPort = 9000;
16+
17+
// Sets the POSTGRES_USER and POSTGRES_PASSWORD implicitly
18+
var db = builder.AddPostgres("db", postgresUser, postgresPassword, port: dbPort)
19+
.WithImage("postgres", "17-alpine") // Ensure we use the same image as docker-compose
20+
.WithContainerName(dbContainerName) // Use a fixed container name
21+
.WithLifetime(ContainerLifetime.Persistent) // Don't tear-down the container when we stop Aspire
22+
.WithDataVolume("listmonk-data") // Wire up the PostgreSQL data volume
23+
.WithEnvironment("POSTGRES_DB", postgresDbName) // Explicitly set this value, so that it's auto-created
24+
.PublishAsDockerComposeService((resource, service) =>
25+
{
26+
service.Restart = "unless-stopped";
27+
service.Healthcheck = new()
28+
{
29+
Interval = "10s",
30+
Timeout = "5s",
31+
Retries = 6,
32+
StartPeriod = "0s",
33+
Test = ["CMD-SHELL", "pg_isready -U listmonk"]
34+
};
35+
});
36+
37+
builder.AddContainer(name: "listmonk", image: "listmonk/listmonk", tag: "latest")
38+
.WaitFor(db) // The app depends on the db, so wait for it to be healthy
39+
.WithHttpEndpoint(port: publicPort, targetPort: 9000) // Expose port 9000 in the container as "publicPort"
40+
.WithExternalHttpEndpoints() // The HTTP endpoint should be publicly accessibly
41+
.WithArgs("sh", "-c", "./listmonk --install --idempotent --yes --config '' && ./listmonk --upgrade --yes --config '' && ./listmonk --config ''")
42+
.WithBindMount(source: "./uploads", target: "/listmonk/uploads") // mount the folder ./uploads on the host into the container
43+
.WithEnvironment("LISTMONK_app__address", $"0.0.0.0:{publicPort.ToString()}") // This points to the app itself (used in emails)
44+
.WithEnvironment("LISTMONK_db__user", postgresUser) // Database connection settings
45+
.WithEnvironment("LISTMONK_db__password", postgresPassword)
46+
.WithEnvironment("LISTMONK_db__database", postgresDbName)
47+
.WithEnvironment("LISTMONK_db__host", dbContainerName)
48+
.WithEnvironment("LISTMONK_db__port", dbPort.ToString())
49+
.WithEnvironment("LISTMONK_db__ssl_mode", "disable")
50+
.WithEnvironment("LISTMONK_db__max_open", "25")
51+
.WithEnvironment("LISTMONK_db__max_idle", "25")
52+
.WithEnvironment("LISTMONK_db__max_lifetime", "300s")
53+
.WithEnvironment("TZ", "Etc/UTC")
54+
.WithEnvironment("LISTMONK_ADMIN_USER", listmonkSuperUser) // Optional super-user
55+
.WithEnvironment("LISTMONK_ADMIN_PASSWORD", listmonkSuperUserPassword)
56+
.PublishAsDockerComposeService((resource, service) =>
57+
{
58+
service.Restart = "unless-stopped";
59+
});
60+
61+
builder.AddDockerComposeEnvironment("docker-compose");
62+
63+
builder.Build().Run();

ListmonkAspire/ListmonkAspire.csproj

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<Sdk Name="Aspire.AppHost.Sdk" Version="9.3.0" />
4+
5+
<PropertyGroup>
6+
<OutputType>Exe</OutputType>
7+
<TargetFramework>net9.0</TargetFramework>
8+
<ImplicitUsings>enable</ImplicitUsings>
9+
<Nullable>enable</Nullable>
10+
<UserSecretsId>2eec9746-c21a-4933-90af-c22431f35459</UserSecretsId>
11+
</PropertyGroup>
12+
13+
<ItemGroup>
14+
<PackageReference Include="Aspire.Hosting.AppHost" Version="9.3.0" />
15+
<PackageReference Include="Aspire.Hosting.Docker" Version="9.3.0-*" />
16+
<PackageReference Include="Aspire.Hosting.PostgreSQL" Version="9.3.0" />
17+
</ItemGroup>
18+
19+
</Project>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"$schema": "https://json.schemastore.org/launchsettings.json",
3+
"profiles": {
4+
"https": {
5+
"commandName": "Project",
6+
"dotnetRunMessages": true,
7+
"launchBrowser": true,
8+
"applicationUrl": "https://localhost:17129;http://localhost:15032",
9+
"environmentVariables": {
10+
"ASPNETCORE_ENVIRONMENT": "Development",
11+
"DOTNET_ENVIRONMENT": "Development",
12+
"ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21010",
13+
"ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22254"
14+
}
15+
},
16+
"http": {
17+
"commandName": "Project",
18+
"dotnetRunMessages": true,
19+
"launchBrowser": true,
20+
"applicationUrl": "http://localhost:15032",
21+
"environmentVariables": {
22+
"ASPNETCORE_ENVIRONMENT": "Development",
23+
"DOTNET_ENVIRONMENT": "Development",
24+
"ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19268",
25+
"ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20167"
26+
}
27+
}
28+
}
29+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
}
8+
}

ListmonkAspire/appsettings.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning",
6+
"Aspire.Hosting.Dcp": "Warning"
7+
}
8+
}
9+
}

ListmonkAspire/publish/.env

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Parameter db-user
2+
DB_USER=
3+
4+
# Parameter db-password
5+
DB_PASSWORD=
6+
7+
# Parameter db-name
8+
DB_NAME=listmonk
9+
10+
# Parameter listmonk-admin-user
11+
LISTMONK_ADMIN_USER=
12+
13+
# Parameter listmonk-admin-password
14+
LISTMONK_ADMIN_PASSWORD=
15+
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
services:
2+
db:
3+
image: "docker.io/postgres:17-alpine"
4+
container_name: "listmonk_db"
5+
environment:
6+
POSTGRES_HOST_AUTH_METHOD: "scram-sha-256"
7+
POSTGRES_INITDB_ARGS: "--auth-host=scram-sha-256 --auth-local=scram-sha-256"
8+
POSTGRES_USER: "${DB_USER}"
9+
POSTGRES_PASSWORD: "${DB_PASSWORD}"
10+
POSTGRES_DB: "${DB_NAME}"
11+
ports:
12+
- "5432:5432"
13+
volumes:
14+
- type: "volume"
15+
target: "/var/lib/postgresql/data"
16+
source: "listmonk-data"
17+
read_only: false
18+
networks:
19+
- "aspire"
20+
restart: "unless-stopped"
21+
healthcheck:
22+
test:
23+
- "CMD-SHELL"
24+
- "pg_isready -U listmonk"
25+
interval: "10s"
26+
timeout: "5s"
27+
retries: 6
28+
start_period: "0s"
29+
listmonk:
30+
image: "listmonk/listmonk:latest"
31+
command:
32+
- "sh"
33+
- "-c"
34+
- "./listmonk --install --idempotent --yes --config '' && ./listmonk --upgrade --yes --config '' && ./listmonk --config ''"
35+
environment:
36+
LISTMONK_app__address: "0.0.0.0:9000"
37+
LISTMONK_db__user: "${DB_USER}"
38+
LISTMONK_db__password: "${DB_PASSWORD}"
39+
LISTMONK_db__database: "${DB_NAME}"
40+
LISTMONK_db__host: "listmonk_db"
41+
LISTMONK_db__port: "5432"
42+
LISTMONK_db__ssl_mode: "disable"
43+
LISTMONK_db__max_open: "25"
44+
LISTMONK_db__max_idle: "25"
45+
LISTMONK_db__max_lifetime: "300s"
46+
TZ: "Etc/UTC"
47+
LISTMONK_ADMIN_USER: "${LISTMONK_ADMIN_USER}"
48+
LISTMONK_ADMIN_PASSWORD: "${LISTMONK_ADMIN_PASSWORD}"
49+
ports:
50+
- "9000:9000"
51+
volumes:
52+
- type: "bind"
53+
target: "/listmonk/uploads"
54+
source: "D:\\repos\\blog-examples\\ListmonkAspire\\uploads"
55+
read_only: false
56+
depends_on:
57+
db:
58+
condition: "service_started"
59+
networks:
60+
- "aspire"
61+
restart: "unless-stopped"
62+
networks:
63+
aspire:
64+
driver: "bridge"
65+
volumes:
66+
listmonk-data:
67+
driver: "local"

0 commit comments

Comments
 (0)