Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public static IResourceBuilder<RavenDBServerResource> AddRavenDB(this IDistribut
ClientCertificate = securedSettings?.ClientCertificate
};

return AddRavenDbInternal(builder, name, serverResource, environmentVariables, serverSettings.Port, serverSettings.TcpPort);
return AddRavenDbInternal(builder, name, serverResource, environmentVariables, serverSettings.Port,
serverSettings.TcpPort, serverSettings.ForceTcpScheme);
}

/// <summary>
Expand Down Expand Up @@ -100,7 +101,8 @@ private static IResourceBuilder<RavenDBServerResource> AddRavenDbInternal(
RavenDBServerResource serverResource,
Dictionary<string, object> environmentVariables,
int? port,
int? tcpPort)
int? tcpPort,
bool? forceTcpScheme = false)
{
string? connectionString = null;
builder.Eventing.Subscribe<ConnectionStringAvailableEvent>(serverResource, async (_, ct) =>
Expand All @@ -120,12 +122,13 @@ private static IResourceBuilder<RavenDBServerResource> AddRavenDbInternal(
certificate: serverResource.ClientCertificate);

var effectiveTcpPort = tcpPort ?? 38888;
var useTcpScheme = forceTcpScheme ?? false;

return builder.AddResource(serverResource)
.WithEndpoint(
port: port,
targetPort: serverResource.IsSecured ? 443 : 8080,
scheme: serverResource.PrimaryEndpointName,
scheme: useTcpScheme? "tcp" : serverResource.PrimaryEndpointName,
name: serverResource.PrimaryEndpointName,
isProxied: false)
.WithEndpoint(
Expand Down Expand Up @@ -172,7 +175,8 @@ private static Dictionary<string, object> GetEnvironmentVariablesFromServerSetti

private static void ConfigureEnvironmentVariables(EnvironmentCallbackContext context, RavenDBServerResource serverResource, Dictionary<string, object>? environmentVariables = null)
{
context.EnvironmentVariables.TryAdd("RAVEN_ServerUrl_Tcp", $"{serverResource.TcpEndpoint.Scheme}://0.0.0.0:{serverResource.TcpEndpoint.Port}");
var tcpPort = serverResource.TcpEndpoint.IsAllocated ? serverResource.TcpEndpoint.Port : serverResource.TcpEndpoint.TargetPort;
context.EnvironmentVariables.TryAdd("RAVEN_ServerUrl_Tcp", $"{serverResource.TcpEndpoint.Scheme}://0.0.0.0:{tcpPort}");

if (environmentVariables is null)
{
Expand All @@ -185,7 +189,19 @@ private static void ConfigureEnvironmentVariables(EnvironmentCallbackContext con
context.EnvironmentVariables.TryAdd(environmentVariable.Key, environmentVariable.Value);
}

context.EnvironmentVariables.TryAdd("RAVEN_PublicServerUrl_Tcp", serverResource.TcpEndpoint.Url);
if (serverResource.TcpEndpoint.IsAllocated)
{
context.EnvironmentVariables.TryAdd("RAVEN_PublicServerUrl_Tcp", serverResource.TcpEndpoint.Url);
}
// Tcp endpoint is not allocated yet when we're generating manifest (e.g. aspire plugins)
// In such a case, just check if the public server url isn't set manually by the user
// If it is, use it with the container target port explicitly to generate the correct manifest
else if (serverResource.PublicServerUrl is not null)
{
string publicHost = new Uri(serverResource.PublicServerUrl).Host;
string publicServerUrlTcp = $"tcp://{publicHost}:{serverResource.TcpEndpoint.TargetPort}";
context.EnvironmentVariables.TryAdd("RAVEN_PublicServerUrl_Tcp", publicServerUrlTcp);
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ public class RavenDBServerSettings
/// If not set, the default 38888 is used.
/// </summary>
public int? TcpPort { get; set; }


/// <summary>
/// Advanced/debug optional parameter that forces the TCP scheme for the RavenDB server URL.
/// Useful for deployment scenarios with constrained http(s):// schema usage (e.g., only port 80 can use http)
/// </summary>
public bool? ForceTcpScheme { get; set; }

/// <summary>
/// Protected constructor to allow inheritance but prevent direct instantiation.
Expand Down
Loading