-
Notifications
You must be signed in to change notification settings - Fork 129
Add Keycloak with Postgres integration #811
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
0df225d
2e07fa8
1bf7ea7
90621f4
7a4fc17
9b11f66
03cbc0a
53c7ca1
9c913c5
d77acaf
fcfad00
6cd7d93
d4720a9
3962aa1
beb9fe9
e01ce34
19c6f9a
31a647b
cdd4b15
1ba736e
1efdbbc
afb6c43
993aa3e
6eeee8c
8514cab
7513876
8d7af9f
2c66428
d504e4c
5db02af
c5b5d8d
5424687
fe16c1f
50db669
9d0a369
96e174f
fedcf87
6c968b4
b1d9793
a7422fe
bbbb8d4
9055d7b
81bb900
4a801e9
cab3674
1e5d94d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,13 @@ | |
</PropertyGroup> | ||
<ItemGroup Label="Aspire Packages"> | ||
<!-- Aspire packages --> | ||
<PackageVersion Include="Aspire.Hosting" Version="$(AspireVersion)" /> | ||
<PackageVersion Include="Aspire.Hosting" Version="9.4.1" /> | ||
<PackageVersion Include="Aspire.Hosting.AppHost" Version="$(AspireVersion)" /> | ||
<PackageVersion Include="Aspire.Hosting.Azure.Storage" Version="$(AspireVersion)" /> | ||
<PackageVersion Include="Aspire.Hosting.Dapr" Version="$(AspireVersion)" /> | ||
<PackageVersion Include="Aspire.Hosting.Azure.AppContainers" Version="$(AspireVersion)" /> | ||
<PackageVersion Include="Aspire.Hosting.Azure.Redis" Version="$(AspireVersion)" /> | ||
<PackageVersion Include="Aspire.Hosting.Keycloak" Version="9.4.1-preview.1.25408.4" /> | ||
|
||
<PackageVersion Include="Aspire.Hosting.NodeJS" Version="$(AspireVersion)" /> | ||
<PackageVersion Include="Aspire.Hosting.PostgreSQL" Version="$(AspireVersion)" /> | ||
<PackageVersion Include="Aspire.Hosting.Python" Version="$(AspireVersion)" /> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The package name should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can i name it like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there may be other providers here. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net9.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Aspire.Hosting" /> | ||
<PackageReference Include="Aspire.Hosting.Keycloak" /> | ||
<PackageReference Include="Aspire.Hosting.PostgreSQL" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using Aspire.Hosting; | ||
using Aspire.Hosting.ApplicationModel; | ||
using Npgsql; | ||
|
||
namespace CommunityToolkit.Aspire.Keycloak.Postgress; | ||
|
||
/// <summary> | ||
/// Provides extension methods for configuring Keycloak with a Postgres database | ||
/// in a resource builder. | ||
/// </summary> | ||
public static class KeycloakPostgresExtension | ||
{ | ||
/// <summary> | ||
/// Configures Keycloak with a Postgres database using the provided resource builders. | ||
/// This method sets environment variables required for Keycloak to connect to PostgreSQL. | ||
/// </summary> | ||
/// <param name="builder"> | ||
/// The resource builder for the Keycloak resource. It is required for defining Keycloak settings. | ||
/// </param> | ||
/// <param name="database"> | ||
/// The resource builder for the Postgres database resource. It provides connection string | ||
/// information and other database-related configurations. | ||
/// </param> | ||
/// <param name="transaction"> | ||
/// A boolean indicating whether transactions should be enabled in the configuration. Default is true. | ||
/// </param> | ||
/// <param name="port"> | ||
/// The port number on which the Postgres database is running. Default is 5432. | ||
/// </param> | ||
public static void AddPostgrctes(this IResourceBuilder<KeycloakResource> builder, | ||
axies20 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
IResourceBuilder<PostgresDatabaseResource> database, bool transaction = true, int port = 5432) | ||
{ | ||
ArgumentNullException.ThrowIfNull(builder); | ||
ArgumentNullException.ThrowIfNull(database); | ||
|
||
|
||
database.OnConnectionStringAvailable(async (dataResource, _, cancellationToken) => | ||
{ | ||
NpgsqlConnectionStringBuilder npg = | ||
new(await dataResource.ConnectionStringExpression.GetValueAsync(cancellationToken)); | ||
builder.WithEnvironment("KC_DB", "postgres") | ||
.WithEnvironment("KC_DB", "postgres") | ||
.WithEnvironment("KC_DB_URL", | ||
$"jdbc:postgresql://{dataResource.Parent.Name}:{port.ToString()}/{npg.Database}") | ||
.WithEnvironment("KC_DB_USERNAME", npg.Username) | ||
.WithEnvironment("KC_DB_PASSWORD", npg.Password); | ||
}); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume this is just done when you were testing, but ensure you roll that back and use the MSBuild variable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had error
0>CommunityToolkit.Aspire.Keycloak.Postgres.csproj: Error NU1605 : Warning As Error: Detected package downgrade: Aspire.Hosting from 9.4.1 to 9.4.0. Reference the package directly from the project to select a different version.
CommunityToolkit.Aspire.Keycloak.Postgres -> Aspire.Hosting.Keycloak 9.4.1-preview.1.25408.4 -> Aspire.Hosting (>= 9.4.1)
CommunityToolkit.Aspire.Keycloak.Postgres -> Aspire.Hosting (>= 9.4.0)
0>------- Finished building project: CommunityToolkit.Aspire.Keycloak.Postgres. Succeeded: False. Errors: 1. Warnings: 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
main
branch is now updated to 9.4.1 Aspire.