-
Notifications
You must be signed in to change notification settings - Fork 915
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate test apps for spring-ai projects
Add support for Testcontainers and Docker Compose. See gh-1484
- Loading branch information
1 parent
1f3d44a
commit 25f4998
Showing
23 changed files
with
875 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...tart/site/extension/dependency/springai/SpringAiChromaProjectGenerationConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright 2012-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.spring.start.site.extension.dependency.springai; | ||
|
||
import io.spring.initializr.generator.condition.ConditionalOnRequestedDependency; | ||
import io.spring.initializr.generator.project.ProjectDescription; | ||
import io.spring.initializr.generator.project.ProjectGenerationConfiguration; | ||
import io.spring.initializr.metadata.InitializrMetadata; | ||
import io.spring.start.site.container.ComposeFileCustomizer; | ||
import io.spring.start.site.container.DockerServiceResolver; | ||
import io.spring.start.site.container.ServiceConnections.ServiceConnection; | ||
import io.spring.start.site.container.ServiceConnectionsCustomizer; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
|
||
/** | ||
* Configuration for generation of projects that depend on Chroma. | ||
* | ||
* @author Eddú Meléndez | ||
*/ | ||
@ProjectGenerationConfiguration | ||
@ConditionalOnRequestedDependency("spring-ai-vectordb-chroma") | ||
class SpringAiChromaProjectGenerationConfiguration { | ||
|
||
private static final String TESTCONTAINERS_CLASS_NAME = "org.testcontainers.chromadb.ChromaDBContainer"; | ||
|
||
@Bean | ||
@ConditionalOnRequestedDependency("testcontainers") | ||
ServiceConnectionsCustomizer chromaServiceConnectionsCustomizer(InitializrMetadata metadata, | ||
ProjectDescription description, DockerServiceResolver serviceResolver) { | ||
return (serviceConnections) -> { | ||
if (SpringAiVersion.version1OrLater(metadata, description.getPlatformVersion())) { | ||
serviceResolver.doWith("chroma", (service) -> serviceConnections | ||
.addServiceConnection(ServiceConnection.ofContainer("chroma", service, TESTCONTAINERS_CLASS_NAME))); | ||
} | ||
}; | ||
} | ||
|
||
@Bean | ||
@ConditionalOnRequestedDependency("docker-compose") | ||
ComposeFileCustomizer chromaComposeFileCustomizer(InitializrMetadata metadata, ProjectDescription description, | ||
DockerServiceResolver serviceResolver) { | ||
return (composeFile) -> { | ||
if (SpringAiVersion.version1OrLater(metadata, description.getPlatformVersion())) { | ||
serviceResolver.doWith("chroma", (service) -> composeFile.services().add("chroma", service)); | ||
} | ||
}; | ||
} | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
...te/extension/dependency/springai/SpringAiDockerComposeProjectGenerationConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright 2012-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.spring.start.site.extension.dependency.springai; | ||
|
||
import io.spring.initializr.generator.buildsystem.Build; | ||
import io.spring.initializr.generator.buildsystem.Dependency; | ||
import io.spring.initializr.generator.buildsystem.DependencyScope; | ||
import io.spring.initializr.generator.condition.ConditionalOnRequestedDependency; | ||
import io.spring.initializr.generator.project.ProjectDescription; | ||
import io.spring.initializr.generator.project.ProjectGenerationConfiguration; | ||
import io.spring.initializr.generator.spring.build.BuildCustomizer; | ||
import io.spring.initializr.metadata.InitializrMetadata; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
|
||
/** | ||
* Configuration for generation of projects that depend on Spring AI Docker Compose. | ||
* | ||
* @author Eddú Meléndez | ||
*/ | ||
@ProjectGenerationConfiguration | ||
@ConditionalOnRequestedDependency("docker-compose") | ||
class SpringAiDockerComposeProjectGenerationConfiguration { | ||
|
||
@Bean | ||
BuildCustomizer<Build> springAiDockerComposeBuildCustomizer(InitializrMetadata metadata, | ||
ProjectDescription description) { | ||
return (build) -> { | ||
if (SpringAiVersion.version1OrLater(metadata, description.getPlatformVersion())) { | ||
build.dependencies() | ||
.add("spring-ai-docker-compose", | ||
Dependency.withCoordinates("org.springframework.ai", "spring-ai-spring-boot-docker-compose") | ||
.scope(DependencyScope.TEST_COMPILE)); | ||
} | ||
}; | ||
} | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
...tart/site/extension/dependency/springai/SpringAiMilvusProjectGenerationConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright 2012-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.spring.start.site.extension.dependency.springai; | ||
|
||
import io.spring.initializr.generator.condition.ConditionalOnRequestedDependency; | ||
import io.spring.initializr.generator.project.ProjectDescription; | ||
import io.spring.initializr.generator.project.ProjectGenerationConfiguration; | ||
import io.spring.initializr.metadata.InitializrMetadata; | ||
import io.spring.start.site.container.DockerServiceResolver; | ||
import io.spring.start.site.container.ServiceConnections.ServiceConnection; | ||
import io.spring.start.site.container.ServiceConnectionsCustomizer; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
|
||
/** | ||
* Configuration for generation of projects that depend on Milvus. | ||
* | ||
* @author Eddú Meléndez | ||
*/ | ||
@ProjectGenerationConfiguration | ||
@ConditionalOnRequestedDependency("spring-ai-vectordb-milvus") | ||
class SpringAiMilvusProjectGenerationConfiguration { | ||
|
||
private static final String TESTCONTAINERS_CLASS_NAME = "org.testcontainers.milvus.MilvusContainer"; | ||
|
||
@Bean | ||
@ConditionalOnRequestedDependency("testcontainers") | ||
ServiceConnectionsCustomizer milvusServiceConnectionsCustomizer(InitializrMetadata metadata, | ||
ProjectDescription description, DockerServiceResolver serviceResolver) { | ||
return (serviceConnections) -> { | ||
if (SpringAiVersion.version1OrLater(metadata, description.getPlatformVersion())) { | ||
serviceResolver.doWith("milvus", (service) -> serviceConnections | ||
.addServiceConnection(ServiceConnection.ofContainer("milvus", service, TESTCONTAINERS_CLASS_NAME))); | ||
} | ||
}; | ||
} | ||
|
||
} |
64 changes: 64 additions & 0 deletions
64
...tart/site/extension/dependency/springai/SpringAiOllamaProjectGenerationConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright 2012-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.spring.start.site.extension.dependency.springai; | ||
|
||
import io.spring.initializr.generator.condition.ConditionalOnRequestedDependency; | ||
import io.spring.initializr.generator.project.ProjectDescription; | ||
import io.spring.initializr.generator.project.ProjectGenerationConfiguration; | ||
import io.spring.initializr.metadata.InitializrMetadata; | ||
import io.spring.start.site.container.ComposeFileCustomizer; | ||
import io.spring.start.site.container.DockerServiceResolver; | ||
import io.spring.start.site.container.ServiceConnections.ServiceConnection; | ||
import io.spring.start.site.container.ServiceConnectionsCustomizer; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
|
||
/** | ||
* Configuration for generation of projects that depend on Ollama. | ||
* | ||
* @author Eddú Meléndez | ||
*/ | ||
@ProjectGenerationConfiguration | ||
@ConditionalOnRequestedDependency("spring-ai-ollama") | ||
class SpringAiOllamaProjectGenerationConfiguration { | ||
|
||
private static final String TESTCONTAINERS_CLASS_NAME = "org.testcontainers.ollama.OllamaContainer"; | ||
|
||
@Bean | ||
@ConditionalOnRequestedDependency("testcontainers") | ||
ServiceConnectionsCustomizer ollamaServiceConnectionsCustomizer(InitializrMetadata metadata, | ||
ProjectDescription description, DockerServiceResolver serviceResolver) { | ||
return (serviceConnections) -> { | ||
if (SpringAiVersion.version1OrLater(metadata, description.getPlatformVersion())) { | ||
serviceResolver.doWith("ollama", (service) -> serviceConnections | ||
.addServiceConnection(ServiceConnection.ofContainer("ollama", service, TESTCONTAINERS_CLASS_NAME))); | ||
} | ||
}; | ||
} | ||
|
||
@Bean | ||
@ConditionalOnRequestedDependency("docker-compose") | ||
ComposeFileCustomizer ollamaComposeFileCustomizer(InitializrMetadata metadata, ProjectDescription description, | ||
DockerServiceResolver serviceResolver) { | ||
return (composeFile) -> { | ||
if (SpringAiVersion.version1OrLater(metadata, description.getPlatformVersion())) { | ||
serviceResolver.doWith("ollama", (service) -> composeFile.services().add("ollama", service)); | ||
} | ||
}; | ||
} | ||
|
||
} |
64 changes: 64 additions & 0 deletions
64
...tart/site/extension/dependency/springai/SpringAiQdrantProjectGenerationConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright 2012-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.spring.start.site.extension.dependency.springai; | ||
|
||
import io.spring.initializr.generator.condition.ConditionalOnRequestedDependency; | ||
import io.spring.initializr.generator.project.ProjectDescription; | ||
import io.spring.initializr.generator.project.ProjectGenerationConfiguration; | ||
import io.spring.initializr.metadata.InitializrMetadata; | ||
import io.spring.start.site.container.ComposeFileCustomizer; | ||
import io.spring.start.site.container.DockerServiceResolver; | ||
import io.spring.start.site.container.ServiceConnections.ServiceConnection; | ||
import io.spring.start.site.container.ServiceConnectionsCustomizer; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
|
||
/** | ||
* Configuration for generation of projects that depend on Qdrant. | ||
* | ||
* @author Eddú Meléndez | ||
*/ | ||
@ProjectGenerationConfiguration | ||
@ConditionalOnRequestedDependency("spring-ai-vectordb-qdrant") | ||
class SpringAiQdrantProjectGenerationConfiguration { | ||
|
||
private static final String TESTCONTAINERS_CLASS_NAME = "org.testcontainers.qdrant.QdrantContainer"; | ||
|
||
@Bean | ||
@ConditionalOnRequestedDependency("testcontainers") | ||
ServiceConnectionsCustomizer qdrantServiceConnectionsCustomizer(InitializrMetadata metadata, | ||
ProjectDescription description, DockerServiceResolver serviceResolver) { | ||
return (serviceConnections) -> { | ||
if (SpringAiVersion.version1OrLater(metadata, description.getPlatformVersion())) { | ||
serviceResolver.doWith("qdrant", (service) -> serviceConnections | ||
.addServiceConnection(ServiceConnection.ofContainer("qdrant", service, TESTCONTAINERS_CLASS_NAME))); | ||
} | ||
}; | ||
} | ||
|
||
@Bean | ||
@ConditionalOnRequestedDependency("docker-compose") | ||
ComposeFileCustomizer qdrantComposeFileCustomizer(InitializrMetadata metadata, ProjectDescription description, | ||
DockerServiceResolver serviceResolver) { | ||
return (composeFile) -> { | ||
if (SpringAiVersion.version1OrLater(metadata, description.getPlatformVersion())) { | ||
serviceResolver.doWith("qdrant", (service) -> composeFile.services().add("qdrant", service)); | ||
} | ||
}; | ||
} | ||
|
||
} |
Oops, something went wrong.