|
2 | 2 |
|
3 | 3 | var builder = DistributedApplication.CreateBuilder(args); |
4 | 4 |
|
5 | | -// Cosmos DB Emulator (for local dev). If you prefer local emulator app, set COSMOS_CONNECTION_STRING externally and skip this container. |
6 | | -var cosmosEmu = builder.AddContainer("cosmos", "mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator", tag: "latest") |
7 | | - .WithEnvironment("AZURE_COSMOS_EMULATOR_ENABLE_TELEMETRY", "false") |
8 | | - .WithEnvironment("AZURE_COSMOS_EMULATOR_PARTITION_COUNT", "3") |
9 | | - .WithEnvironment("AZURE_COSMOS_EMULATOR_ENABLE_DATA_PERSISTENCE", "true") |
10 | | - .WithContainerRuntimeArgs("--cap-add=NET_ADMIN") |
11 | | - .WithHttpEndpoint(port: 8085, targetPort: 8081, name: "cosmos"); // maps emulator 8081 -> 8085 on host |
12 | | - |
13 | | -// Connection strings: |
14 | | -// - Inside containers (same Docker/Aspire network): use the container hostname `cosmos` at port 8081. |
15 | | -// - From the host (for local tools like the Seeder): use https://localhost:8085 mapped above. |
16 | | -var cosmosConnForContainers = "AccountEndpoint=https://cosmos:8081/;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==;"; |
17 | | -var cosmosConnForHost = "AccountEndpoint=https://localhost:8085/;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==;"; |
18 | | - |
19 | | -var dab = builder.AddContainer("dab", "mcr.microsoft.com/data-api-builder", tag: "latest") |
20 | | - .WithBindMount("..\\dab\\dab-config.json", "/App/dab-config.json") |
21 | | - .WithEnvironment("ASPNETCORE_URLS", "http://+:8082") |
22 | | - // Prefer an explicit COSMOS_CONNECTION_STRING if provided by the user, otherwise default to the container-network connection. |
23 | | - .WithEnvironment("COSMOS_CONNECTION_STRING", Environment.GetEnvironmentVariable("COSMOS_CONNECTION_STRING") ?? cosmosConnForContainers) |
24 | | - // Provide COSMOS_CONNECTION_STRING via environment or user-secrets for DAB to connect to Cosmos |
25 | | - .WithHttpEndpoint(port: 8082, name: "http") |
26 | | - .WithArgs(["dab", "start", "--host", "0.0.0.0", "--config", "/App/dab-config.json"]); |
| 5 | +// Make containerized resources optional to avoid requiring DCP when running `dotnet run`. |
| 6 | +var skipContainersEnv = Environment.GetEnvironmentVariable("ASPIRE_SKIP_CONTAINERS"); |
| 7 | +var skipContainers = string.IsNullOrWhiteSpace(skipContainersEnv) || bool.TryParse(skipContainersEnv, out var val) && val; |
| 8 | + |
| 9 | +if (!skipContainers) |
| 10 | +{ |
| 11 | + // Cosmos DB Emulator (for local dev). If you prefer local emulator app, set COSMOS_CONNECTION_STRING externally and skip this container. |
| 12 | + var cosmosEmu = builder.AddContainer("cosmos", "mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator", tag: "latest") |
| 13 | + .WithEnvironment("AZURE_COSMOS_EMULATOR_ENABLE_TELEMETRY", "false") |
| 14 | + .WithEnvironment("AZURE_COSMOS_EMULATOR_PARTITION_COUNT", "3") |
| 15 | + .WithEnvironment("AZURE_COSMOS_EMULATOR_ENABLE_DATA_PERSISTENCE", "true") |
| 16 | + .WithContainerRuntimeArgs("--cap-add=NET_ADMIN") |
| 17 | + .WithHttpEndpoint(port: 8085, targetPort: 8081, name: "cosmos"); // maps emulator 8081 -> 8085 on host |
| 18 | + |
| 19 | + // Connection strings: |
| 20 | + // - Inside containers (same Docker/Aspire network): use the container hostname `cosmos` at port 8081. |
| 21 | + // - From the host (for local tools like the Seeder): use https://localhost:8085 mapped above. |
| 22 | + var cosmosConnForContainers = "AccountEndpoint=https://cosmos:8081/;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==;"; |
| 23 | + var cosmosConnForHost = "AccountEndpoint=https://localhost:8085/;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==;"; |
| 24 | + |
| 25 | + var dab = builder.AddContainer("dab", "mcr.microsoft.com/data-api-builder", tag: "latest") |
| 26 | + .WithBindMount("..\\dab\\dab-config.json", "/App/dab-config.json") |
| 27 | + .WithEnvironment("ASPNETCORE_URLS", "http://+:8082") |
| 28 | + // Prefer an explicit COSMOS_CONNECTION_STRING if provided by the user, otherwise default to the container-network connection. |
| 29 | + .WithEnvironment("COSMOS_CONNECTION_STRING", Environment.GetEnvironmentVariable("COSMOS_CONNECTION_STRING") ?? cosmosConnForContainers) |
| 30 | + // Provide COSMOS_CONNECTION_STRING via environment or user-secrets for DAB to connect to Cosmos |
| 31 | + .WithHttpEndpoint(port: 8082, name: "http") |
| 32 | + .WithArgs(["dab", "start", "--host", "0.0.0.0", "--config", "/App/dab-config.json"]); |
| 33 | +} |
27 | 34 |
|
28 | 35 | // (Optional) Run Seeder manually: dotnet run --project management-portal/Seeder |
29 | 36 |
|
|
0 commit comments