|
| 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(); |
0 commit comments