Skip to content
Closed
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
3 changes: 2 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<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.Docker" Version="13.3.0-preview.1.26169.7" />
<PackageVersion Include="Aspire.Hosting.Elasticsearch" Version="13.1.0" />
<PackageVersion Include="Aspire.Hosting.Keycloak" Version="$(AspireVersion)$(AspirePreviewSuffix)" />
<PackageVersion Include="Aspire.Keycloak.Authentication" Version="$(AspireVersion)$(AspirePreviewSuffix)" />
Expand Down Expand Up @@ -130,4 +131,4 @@
<ItemGroup Label="Overrides">
<PackageVersion Include="Microsoft.Bcl.Memory" Version="9.0.14" />
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:5050",
"sslPort": 5051
}
},
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"http": {
"commandName": "Project",
Expand All @@ -28,14 +20,6 @@
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@
<ProjectReference Include="..\..\..\src\CommunityToolkit.Aspire.Hosting.Java\CommunityToolkit.Aspire.Hosting.Java.csproj" IsAspireProjectResource="false" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Aspire.Hosting.Docker" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
var builder = DistributedApplication.CreateBuilder(args);

var apiapp = builder.AddProject<Projects.CommunityToolkit_Aspire_Hosting_Java_ApiApp>("apiapp");
builder.AddDockerComposeEnvironment("env");

var apiapp = builder.AddProject<Projects.CommunityToolkit_Aspire_Hosting_Java_ApiApp>("apiapp")
.WithExternalHttpEndpoints();

var containerapp = builder.AddJavaContainerApp("containerapp", image: "docker.io/aliencube/aspire-spring-maven-sample")
.WithOtelAgent("/agents/opentelemetry-javaagent.jar")
.WithHttpEndpoint(targetPort: 8080, env: "SERVER_PORT");
.WithHttpEndpoint(targetPort: 8080, env: "SERVER_PORT")
.WithExternalHttpEndpoints();

var executableapp = builder.AddJavaApp("executableapp",
workingDirectory: "../CommunityToolkit.Aspire.Hosting.Java.Spring.Maven")
.WithMavenGoal("spring-boot:run")
.WithOtelAgent("../../../agents/opentelemetry-javaagent.jar")
.WithHttpEndpoint(targetPort: 8080, env: "SERVER_PORT")
.WithHttpHealthCheck("/health");
.WithHttpHealthCheck("/health")
.WithExternalHttpEndpoints();

var webapp = builder.AddProject<Projects.CommunityToolkit_Aspire_Hosting_Java_WebApp>("webapp")
.WithExternalHttpEndpoints()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Container image name for apiapp
APIAPP_IMAGE=

# Default container port for apiapp
APIAPP_PORT=

# Container image name for executableapp
EXECUTABLEAPP_IMAGE=

# Container image name for webapp
WEBAPP_IMAGE=

# Default container port for webapp
WEBAPP_PORT=

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Container image name for apiapp
APIAPP_IMAGE=apiapp:aspire-deploy-20260320212742

# Default container port for apiapp
APIAPP_PORT=8080

# Container image name for executableapp
EXECUTABLEAPP_IMAGE=executableapp:aspire-deploy-20260320212742

# Container image name for webapp
WEBAPP_IMAGE=webapp:aspire-deploy-20260320212742

# Default container port for webapp
WEBAPP_PORT=8080

Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
services:
env-dashboard:
image: "mcr.microsoft.com/dotnet/nightly/aspire-dashboard:latest"
ports:
- "18888"
expose:
- "18889"
- "18890"
networks:
- "aspire"
restart: "always"
apiapp:
image: "${APIAPP_IMAGE}"
environment:
OTEL_DOTNET_EXPERIMENTAL_OTLP_RETRY: "in_memory"
ASPNETCORE_FORWARDEDHEADERS_ENABLED: "true"
HTTP_PORTS: "${APIAPP_PORT}"
OTEL_EXPORTER_OTLP_ENDPOINT: "http://env-dashboard:18889"
OTEL_EXPORTER_OTLP_PROTOCOL: "grpc"
OTEL_SERVICE_NAME: "apiapp"
ports:
- "${APIAPP_PORT}"
networks:
- "aspire"
containerapp:
image: "docker.io/aliencube/aspire-spring-maven-sample:latest"
environment:
JAVA_TOOL_OPTIONS: "-javaagent:/agents/opentelemetry-javaagent.jar"
SERVER_PORT: "8080"
OTEL_EXPORTER_OTLP_ENDPOINT: "http://env-dashboard:18889"
OTEL_EXPORTER_OTLP_PROTOCOL: "grpc"
OTEL_SERVICE_NAME: "containerapp"
ports:
- "8080"
networks:
- "aspire"
executableapp:
image: "${EXECUTABLEAPP_IMAGE}"
environment:
JAVA_TOOL_OPTIONS: "-javaagent:../../../agents/opentelemetry-javaagent.jar"
SERVER_PORT: "8080"
OTEL_EXPORTER_OTLP_ENDPOINT: "http://env-dashboard:18889"
OTEL_EXPORTER_OTLP_PROTOCOL: "grpc"
OTEL_SERVICE_NAME: "executableapp"
ports:
- "8080"
networks:
- "aspire"
webapp:
image: "${WEBAPP_IMAGE}"
environment:
OTEL_DOTNET_EXPERIMENTAL_OTLP_RETRY: "in_memory"
ASPNETCORE_FORWARDEDHEADERS_ENABLED: "true"
HTTP_PORTS: "${WEBAPP_PORT}"
CONTAINERAPP_HTTP: "http://containerapp:8080"
services__containerapp__http__0: "http://containerapp:8080"
EXECUTABLEAPP_HTTP: "http://executableapp:8080"
services__executableapp__http__0: "http://executableapp:8080"
APIAPP_HTTP: "http://apiapp:${APIAPP_PORT}"
services__apiapp__http__0: "http://apiapp:${APIAPP_PORT}"
APIAPP_HTTPS: "https://apiapp:${APIAPP_PORT}"
OTEL_EXPORTER_OTLP_ENDPOINT: "http://env-dashboard:18889"
OTEL_EXPORTER_OTLP_PROTOCOL: "grpc"
OTEL_SERVICE_NAME: "webapp"
ports:
- "${WEBAPP_PORT}"
networks:
- "aspire"
networks:
aspire:
driver: "bridge"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"appHost": {
"path": "CommunityToolkit.Aspire.Hosting.Java.AppHost.csproj"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ public static IResourceBuilder<JavaAppExecutableResource> AddJavaApp(this IDistr
context.Args.Add("-jar");
context.Args.Add(resource.JarPath);
}
});
})
.PublishAsJavaDockerfile();

return resourceBuilder;
}
Expand Down Expand Up @@ -111,11 +112,13 @@ public static IResourceBuilder<JavaAppExecutableResource> AddJavaApp(this IDistr

workingDirectory = PathNormalizer.NormalizePathForCurrentPlatform(Path.Combine(builder.AppHostDirectory, workingDirectory));
var resource = new JavaAppExecutableResource(name, "java", workingDirectory);
resource.JarPath = options.ApplicationName;

return builder.AddResource(resource)
.WithJavaDefaults(options)
.WithHttpEndpoint(port: options.Port, name: JavaAppContainerResource.HttpEndpointName, isProxied: false)
.WithArgs(allArgs);
.WithArgs(allArgs)
.PublishAsJavaDockerfile();
}

/// <summary>
Expand Down Expand Up @@ -172,11 +175,14 @@ public static IResourceBuilder<JavaAppExecutableResource> WithMavenBuild(
? wrapper.WrapperPath
: Path.GetFullPath(Path.Combine(builder.Resource.WorkingDirectory, DefaultMavenWrapper));

return builder.WithJavaBuildStep(
buildResourceName: $"{builder.Resource.Name}-maven-build",
createResource: (name, wrapperScript, workingDirectory) => new MavenBuildResource(name, wrapperScript, workingDirectory),
wrapperPath: resolvedWrapper,
buildArgs: args.Length > 0 ? args : ["clean", "package"]);
string[] resolvedBuildArgs = args.Length > 0 ? args : ["clean", "package"];

return builder.WithPublishBuildAnnotation(JavaBuildTool.Maven, resolvedBuildArgs)
.WithJavaBuildStep(
buildResourceName: $"{builder.Resource.Name}-maven-build",
createResource: (name, wrapperScript, workingDirectory) => new MavenBuildResource(name, wrapperScript, workingDirectory),
wrapperPath: resolvedWrapper,
buildArgs: resolvedBuildArgs);
}

/// <summary>
Expand All @@ -197,11 +203,14 @@ public static IResourceBuilder<JavaAppExecutableResource> WithGradleBuild(
? wrapper.WrapperPath
: Path.GetFullPath(Path.Combine(builder.Resource.WorkingDirectory, DefaultGradleWrapper));

return builder.WithJavaBuildStep(
buildResourceName: $"{builder.Resource.Name}-gradle-build",
createResource: (name, wrapperScript, workingDirectory) => new GradleBuildResource(name, wrapperScript, workingDirectory),
wrapperPath: resolvedWrapper,
buildArgs: args.Length > 0 ? args : ["clean", "build"]);
string[] resolvedBuildArgs = args.Length > 0 ? args : ["clean", "build"];

return builder.WithPublishBuildAnnotation(JavaBuildTool.Gradle, resolvedBuildArgs)
.WithJavaBuildStep(
buildResourceName: $"{builder.Resource.Name}-gradle-build",
createResource: (name, wrapperScript, workingDirectory) => new GradleBuildResource(name, wrapperScript, workingDirectory),
wrapperPath: resolvedWrapper,
buildArgs: resolvedBuildArgs);
}

private static IResourceBuilder<JavaAppExecutableResource> WithJavaBuildStep<TBuildResource>(
Expand All @@ -226,6 +235,20 @@ private static IResourceBuilder<JavaAppExecutableResource> WithJavaBuildStep<TBu
return builder;
}

private static IResourceBuilder<JavaAppExecutableResource> WithPublishBuildAnnotation(
this IResourceBuilder<JavaAppExecutableResource> builder,
JavaBuildTool tool,
string[] buildArgs)
{
string? wrapperPath = builder.Resource.TryGetLastAnnotation<WrapperAnnotation>(out var wrapper)
? wrapper.WrapperPath
: null;

builder.Resource.Annotations.Add(new JavaPublishBuildAnnotation(tool, wrapperPath, buildArgs));

return builder;
}

/// <summary>
/// Configures the Java application to run using a Maven goal (e.g., <c>spring-boot:run</c>).
/// In run mode, the resource command is changed from <c>java</c> to the Maven wrapper.
Expand Down Expand Up @@ -254,7 +277,8 @@ public static IResourceBuilder<JavaAppExecutableResource> WithMavenGoal(
: Path.GetFullPath(Path.Combine(builder.Resource.WorkingDirectory, DefaultMavenWrapper));

builder.Resource.Annotations.Add(
new JavaBuildToolAnnotation(resolvedWrapper, args is { Length: > 0 } ? [goal, .. args] : [goal]));
new JavaBuildToolAnnotation(JavaBuildTool.Maven, resolvedWrapper, args is { Length: > 0 } ? [goal, .. args] : [goal]));
builder.WithPublishBuildAnnotation(JavaBuildTool.Maven, ["package"]);

if (builder.ApplicationBuilder.ExecutionContext.IsRunMode)
{
Expand Down Expand Up @@ -292,7 +316,8 @@ public static IResourceBuilder<JavaAppExecutableResource> WithGradleTask(
: Path.GetFullPath(Path.Combine(builder.Resource.WorkingDirectory, DefaultGradleWrapper));

builder.Resource.Annotations.Add(
new JavaBuildToolAnnotation(resolvedWrapper, args is { Length: > 0 } ? [task, .. args] : [task]));
new JavaBuildToolAnnotation(JavaBuildTool.Gradle, resolvedWrapper, args is { Length: > 0 } ? [task, .. args] : [task]));
builder.WithPublishBuildAnnotation(JavaBuildTool.Gradle, ["build"]);

if (builder.ApplicationBuilder.ExecutionContext.IsRunMode)
{
Expand Down
Loading
Loading