Skip to content

Commit efcbc65

Browse files
authored
Chore/add launches (#10)
* persist keycloak to postgres and app data, name the dev container and add launches to launch.json * additional launches, rename postgres container, db dump/restore instructions * remove unrequired changes * keycloak now uses postgres and the dev container works with zscalar * revert unneeded change * PR responses * update readme and remove unnecessary parameter
1 parent 5d7ff63 commit efcbc65

File tree

10 files changed

+155
-14
lines changed

10 files changed

+155
-14
lines changed

.devcontainer/devcontainer.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{
22
"name": "Crucible Development",
3+
"runArgs": [
4+
"--name",
5+
"crucible-dev"
6+
],
37
"build": {
48
"dockerfile": "Dockerfile"
59
},

.env/alloy.env

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Launch__Player=false
2+
Launch__Caster=false
3+
Launch__Alloy=true
4+
Launch__TopoMojo=false
5+
Launch__Steamfitter=false
6+
Launch__Cite=false
7+
Launch__Gallery=false
8+
Launch__Blueprint=false

.env/caster.env

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Launch__Player=false
2+
Launch__Caster=true
3+
Launch__Alloy=false
4+
Launch__TopoMojo=false
5+
Launch__Steamfitter=false
6+
Launch__Cite=false
7+
Launch__Gallery=false
8+
Launch__Blueprint=false

.env/player.env

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Launch__Player=true
2+
Launch__Caster=false
3+
Launch__Alloy=false
4+
Launch__TopoMojo=false
5+
Launch__Steamfitter=false
6+
Launch__Cite=false
7+
Launch__Gallery=false
8+
Launch__Blueprint=false

.env/steamfitter.env

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Launch__Player=false
2+
Launch__Caster=false
3+
Launch__Alloy=false
4+
Launch__TopoMojo=false
5+
Launch__Steamfitter=true
6+
Launch__Cite=false
7+
Launch__Gallery=false
8+
Launch__Blueprint=false

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,6 @@ nunit-*.xml
5959

6060
# devcontainer certs
6161
.devcontainer/certs/*.crt
62+
63+
# db dumps to restore into postgres
64+
db-dumps/

.vscode/launch.json

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,62 @@
1818
"projectPath": "${workspaceFolder}/Crucible.Apphost/Crucible.AppHost.csproj",
1919
"envFile": "${workspaceFolder}/.env/exercise.env"
2020
},
21+
{
22+
"name": "TTX",
23+
"type": "dotnet",
24+
"request": "launch",
25+
"projectPath": "${workspaceFolder}/Crucible.Apphost/Crucible.AppHost.csproj",
26+
"envFile": "${workspaceFolder}/.env/ttx.env"
27+
},
28+
{
29+
"name": "Alloy",
30+
"type": "dotnet",
31+
"request": "launch",
32+
"projectPath": "${workspaceFolder}/Crucible.Apphost/Crucible.AppHost.csproj",
33+
"envFile": "${workspaceFolder}/.env/alloy.env"
34+
},
35+
{
36+
"name": "Blueprint",
37+
"type": "dotnet",
38+
"request": "launch",
39+
"projectPath": "${workspaceFolder}/Crucible.Apphost/Crucible.AppHost.csproj",
40+
"envFile": "${workspaceFolder}/.env/blueprint.env"
41+
},
42+
{
43+
"name": "Caster",
44+
"type": "dotnet",
45+
"request": "launch",
46+
"projectPath": "${workspaceFolder}/Crucible.Apphost/Crucible.AppHost.csproj",
47+
"envFile": "${workspaceFolder}/.env/caster.env"
48+
},
49+
{
50+
"name": "CITE",
51+
"type": "dotnet",
52+
"request": "launch",
53+
"projectPath": "${workspaceFolder}/Crucible.Apphost/Crucible.AppHost.csproj",
54+
"envFile": "${workspaceFolder}/.env/cite.env"
55+
},
56+
{
57+
"name": "Gallery",
58+
"type": "dotnet",
59+
"request": "launch",
60+
"projectPath": "${workspaceFolder}/Crucible.Apphost/Crucible.AppHost.csproj",
61+
"envFile": "${workspaceFolder}/.env/gallery.env"
62+
},
63+
{
64+
"name": "Player",
65+
"type": "dotnet",
66+
"request": "launch",
67+
"projectPath": "${workspaceFolder}/Crucible.Apphost/Crucible.AppHost.csproj",
68+
"envFile": "${workspaceFolder}/.env/player.env"
69+
},
70+
{
71+
"name": "Steamfitter",
72+
"type": "dotnet",
73+
"request": "launch",
74+
"projectPath": "${workspaceFolder}/Crucible.Apphost/Crucible.AppHost.csproj",
75+
"envFile": "${workspaceFolder}/.env/steamfitter.env"
76+
},
2177
{
2278
"name": "TopoMojo",
2379
"type": "dotnet",
@@ -26,4 +82,4 @@
2682
"envFile": "${workspaceFolder}/.env/topo.env"
2783
}
2884
]
29-
}
85+
}

Crucible.AppHost/AppHost.cs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,17 @@
1313
var postgres = builder.AddPostgres("postgres")
1414
.WithDataVolume()
1515
.WithLifetime(ContainerLifetime.Persistent)
16+
.WithContainerName("crucible-postgres")
1617
.WithPgAdmin();
1718

19+
var keycloakDb = postgres.AddDatabase("keycloakDb", "keycloak");
1820
var keycloak = builder.AddKeycloak("keycloak", 8080)
19-
.WithLifetime(ContainerLifetime.Persistent)
21+
.WithReference(keycloakDb)
22+
// Configure environment variables for the PostgreSQL connection
23+
.WithEnvironment("KC_DB", "postgres")
24+
.WithEnvironment("KC_DB_URL_HOST", postgres.Resource.PrimaryEndpoint.Property(EndpointProperty.Host))
25+
.WithEnvironment("KC_DB_USERNAME", postgres.Resource.UserNameReference)
26+
.WithEnvironment("KC_DB_PASSWORD", postgres.Resource.PasswordParameter)
2027
.WithRealmImport($"{builder.AppHostDirectory}/resources/crucible-realm.json");
2128

2229
var mkdocs = builder.AddContainer("mkdocs", "squidfunk/mkdocs-material")
@@ -49,6 +56,7 @@ public static void AddPlayer(this IDistributedApplicationBuilder builder, IResou
4956
.WithHttpHealthCheck("api/health/ready")
5057
.WithReference(playerDb, "PostgreSQL")
5158
.WithEnvironment("Database__Provider", "PostgreSQL")
59+
.WithEnvironment("Database__DevModeRecreate", "false")
5260
.WithEnvironment("Authorization__Authority", "http://localhost:8080/realms/crucible")
5361
.WithEnvironment("Authorization__AuthorizationUrl", "http://localhost:8080/realms/crucible/protocol/openid-connect/auth")
5462
.WithEnvironment("Authorization__TokenUrl", "http://localhost:8080/realms/crucible/protocol/openid-connect/token")
@@ -76,6 +84,7 @@ private static void AddPlayerVm(this IDistributedApplicationBuilder builder, IRe
7684
.WithHttpHealthCheck("api/health/ready")
7785
.WithReference(vmDb, "PostgreSQL")
7886
.WithEnvironment("Database__Provider", "PostgreSQL")
87+
.WithEnvironment("Database__DevModeRecreate", "false")
7988
.WithEnvironment("VmUsageLogging__Enabled", "true")
8089
.WithEnvironment("VmUsageLogging__PostgreSQL", vmLoggingDb.Resource.ConnectionStringExpression)
8190
.WithEnvironment("Authorization__Authority", "http://localhost:8080/realms/crucible")
@@ -112,6 +121,7 @@ public static void AddCaster(this IDistributedApplicationBuilder builder, IResou
112121
.WithHttpHealthCheck("api/health/ready")
113122
.WithReference(casterDb, "PostgreSQL")
114123
.WithEnvironment("Database__Provider", "PostgreSQL")
124+
.WithEnvironment("Database__DevModeRecreate", "false")
115125
.WithEnvironment("Authorization__Authority", "http://localhost:8080/realms/crucible")
116126
.WithEnvironment("Authorization__AuthorizationUrl", "http://localhost:8080/realms/crucible/protocol/openid-connect/auth")
117127
.WithEnvironment("Authorization__TokenUrl", "http://localhost:8080/realms/crucible/protocol/openid-connect/token")
@@ -138,6 +148,7 @@ public static void AddAlloy(this IDistributedApplicationBuilder builder, IResour
138148
.WithHttpHealthCheck("api/health/ready")
139149
.WithReference(alloyDb, "PostgreSQL")
140150
.WithEnvironment("Database__Provider", "PostgreSQL")
151+
.WithEnvironment("Database__DevModeRecreate", "false")
141152
.WithEnvironment("Authorization__Authority", "http://localhost:8080/realms/crucible")
142153
.WithEnvironment("Authorization__AuthorizationUrl", "http://localhost:8080/realms/crucible/protocol/openid-connect/auth")
143154
.WithEnvironment("Authorization__TokenUrl", "http://localhost:8080/realms/crucible/protocol/openid-connect/token")
@@ -172,6 +183,7 @@ public static void AddTopoMojo(this IDistributedApplicationBuilder builder, IRes
172183
.WithReference(topoDb, "PostgreSQL")
173184
.WithEnvironment("Database__ConnectionString", topoDb.Resource.ConnectionStringExpression)
174185
.WithEnvironment("Database__Provider", "PostgreSQL")
186+
.WithEnvironment("Database__DevModeRecreate", "false")
175187
.WithEnvironment("Oidc__Authority", "http://localhost:8080/realms/crucible")
176188
.WithEnvironment("Oidc__Audience", "topomojo")
177189
.WithEnvironment("OpenApi__Client__AuthorizationUrl", "http://localhost:8080/realms/crucible/protocol/openid-connect/auth")
@@ -209,15 +221,17 @@ public static void AddSteamfitter(this IDistributedApplicationBuilder builder, I
209221
.WithHttpHealthCheck("api/health/ready")
210222
.WithReference(steamfitterDb, "PostgreSQL")
211223
.WithEnvironment("Database__Provider", "PostgreSQL")
224+
.WithEnvironment("Database__DevModeRecreate", "false")
212225
.WithEnvironment("Authorization__Authority", "http://localhost:8080/realms/crucible")
213226
.WithEnvironment("Authorization__AuthorizationUrl", "http://localhost:8080/realms/crucible/protocol/openid-connect/auth")
214227
.WithEnvironment("Authorization__TokenUrl", "http://localhost:8080/realms/crucible/protocol/openid-connect/token")
228+
.WithEnvironment("Authorization__AuthorizationScope", "steamfitter player player-vm")
215229
.WithEnvironment("Authorization__ClientId", "steamfitter.api")
216230
.WithEnvironment("ResourceOwnerAuthorization__Authority", "http://localhost:8080/realms/crucible")
217231
.WithEnvironment("ResourceOwnerAuthorization__ClientId", "steamfitter.admin")
218232
.WithEnvironment("ResourceOwnerAuthorization__UserName", "admin")
219233
.WithEnvironment("ResourceOwnerAuthorization__Password", "admin")
220-
.WithEnvironment("ResourceOwnerAuthorization__Scope", "player player-vm alloy steamfitter caster")
234+
.WithEnvironment("ResourceOwnerAuthorization__Scope", "steamfitter player player-vm cite gallery")
221235
.WithEnvironment("ResourceOwnerAuthorization__ValidateDiscoveryDocument", "false");
222236

223237
var steamfitterUiRoot = "/mnt/data/crucible/steamfitter/steamfitter.ui";
@@ -241,15 +255,17 @@ public static void AddCite(this IDistributedApplicationBuilder builder, IResourc
241255
.WithHttpHealthCheck("api/health/ready")
242256
.WithReference(citeDb, "PostgreSQL")
243257
.WithEnvironment("Database__Provider", "PostgreSQL")
258+
.WithEnvironment("Database__DevModeRecreate", "false")
244259
.WithEnvironment("Authorization__Authority", "http://localhost:8080/realms/crucible")
245260
.WithEnvironment("Authorization__AuthorizationUrl", "http://localhost:8080/realms/crucible/protocol/openid-connect/auth")
246261
.WithEnvironment("Authorization__TokenUrl", "http://localhost:8080/realms/crucible/protocol/openid-connect/token")
262+
.WithEnvironment("Authorization__AuthorizationScope", "cite")
247263
.WithEnvironment("Authorization__ClientId", "cite.api")
248264
.WithEnvironment("ResourceOwnerAuthorization__Authority", "http://localhost:8080/realms/crucible")
249265
.WithEnvironment("ResourceOwnerAuthorization__ClientId", "cite.admin")
250266
.WithEnvironment("ResourceOwnerAuthorization__UserName", "admin")
251267
.WithEnvironment("ResourceOwnerAuthorization__Password", "admin")
252-
.WithEnvironment("ResourceOwnerAuthorization__Scope", "player player-vm cite steamfitter caster")
268+
.WithEnvironment("ResourceOwnerAuthorization__Scope", "openid profile email cite gallery")
253269
.WithEnvironment("ResourceOwnerAuthorization__ValidateDiscoveryDocument", "false");
254270

255271
var citeUiRoot = "/mnt/data/crucible/cite/cite.ui";
@@ -273,15 +289,17 @@ public static void AddGallery(this IDistributedApplicationBuilder builder, IReso
273289
.WithHttpHealthCheck("api/health/ready")
274290
.WithReference(galleryDb, "PostgreSQL")
275291
.WithEnvironment("Database__Provider", "PostgreSQL")
292+
.WithEnvironment("Database__DevModeRecreate", "false")
276293
.WithEnvironment("Authorization__Authority", "http://localhost:8080/realms/crucible")
277294
.WithEnvironment("Authorization__AuthorizationUrl", "http://localhost:8080/realms/crucible/protocol/openid-connect/auth")
278295
.WithEnvironment("Authorization__TokenUrl", "http://localhost:8080/realms/crucible/protocol/openid-connect/token")
296+
.WithEnvironment("Authorization__AuthorizationScope", "gallery")
279297
.WithEnvironment("Authorization__ClientId", "gallery.api")
280298
.WithEnvironment("ResourceOwnerAuthorization__Authority", "http://localhost:8080/realms/crucible")
281299
.WithEnvironment("ResourceOwnerAuthorization__ClientId", "gallery.admin")
282300
.WithEnvironment("ResourceOwnerAuthorization__UserName", "admin")
283301
.WithEnvironment("ResourceOwnerAuthorization__Password", "admin")
284-
.WithEnvironment("ResourceOwnerAuthorization__Scope", "player player-vm gallery steamfitter caster")
302+
.WithEnvironment("ResourceOwnerAuthorization__Scope", "player player-vm steamfitter")
285303
.WithEnvironment("ResourceOwnerAuthorization__ValidateDiscoveryDocument", "false");
286304

287305
var galleryUiRoot = "/mnt/data/crucible/gallery/gallery.ui";
@@ -305,6 +323,7 @@ public static void AddBlueprint(this IDistributedApplicationBuilder builder, IRe
305323
.WithHttpHealthCheck("api/health/ready")
306324
.WithReference(blueprintDb, "PostgreSQL")
307325
.WithEnvironment("Database__Provider", "PostgreSQL")
326+
.WithEnvironment("Database__DevModeRecreate", "false")
308327
.WithEnvironment("Authorization__Authority", "http://localhost:8080/realms/crucible")
309328
.WithEnvironment("Authorization__AuthorizationUrl", "http://localhost:8080/realms/crucible/protocol/openid-connect/auth")
310329
.WithEnvironment("Authorization__TokenUrl", "http://localhost:8080/realms/crucible/protocol/openid-connect/token")
@@ -313,7 +332,7 @@ public static void AddBlueprint(this IDistributedApplicationBuilder builder, IRe
313332
.WithEnvironment("ResourceOwnerAuthorization__ClientId", "blueprint.admin")
314333
.WithEnvironment("ResourceOwnerAuthorization__UserName", "admin")
315334
.WithEnvironment("ResourceOwnerAuthorization__Password", "admin")
316-
.WithEnvironment("ResourceOwnerAuthorization__Scope", "player player-vm blueprint steamfitter caster")
335+
.WithEnvironment("ResourceOwnerAuthorization__Scope", "player player-vm gallery steamfitter cite")
317336
.WithEnvironment("ResourceOwnerAuthorization__ValidateDiscoveryDocument", "false");
318337

319338
var blueprintUiRoot = "/mnt/data/crucible/blueprint/blueprint.ui";

Crucible.AppHost/resources/crucible-realm.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,6 +1761,7 @@
17611761
"roles",
17621762
"profile",
17631763
"cite",
1764+
"gallery",
17641765
"email"
17651766
],
17661767
"optionalClientScopes": [
@@ -2087,7 +2088,6 @@
20872088
"nodeReRegistrationTimeout": -1,
20882089
"defaultClientScopes": [
20892090
"web-origins",
2090-
"blueprint",
20912091
"acr",
20922092
"openid",
20932093
"roles",
@@ -3639,23 +3639,23 @@
36393639
"notBefore" : 0,
36403640
"groups" : [ ]
36413641
}, {
3642-
"id" : "5cad7558-7a92-4385-8246-1a31aa29aa59",
3642+
"id" : "9fd3c38e-58b0-4af1-80d1-1895af91f1f9",
36433643
"createdTimestamp" : 1730729236429,
3644-
"username" : "aschlack",
3644+
"username" : "OGadmin",
36453645
"enabled" : true,
36463646
"totp" : false,
36473647
"emailVerified" : false,
3648-
"firstName" : "Andrew",
3649-
"lastName" : "Schlackman",
3648+
"firstName" : "OG",
3649+
"lastName" : "Admin",
36503650
"attributes" : {
36513651
"terms_and_conditions" : [ "1730729259" ]
36523652
},
36533653
"credentials" : [ {
3654-
"id" : "039c2699-f3b6-4f00-a3e3-25ac37964efe",
3654+
"id" : "930c2699-f3b6-4f00-a3e3-25ac37964fef",
36553655
"type" : "password",
36563656
"userLabel" : "My password",
36573657
"createdDate" : 1730729246788,
3658-
"secretData" : "{\"value\":\"7tyeoBxftnEZ/uSn6bapzvcXK1puAtW0I8rdsiUK8QM=\",\"salt\":\"WI3T2+ACdtSBRoGG6LQrsw==\",\"additionalParameters\":{}}",
3658+
"secretData" : "{\"value\":\"3E3znP6H4/QTbd2w1PznMm+PIygqTmvznggrzAarD+8=\",\"salt\":\"ldA2KO1HhEv6xQxWhktn3Q==\",\"additionalParameters\":{}}",
36593659
"credentialData" : "{\"hashIterations\":27500,\"algorithm\":\"pbkdf2-sha256\",\"additionalParameters\":{}}"
36603660
} ],
36613661
"disableableCredentialTypes" : [ ],
@@ -3852,4 +3852,4 @@
38523852
"notBefore" : 0,
38533853
"groups" : [ ]
38543854
} ]
3855-
}
3855+
}

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ If you're on a Windows machine, Docker's consumption of your host machine's memo
1919
- Memory Limit: 16GB
2020
- Disk Usage Limit: 120GB
2121

22+
### zscalar
23+
24+
The dev container is designed to work with zscalar. You will need to copy the required certs into the **.devcontainer/certs** folder.
25+
2226
## Troubleshooting
2327

2428
This repo is still under construction, so you may run into the occasional challenge or oddity. From our lessons learned:
@@ -29,3 +33,26 @@ This repo is still under construction, so you may run into the occasional challe
2933
## Known issues
3034

3135
- Some extensions (e.g. C#) very rarely seem to fail to install in the container's VS Code environment. If you see weird intellisense behavior or have compilation/debugging problems, ensure all extensions in the `devcontainers.json` file are installed in your container.
36+
37+
38+
# Database seeding and backup
39+
## setup
40+
... using blueprint as the example
41+
create a db-dumps folder under crucible-dev
42+
copy your blueprint.dump file into the db-dumps folder
43+
44+
## seed/restore a database
45+
navigate to the db-dumps folder in the integrated terminal
46+
drop the blueprint database using pgadmin
47+
create a new blueprint database using pgadmin
48+
assuming crucible-postgres is the postgres container name,
49+
docker cp blueprint.dump crucible-postgres:/tmp/blueprint.dump
50+
docker exec -it crucible-postgres /bin/bash
51+
/usr/lib/postgresql/17/bin/psql --username=postgres blueprint < /tmp/blueprint.dump
52+
exit
53+
54+
## backup/dump a database
55+
docker exec -it crucible-postgres /bin/bash
56+
pg_dump -U postgres blueprint > /tmp/blueprint.dump
57+
exit
58+
docker cp crucible-postgres:/tmp/blueprint.dump blueprint.dump

0 commit comments

Comments
 (0)