|
8 | 8 |
|
9 | 9 | var builder = DistributedApplication.CreateBuilder(args); |
10 | 10 |
|
| 11 | + |
11 | 12 | LaunchOptions launchOptions = builder.Configuration.GetSection("Launch").Get<LaunchOptions>() ?? new(); |
12 | 13 |
|
13 | 14 | LogLaunchOptions(launchOptions); |
|
26 | 27 | builder.AddMoodle(postgres, keycloak, launchOptions); |
27 | 28 | builder.AddLrsql(postgres, keycloak, launchOptions); |
28 | 29 | builder.AddMisp(postgres, keycloak, launchOptions); |
| 30 | +builder.AddSuperset(postgres, keycloak, launchOptions); |
29 | 31 | builder.AddDocs(launchOptions); |
30 | 32 |
|
31 | 33 | builder.Build().Run(); |
@@ -979,6 +981,72 @@ public static void AddMisp(this IDistributedApplicationBuilder builder, IResourc |
979 | 981 | } |
980 | 982 | } |
981 | 983 |
|
| 984 | + public static void AddSuperset(this IDistributedApplicationBuilder builder, IResourceBuilder<PostgresServerResource> postgres, IResourceBuilder<KeycloakResource> keycloak, LaunchOptions options) |
| 985 | + { |
| 986 | + var supersetMode = ResolveMode(options.Superset, "Superset", options); |
| 987 | + |
| 988 | + if (!options.AddAllApplications && !IsEnabled(supersetMode)) |
| 989 | + return; |
| 990 | + |
| 991 | + var supersetDb = postgres.AddDatabase("supersetDb", "superset"); |
| 992 | + |
| 993 | + var superset = builder.AddContainer("superset", "superset-custom-image") |
| 994 | + .WithDockerfile("./resources/superset", "Dockerfile.SupersetCustom") |
| 995 | + .WithLifetime(ContainerLifetime.Persistent) |
| 996 | + .WithContainerName("superset") |
| 997 | + .WaitFor(postgres) |
| 998 | + .WaitFor(keycloak) |
| 999 | + .WithHttpEndpoint(port: 8088, targetPort: 8088) |
| 1000 | + .WithHttpHealthCheck(path: "/health", endpointName: "http") |
| 1001 | + .WithBindMount("./resources/superset/superset_config.py", "/app/superset_config.py", isReadOnly: true) |
| 1002 | + .WithBindMount("./resources/superset/init-superset.sh", "/app/init-superset.sh", isReadOnly: true) |
| 1003 | + .WithBindMount("./resources/superset/create-dashboard-orm.py", "/app/create-dashboard-orm.py", isReadOnly: true) |
| 1004 | + .WithEnvironment("SUPERSET_CONFIG_PATH", "/app/superset_config.py") |
| 1005 | + .WithEnvironment("SUPERSET_SECRET_KEY", "crucible-dev-superset-secret-key") |
| 1006 | + .WithEnvironment("KEYCLOAK_EXTERNAL_URL", "http://localhost:8080/realms/crucible") |
| 1007 | + .WithEnvironment(context => |
| 1008 | + { |
| 1009 | + // Internal Keycloak URL for server-to-server communication |
| 1010 | + var keycloakEndpoint = keycloak.GetEndpoint("http"); |
| 1011 | + var keycloakHost = keycloakEndpoint.Property(EndpointProperty.Host); |
| 1012 | + var keycloakPort = keycloakEndpoint.Property(EndpointProperty.Port); |
| 1013 | + context.EnvironmentVariables["KEYCLOAK_INTERNAL_URL"] = |
| 1014 | + ReferenceExpression.Create($"http://{keycloakHost}:{keycloakPort}/realms/crucible"); |
| 1015 | + }) |
| 1016 | + .WithEnvironment("KEYCLOAK_CLIENT_ID", "superset") |
| 1017 | + .WithEnvironment("KEYCLOAK_CLIENT_SECRET", "superset-client-secret") |
| 1018 | + .WithEnvironment(context => |
| 1019 | + { |
| 1020 | + var host = postgres.Resource.PrimaryEndpoint.Property(EndpointProperty.Host); |
| 1021 | + var port = postgres.Resource.PrimaryEndpoint.Property(EndpointProperty.Port); |
| 1022 | + var user = postgres.Resource.UserNameReference; |
| 1023 | + var password = postgres.Resource.PasswordParameter; |
| 1024 | + var dbName = supersetDb.Resource.DatabaseName; |
| 1025 | + |
| 1026 | + context.EnvironmentVariables["DATABASE_HOST"] = host; |
| 1027 | + context.EnvironmentVariables["DATABASE_PORT"] = port; |
| 1028 | + context.EnvironmentVariables["DATABASE_USER"] = user; |
| 1029 | + context.EnvironmentVariables["DATABASE_PASSWORD"] = password; |
| 1030 | + context.EnvironmentVariables["DATABASE_DB"] = dbName; |
| 1031 | + |
| 1032 | + // Compose the SQLAlchemy URI for Superset metadata DB |
| 1033 | + context.EnvironmentVariables["SUPERSET_SQLALCHEMY_DATABASE_URI"] = |
| 1034 | + ReferenceExpression.Create($"postgresql+psycopg2://{user}:{password}@{host}:{port}/{dbName}"); |
| 1035 | + |
| 1036 | + // LRsql database connection for xAPI analytics |
| 1037 | + context.EnvironmentVariables["LRSQL_SQLALCHEMY_URI"] = |
| 1038 | + ReferenceExpression.Create($"postgresql+psycopg2://{user}:{password}@{host}:{port}/lrsql"); |
| 1039 | + }) |
| 1040 | + .WithEnvironment("SUPERSET_LOAD_EXAMPLES", "no") |
| 1041 | + .WithEnvironment("CYPRESS_CONFIG", "false") |
| 1042 | + .WithArgs("bash", "/app/init-superset.sh"); |
| 1043 | + |
| 1044 | + if (!IsEnabled(supersetMode)) |
| 1045 | + { |
| 1046 | + superset.WithExplicitStart(); |
| 1047 | + } |
| 1048 | + } |
| 1049 | + |
982 | 1050 | private static void ConfigureApiSecrets( |
983 | 1051 | this IDistributedApplicationBuilder builder, |
984 | 1052 | string apiProjectPath, |
|
0 commit comments