-
Notifications
You must be signed in to change notification settings - Fork 349
Expand file tree
/
Copy pathAppHost.cs
More file actions
95 lines (78 loc) · 3.66 KB
/
Copy pathAppHost.cs
File metadata and controls
95 lines (78 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using Microsoft.Extensions.DependencyInjection;
var builder = DistributedApplication.CreateBuilder(args);
var aspireDB = Environment.GetEnvironmentVariable("ASPIRE_DATABASE_TYPE");
var databaseConnectionString = Environment.GetEnvironmentVariable("ASPIRE_DATABASE_CONNECTION_STRING") ?? "";
switch (aspireDB)
{
case "mssql":
var sqlScript = File.ReadAllText("./init-scripts/sql/create-database.sql");
IResourceBuilder<SqlServerDatabaseResource>? sqlDbContainer = null;
if (string.IsNullOrEmpty(databaseConnectionString))
{
Console.WriteLine("No connection string provided, starting a local SQL Server container.");
sqlDbContainer = builder.AddSqlServer("sqlserver")
.WithDataVolume()
.WithLifetime(ContainerLifetime.Persistent)
.AddDatabase("msSqlDb", "Trek")
.WithCreationScript(sqlScript);
}
var mssqlService = builder.AddProject<Projects.Azure_DataApiBuilder_Service>("mssql-service", "Development")
.WithArgs("-f", "net10.0")
.WithEndpoint(endpointName: "https", (e) => e.Port = 1234)
.WithEndpoint(endpointName: "http", (e) => e.Port = 2345)
.WithEnvironment("db-type", "mssql")
.WithUrls((e) =>
{
e.Urls.Clear();
e.Urls.Add(new() { Url = "/swagger", DisplayText = "🔒Swagger", Endpoint = e.GetEndpoint("https") });
e.Urls.Add(new() { Url = "/graphql", DisplayText = "🔒GraphQL", Endpoint = e.GetEndpoint("https") });
})
.WithHttpHealthCheck("/health");
if (sqlDbContainer is null)
{
mssqlService.WithEnvironment("DAB_CONNSTRING", databaseConnectionString);
}
else
{
mssqlService.WithEnvironment("DAB_CONNSTRING", sqlDbContainer)
.WaitFor(sqlDbContainer);
}
break;
case "postgresql":
var pgScript = File.ReadAllText("./init-scripts/pg/create-database-pg.sql");
IResourceBuilder<PostgresDatabaseResource>? postgresDB = null;
if (!string.IsNullOrEmpty(databaseConnectionString))
{
Console.WriteLine("No connection string provided, starting a local PostgreSQL container.");
postgresDB = builder.AddPostgres("postgres")
.WithPgAdmin()
.WithLifetime(ContainerLifetime.Persistent)
.AddDatabase("pgDb", "postgres")
.WithCreationScript(pgScript);
}
var pgService = builder.AddProject<Projects.Azure_DataApiBuilder_Service>("pg-service", "Development")
.WithArgs("-f", "net10.0")
.WithEndpoint(endpointName: "https", (e) => e.Port = 1234)
.WithEndpoint(endpointName: "http", (e) => e.Port = 2345)
.WithEnvironment("db-type", "postgresql")
.WithUrls((e) =>
{
e.Urls.Clear();
e.Urls.Add(new() { Url = "/swagger", DisplayText = "🔒Swagger", Endpoint = e.GetEndpoint("https") });
e.Urls.Add(new() { Url = "/graphql", DisplayText = "🔒GraphQL", Endpoint = e.GetEndpoint("https") });
})
.WithHttpHealthCheck("/health");
if (postgresDB is null)
{
pgService.WithEnvironment("DAB_CONNSTRING", databaseConnectionString);
}
else
{
pgService.WithEnvironment("DAB_CONNSTRING", postgresDB)
.WaitFor(postgresDB);
}
break;
default:
throw new Exception("Please set the ASPIRE_DATABASE environment variable to either 'mssql' or 'postgresql'.");
}
builder.Build().Run();