|
| 1 | +/* |
| 2 | + * Copyright 2012-2024 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package io.spring.start.site.extension.dependency.redis; |
| 18 | + |
| 19 | +import io.spring.initializr.generator.condition.ConditionalOnRequestedDependency; |
| 20 | +import io.spring.start.site.container.ComposeFileCustomizer; |
| 21 | +import io.spring.start.site.container.DockerServiceResolver; |
| 22 | +import io.spring.start.site.container.ServiceConnections.ServiceConnection; |
| 23 | +import io.spring.start.site.container.ServiceConnectionsCustomizer; |
| 24 | + |
| 25 | +import org.springframework.context.annotation.Bean; |
| 26 | +import org.springframework.context.annotation.Configuration; |
| 27 | + |
| 28 | +/** |
| 29 | + * Configuration for generation of projects that depend on Redis Stack. |
| 30 | + * |
| 31 | + * @author Eddú Meléndez |
| 32 | + */ |
| 33 | +@Configuration(proxyBeanMethods = false) |
| 34 | +@ConditionalOnRequestedDependency("spring-ai-vectordb-redis") |
| 35 | +class RedisStackProjectGenerationConfiguration { |
| 36 | + |
| 37 | + @Bean |
| 38 | + @ConditionalOnRequestedDependency("testcontainers") |
| 39 | + ServiceConnectionsCustomizer redisStackServiceConnectionsCustomizer(DockerServiceResolver serviceResolver) { |
| 40 | + return (serviceConnections) -> serviceResolver.doWith("redis-stack", (service) -> serviceConnections |
| 41 | + .addServiceConnection(ServiceConnection.ofGenericContainer("redis-stack", service, "redis"))); |
| 42 | + } |
| 43 | + |
| 44 | + @Bean |
| 45 | + @ConditionalOnRequestedDependency("docker-compose") |
| 46 | + ComposeFileCustomizer redisStackComposeFileCustomizer(DockerServiceResolver serviceResolver) { |
| 47 | + return (composeFile) -> serviceResolver.doWith("redis-stack", (service) -> composeFile.services() |
| 48 | + .add("redis", |
| 49 | + service.andThen(builder -> builder.label("org.springframework.boot.service-connection", "redis")))); |
| 50 | + } |
| 51 | + |
| 52 | +} |
0 commit comments