Start splitting spring-boot-docker-compose

This commit is contained in:
Phillip Webb
2025-05-19 10:05:25 -07:00
parent e7cd3bed65
commit fac158fe4e
184 changed files with 113 additions and 79 deletions

View File

@@ -1,79 +0,0 @@
/*
* Copyright 2012-2025 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 org.springframework.boot.docker.compose.service.connection.activemq;
import org.springframework.boot.activemq.autoconfigure.ActiveMQConnectionDetails;
import org.springframework.boot.docker.compose.core.RunningService;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource;
/**
* {@link DockerComposeConnectionDetailsFactory} to create
* {@link ActiveMQConnectionDetails} for an {@code activemq} service.
*
* @author Stephane Nicoll
* @author Eddú Meléndez
*/
class ActiveMQClassicDockerComposeConnectionDetailsFactory
extends DockerComposeConnectionDetailsFactory<ActiveMQConnectionDetails> {
private static final int ACTIVEMQ_PORT = 61616;
protected ActiveMQClassicDockerComposeConnectionDetailsFactory() {
super("apache/activemq-classic");
}
@Override
protected ActiveMQConnectionDetails getDockerComposeConnectionDetails(DockerComposeConnectionSource source) {
return new ActiveMQDockerComposeConnectionDetails(source.getRunningService());
}
/**
* {@link ActiveMQConnectionDetails} backed by an {@code activemq}
* {@link RunningService}.
*/
static class ActiveMQDockerComposeConnectionDetails extends DockerComposeConnectionDetails
implements ActiveMQConnectionDetails {
private final ActiveMQClassicEnvironment environment;
private final String brokerUrl;
protected ActiveMQDockerComposeConnectionDetails(RunningService service) {
super(service);
this.environment = new ActiveMQClassicEnvironment(service.env());
this.brokerUrl = "tcp://" + service.host() + ":" + service.ports().get(ACTIVEMQ_PORT);
}
@Override
public String getBrokerUrl() {
return this.brokerUrl;
}
@Override
public String getUser() {
return this.environment.getUser();
}
@Override
public String getPassword() {
return this.environment.getPassword();
}
}
}

View File

@@ -1,46 +0,0 @@
/*
* 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 org.springframework.boot.docker.compose.service.connection.activemq;
import java.util.Map;
/**
* ActiveMQ environment details.
*
* @author Stephane Nicoll
* @author Eddú Meléndez
*/
class ActiveMQClassicEnvironment {
private final String user;
private final String password;
ActiveMQClassicEnvironment(Map<String, String> env) {
this.user = env.get("ACTIVEMQ_CONNECTION_USER");
this.password = env.get("ACTIVEMQ_CONNECTION_PASSWORD");
}
String getUser() {
return this.user;
}
String getPassword() {
return this.password;
}
}

View File

@@ -1,78 +0,0 @@
/*
* Copyright 2012-2025 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 org.springframework.boot.docker.compose.service.connection.activemq;
import org.springframework.boot.activemq.autoconfigure.ActiveMQConnectionDetails;
import org.springframework.boot.docker.compose.core.RunningService;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource;
/**
* {@link DockerComposeConnectionDetailsFactory} to create
* {@link ActiveMQConnectionDetails} for an {@code activemq} service.
*
* @author Stephane Nicoll
*/
class ActiveMQDockerComposeConnectionDetailsFactory
extends DockerComposeConnectionDetailsFactory<ActiveMQConnectionDetails> {
private static final int ACTIVEMQ_PORT = 61616;
protected ActiveMQDockerComposeConnectionDetailsFactory() {
super("symptoma/activemq");
}
@Override
protected ActiveMQConnectionDetails getDockerComposeConnectionDetails(DockerComposeConnectionSource source) {
return new ActiveMQDockerComposeConnectionDetails(source.getRunningService());
}
/**
* {@link ActiveMQConnectionDetails} backed by an {@code activemq}
* {@link RunningService}.
*/
static class ActiveMQDockerComposeConnectionDetails extends DockerComposeConnectionDetails
implements ActiveMQConnectionDetails {
private final ActiveMQEnvironment environment;
private final String brokerUrl;
protected ActiveMQDockerComposeConnectionDetails(RunningService service) {
super(service);
this.environment = new ActiveMQEnvironment(service.env());
this.brokerUrl = "tcp://" + service.host() + ":" + service.ports().get(ACTIVEMQ_PORT);
}
@Override
public String getBrokerUrl() {
return this.brokerUrl;
}
@Override
public String getUser() {
return this.environment.getUser();
}
@Override
public String getPassword() {
return this.environment.getPassword();
}
}
}

View File

@@ -1,45 +0,0 @@
/*
* Copyright 2012-2023 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 org.springframework.boot.docker.compose.service.connection.activemq;
import java.util.Map;
/**
* ActiveMQ environment details.
*
* @author Stephane Nicoll
*/
class ActiveMQEnvironment {
private final String user;
private final String password;
ActiveMQEnvironment(Map<String, String> env) {
this.user = env.get("ACTIVEMQ_USERNAME");
this.password = env.get("ACTIVEMQ_PASSWORD");
}
String getUser() {
return this.user;
}
String getPassword() {
return this.password;
}
}

View File

@@ -1,85 +0,0 @@
/*
* Copyright 2012-2025 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 org.springframework.boot.docker.compose.service.connection.activemq;
import org.springframework.boot.artemis.autoconfigure.ArtemisConnectionDetails;
import org.springframework.boot.artemis.autoconfigure.ArtemisMode;
import org.springframework.boot.docker.compose.core.RunningService;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource;
/**
* {@link DockerComposeConnectionDetailsFactory} to create
* {@link ArtemisConnectionDetails} for an {@code artemis} service.
*
* @author Eddú Meléndez
* @author Moritz Halbritter
*/
class ArtemisDockerComposeConnectionDetailsFactory
extends DockerComposeConnectionDetailsFactory<ArtemisConnectionDetails> {
private static final int ACTIVEMQ_PORT = 61616;
protected ArtemisDockerComposeConnectionDetailsFactory() {
super("apache/activemq-artemis");
}
@Override
protected ArtemisConnectionDetails getDockerComposeConnectionDetails(DockerComposeConnectionSource source) {
return new ArtemisDockerComposeConnectionDetails(source.getRunningService());
}
/**
* {@link ArtemisConnectionDetails} backed by a {@code artemis}
* {@link RunningService}.
*/
static class ArtemisDockerComposeConnectionDetails extends DockerComposeConnectionDetails
implements ArtemisConnectionDetails {
private final ArtemisEnvironment environment;
private final String brokerUrl;
protected ArtemisDockerComposeConnectionDetails(RunningService service) {
super(service);
this.environment = new ArtemisEnvironment(service.env());
this.brokerUrl = "tcp://" + service.host() + ":" + service.ports().get(ACTIVEMQ_PORT);
}
@Override
public ArtemisMode getMode() {
return ArtemisMode.NATIVE;
}
@Override
public String getBrokerUrl() {
return this.brokerUrl;
}
@Override
public String getUser() {
return this.environment.getUser();
}
@Override
public String getPassword() {
return this.environment.getPassword();
}
}
}

View File

@@ -1,46 +0,0 @@
/*
* 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 org.springframework.boot.docker.compose.service.connection.activemq;
import java.util.Map;
/**
* Artemis environment details.
*
* @author Eddú Meléndez
* @author Moritz Halbritter
*/
class ArtemisEnvironment {
private final String user;
private final String password;
ArtemisEnvironment(Map<String, String> env) {
this.user = env.get("ARTEMIS_USER");
this.password = env.get("ARTEMIS_PASSWORD");
}
String getUser() {
return this.user;
}
String getPassword() {
return this.password;
}
}

View File

@@ -1,20 +0,0 @@
/*
* 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.
*/
/**
* Auto-configuration for Docker Compose ActiveMQ service connections.
*/
package org.springframework.boot.docker.compose.service.connection.activemq;

View File

@@ -1,78 +0,0 @@
/*
* Copyright 2012-2025 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 org.springframework.boot.docker.compose.service.connection.cassandra;
import java.util.List;
import org.springframework.boot.cassandra.autoconfigure.CassandraConnectionDetails;
import org.springframework.boot.docker.compose.core.RunningService;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource;
/**
* {@link DockerComposeConnectionDetailsFactory} to create
* {@link CassandraConnectionDetails} for a {@code Cassandra} service.
*
* @author Scott Frederick
*/
class CassandraDockerComposeConnectionDetailsFactory
extends DockerComposeConnectionDetailsFactory<CassandraConnectionDetails> {
private static final String[] CASSANDRA_CONTAINER_NAMES = { "cassandra", "bitnami/cassandra" };
private static final int CASSANDRA_PORT = 9042;
CassandraDockerComposeConnectionDetailsFactory() {
super(CASSANDRA_CONTAINER_NAMES);
}
@Override
protected CassandraConnectionDetails getDockerComposeConnectionDetails(DockerComposeConnectionSource source) {
return new CassandraDockerComposeConnectionDetails(source.getRunningService());
}
/**
* {@link CassandraConnectionDetails} backed by a {@code Cassandra}
* {@link RunningService}.
*/
static class CassandraDockerComposeConnectionDetails extends DockerComposeConnectionDetails
implements CassandraConnectionDetails {
private final List<Node> contactPoints;
private final String datacenter;
CassandraDockerComposeConnectionDetails(RunningService service) {
super(service);
CassandraEnvironment cassandraEnvironment = new CassandraEnvironment(service.env());
this.contactPoints = List.of(new Node(service.host(), service.ports().get(CASSANDRA_PORT)));
this.datacenter = cassandraEnvironment.getDatacenter();
}
@Override
public List<Node> getContactPoints() {
return this.contactPoints;
}
@Override
public String getLocalDatacenter() {
return this.datacenter;
}
}
}

View File

@@ -1,38 +0,0 @@
/*
* 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 org.springframework.boot.docker.compose.service.connection.cassandra;
import java.util.Map;
/**
* Cassandra environment details.
*
* @author Scott Frederick
*/
class CassandraEnvironment {
private final String datacenter;
CassandraEnvironment(Map<String, String> env) {
this.datacenter = env.getOrDefault("CASSANDRA_DC", env.getOrDefault("CASSANDRA_DATACENTER", "datacenter1"));
}
String getDatacenter() {
return this.datacenter;
}
}

View File

@@ -1,20 +0,0 @@
/*
* 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.
*/
/**
* Auto-configuration for Docker Compose Cassandra service connections.
*/
package org.springframework.boot.docker.compose.service.connection.cassandra;

View File

@@ -1,62 +0,0 @@
/*
* Copyright 2012-2025 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 org.springframework.boot.docker.compose.service.connection.clickhouse;
import java.util.Map;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
* ClickHouse environment details.
*
* @author Stephane Nicoll
*/
class ClickHouseEnvironment {
private final String username;
private final String password;
private final String database;
ClickHouseEnvironment(Map<String, String> env) {
this.username = env.getOrDefault("CLICKHOUSE_USER", "default");
this.password = extractPassword(env);
this.database = env.getOrDefault("CLICKHOUSE_DB", "default");
}
private String extractPassword(Map<String, String> env) {
boolean allowEmpty = env.containsKey("ALLOW_EMPTY_PASSWORD");
String password = env.get("CLICKHOUSE_PASSWORD");
Assert.state(StringUtils.hasLength(password) || allowEmpty, "No ClickHouse password found");
return (password != null) ? password : "";
}
String getUsername() {
return this.username;
}
String getPassword() {
return this.password;
}
String getDatabase() {
return this.database;
}
}

View File

@@ -1,81 +0,0 @@
/*
* 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 org.springframework.boot.docker.compose.service.connection.clickhouse;
import org.springframework.boot.docker.compose.core.RunningService;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource;
import org.springframework.boot.docker.compose.service.connection.jdbc.JdbcUrlBuilder;
import org.springframework.boot.jdbc.autoconfigure.JdbcConnectionDetails;
/**
* {@link DockerComposeConnectionDetailsFactory} to create {@link JdbcConnectionDetails}
* for a {@code clickhouse} service.
*
* @author Stephane Nicoll
*/
class ClickHouseJdbcDockerComposeConnectionDetailsFactory
extends DockerComposeConnectionDetailsFactory<JdbcConnectionDetails> {
private static final String[] CLICKHOUSE_CONTAINER_NAMES = { "clickhouse/clickhouse-server", "bitnami/clickhouse" };
protected ClickHouseJdbcDockerComposeConnectionDetailsFactory() {
super(CLICKHOUSE_CONTAINER_NAMES);
}
@Override
protected JdbcConnectionDetails getDockerComposeConnectionDetails(DockerComposeConnectionSource source) {
return new ClickhouseJdbcDockerComposeConnectionDetails(source.getRunningService());
}
/**
* {@link JdbcConnectionDetails} backed by a {@code clickhouse}
* {@link RunningService}.
*/
static class ClickhouseJdbcDockerComposeConnectionDetails extends DockerComposeConnectionDetails
implements JdbcConnectionDetails {
private static final JdbcUrlBuilder jdbcUrlBuilder = new JdbcUrlBuilder("clickhouse", 8123);
private final ClickHouseEnvironment environment;
private final String jdbcUrl;
ClickhouseJdbcDockerComposeConnectionDetails(RunningService service) {
super(service);
this.environment = new ClickHouseEnvironment(service.env());
this.jdbcUrl = jdbcUrlBuilder.build(service, this.environment.getDatabase());
}
@Override
public String getUsername() {
return this.environment.getUsername();
}
@Override
public String getPassword() {
return this.environment.getPassword();
}
@Override
public String getJdbcUrl() {
return this.jdbcUrl;
}
}
}

View File

@@ -1,73 +0,0 @@
/*
* Copyright 2012-2025 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 org.springframework.boot.docker.compose.service.connection.clickhouse;
import io.r2dbc.spi.ConnectionFactoryOptions;
import org.springframework.boot.docker.compose.core.RunningService;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource;
import org.springframework.boot.docker.compose.service.connection.r2dbc.ConnectionFactoryOptionsBuilder;
import org.springframework.boot.r2dbc.autoconfigure.R2dbcConnectionDetails;
/**
* {@link DockerComposeConnectionDetailsFactory} to create {@link R2dbcConnectionDetails}
* for a {@code clickhouse} service.
*
* @author Stephane Nicoll
*/
class ClickHouseR2dbcDockerComposeConnectionDetailsFactory
extends DockerComposeConnectionDetailsFactory<R2dbcConnectionDetails> {
private static final String[] CLICKHOUSE_CONTAINER_NAMES = { "clickhouse/clickhouse-server", "bitnami/clickhouse" };
ClickHouseR2dbcDockerComposeConnectionDetailsFactory() {
super(CLICKHOUSE_CONTAINER_NAMES, "io.r2dbc.spi.ConnectionFactoryOptions");
}
@Override
protected R2dbcConnectionDetails getDockerComposeConnectionDetails(DockerComposeConnectionSource source) {
return new ClickhouseDbR2dbcDockerComposeConnectionDetails(source.getRunningService());
}
/**
* {@link R2dbcConnectionDetails} backed by a {@code clickhouse}
* {@link RunningService}.
*/
static class ClickhouseDbR2dbcDockerComposeConnectionDetails extends DockerComposeConnectionDetails
implements R2dbcConnectionDetails {
private static final ConnectionFactoryOptionsBuilder connectionFactoryOptionsBuilder = new ConnectionFactoryOptionsBuilder(
"clickhouse", 8123);
private final ConnectionFactoryOptions connectionFactoryOptions;
ClickhouseDbR2dbcDockerComposeConnectionDetails(RunningService service) {
super(service);
ClickHouseEnvironment environment = new ClickHouseEnvironment(service.env());
this.connectionFactoryOptions = connectionFactoryOptionsBuilder.build(service, environment.getDatabase(),
environment.getUsername(), environment.getPassword());
}
@Override
public ConnectionFactoryOptions getConnectionFactoryOptions() {
return this.connectionFactoryOptions;
}
}
}

View File

@@ -1,20 +0,0 @@
/*
* 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.
*/
/**
* Auto-configuration for Docker Compose ClickHouse service connections.
*/
package org.springframework.boot.docker.compose.service.connection.clickhouse;

View File

@@ -1,87 +0,0 @@
/*
* 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 org.springframework.boot.docker.compose.service.connection.elasticsearch;
import java.util.List;
import org.springframework.boot.docker.compose.core.RunningService;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource;
import org.springframework.boot.elasticsearch.autoconfigure.ElasticsearchConnectionDetails;
import org.springframework.boot.elasticsearch.autoconfigure.ElasticsearchConnectionDetails.Node.Protocol;
/**
* {@link DockerComposeConnectionDetailsFactory} to create
* {@link ElasticsearchConnectionDetails} for an {@code elasticsearch} service.
*
* @author Moritz Halbritter
* @author Andy Wilkinson
* @author Phillip Webb
* @author Scott Frederick
*/
class ElasticsearchDockerComposeConnectionDetailsFactory
extends DockerComposeConnectionDetailsFactory<ElasticsearchConnectionDetails> {
private static final String[] ELASTICSEARCH_CONTAINER_NAMES = { "elasticsearch", "bitnami/elasticsearch" };
private static final int ELASTICSEARCH_PORT = 9200;
protected ElasticsearchDockerComposeConnectionDetailsFactory() {
super(ELASTICSEARCH_CONTAINER_NAMES);
}
@Override
protected ElasticsearchConnectionDetails getDockerComposeConnectionDetails(DockerComposeConnectionSource source) {
return new ElasticsearchDockerComposeConnectionDetails(source.getRunningService());
}
/**
* {@link ElasticsearchConnectionDetails} backed by an {@code elasticsearch}
* {@link RunningService}.
*/
static class ElasticsearchDockerComposeConnectionDetails extends DockerComposeConnectionDetails
implements ElasticsearchConnectionDetails {
private final ElasticsearchEnvironment environment;
private final List<Node> nodes;
ElasticsearchDockerComposeConnectionDetails(RunningService service) {
super(service);
this.environment = new ElasticsearchEnvironment(service.env());
this.nodes = List.of(new Node(service.host(), service.ports().get(ELASTICSEARCH_PORT), Protocol.HTTP,
getUsername(), getPassword()));
}
@Override
public String getUsername() {
return "elastic";
}
@Override
public String getPassword() {
return this.environment.getPassword();
}
@Override
public List<Node> getNodes() {
return this.nodes;
}
}
}

View File

@@ -1,43 +0,0 @@
/*
* Copyright 2012-2023 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 org.springframework.boot.docker.compose.service.connection.elasticsearch;
import java.util.Map;
import org.springframework.util.Assert;
/**
* Elasticsearch environment details.
*
* @author Moritz Halbritter
* @author Andy Wilkinson
* @author Phillip Webb
*/
class ElasticsearchEnvironment {
private final String password;
ElasticsearchEnvironment(Map<String, String> env) {
Assert.state(!env.containsKey("ELASTIC_PASSWORD_FILE"), "ELASTIC_PASSWORD_FILE is not supported");
this.password = env.get("ELASTIC_PASSWORD");
}
String getPassword() {
return this.password;
}
}

View File

@@ -1,20 +0,0 @@
/*
* 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.
*/
/**
* Auto-configuration for Docker Compose Elasticsearch service connections.
*/
package org.springframework.boot.docker.compose.service.connection.elasticsearch;

View File

@@ -1,59 +0,0 @@
/*
* Copyright 2012-2025 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 org.springframework.boot.docker.compose.service.connection.flyway;
import org.springframework.boot.autoconfigure.service.connection.ConnectionDetailsFactory;
import org.springframework.boot.flyway.autoconfigure.FlywayConnectionDetails;
import org.springframework.boot.jdbc.autoconfigure.JdbcConnectionDetails;
/**
* {@link ConnectionDetailsFactory} that produces {@link FlywayConnectionDetails} by
* adapting {@link JdbcConnectionDetails}.
*
* @author Andy Wilkinson
*/
class JdbcAdaptingFlywayConnectionDetailsFactory
implements ConnectionDetailsFactory<JdbcConnectionDetails, FlywayConnectionDetails> {
@Override
public FlywayConnectionDetails getConnectionDetails(JdbcConnectionDetails input) {
return new FlywayConnectionDetails() {
@Override
public String getUsername() {
return input.getUsername();
}
@Override
public String getPassword() {
return input.getPassword();
}
@Override
public String getJdbcUrl() {
return input.getJdbcUrl();
}
@Override
public String getDriverClassName() {
return input.getDriverClassName();
}
};
}
}

View File

@@ -1,20 +0,0 @@
/*
* 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.
*/
/**
* Auto-configuration for Docker Compose Flyway service connections.
*/
package org.springframework.boot.docker.compose.service.connection.flyway;

View File

@@ -1,78 +0,0 @@
/*
* Copyright 2012-2025 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 org.springframework.boot.docker.compose.service.connection.hazelcast;
import com.hazelcast.client.config.ClientConfig;
import org.springframework.boot.docker.compose.core.RunningService;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource;
import org.springframework.boot.hazelcast.autoconfigure.HazelcastConnectionDetails;
/**
* {@link DockerComposeConnectionDetailsFactory} to create
* {@link HazelcastConnectionDetails} for a {@code hazelcast} service.
*
* @author Dmytro Nosan
*/
class HazelcastDockerComposeConnectionDetailsFactory
extends DockerComposeConnectionDetailsFactory<HazelcastConnectionDetails> {
private static final int DEFAULT_PORT = 5701;
protected HazelcastDockerComposeConnectionDetailsFactory() {
super("hazelcast/hazelcast", "com.hazelcast.client.config.ClientConfig");
}
@Override
protected HazelcastConnectionDetails getDockerComposeConnectionDetails(DockerComposeConnectionSource source) {
return new HazelcastDockerComposeConnectionDetails(source.getRunningService());
}
/**
* {@link HazelcastConnectionDetails} backed by a {@code hazelcast}
* {@link RunningService}.
*/
static class HazelcastDockerComposeConnectionDetails extends DockerComposeConnectionDetails
implements HazelcastConnectionDetails {
private final String host;
private final int port;
private final HazelcastEnvironment environment;
HazelcastDockerComposeConnectionDetails(RunningService service) {
super(service);
this.host = service.host();
this.port = service.ports().get(DEFAULT_PORT);
this.environment = new HazelcastEnvironment(service.env());
}
@Override
public ClientConfig getClientConfig() {
ClientConfig config = new ClientConfig();
if (this.environment.getClusterName() != null) {
config.setClusterName(this.environment.getClusterName());
}
config.getNetworkConfig().addAddress(this.host + ":" + this.port);
return config;
}
}
}

View File

@@ -1,38 +0,0 @@
/*
* 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 org.springframework.boot.docker.compose.service.connection.hazelcast;
import java.util.Map;
/**
* Hazelcast environment details.
*
* @author Dmytro Nosan
*/
class HazelcastEnvironment {
private final String clusterName;
HazelcastEnvironment(Map<String, String> env) {
this.clusterName = env.get("HZ_CLUSTERNAME");
}
String getClusterName() {
return this.clusterName;
}
}

View File

@@ -1,20 +0,0 @@
/*
* 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.
*/
/**
* Auto-configuration for Docker Compose Hazelcast service connections.
*/
package org.springframework.boot.docker.compose.service.connection.hazelcast;

View File

@@ -1,100 +0,0 @@
/*
* Copyright 2012-2025 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 org.springframework.boot.docker.compose.service.connection.jdbc;
import org.springframework.boot.docker.compose.core.RunningService;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
* Utility used to build a JDBC URL for a {@link RunningService}.
*
* @author Moritz Halbritter
* @author Andy Wilkinson
* @author Phillip Webb
* @since 3.1.0
*/
public class JdbcUrlBuilder {
private static final String PARAMETERS_LABEL = "org.springframework.boot.jdbc.parameters";
private final String driverProtocol;
private final int containerPort;
/**
* Create a new {@link JdbcUrlBuilder} instance.
* @param driverProtocol the driver protocol
* @param containerPort the source container port
*/
public JdbcUrlBuilder(String driverProtocol, int containerPort) {
Assert.notNull(driverProtocol, "'driverProtocol' must not be null");
this.driverProtocol = driverProtocol;
this.containerPort = containerPort;
}
/**
* Build a JDBC URL for the given {@link RunningService}.
* @param service the running service
* @return a new JDBC URL
*/
public String build(RunningService service) {
return build(service, null);
}
/**
* Build a JDBC URL for the given {@link RunningService} and database.
* @param service the running service
* @param database the database to connect to
* @return a new JDBC URL
*/
public String build(RunningService service, String database) {
return urlFor(service, database);
}
private String urlFor(RunningService service, String database) {
Assert.notNull(service, "'service' must not be null");
StringBuilder url = new StringBuilder("jdbc:%s://%s:%d".formatted(this.driverProtocol, service.host(),
service.ports().get(this.containerPort)));
if (StringUtils.hasLength(database)) {
url.append("/");
url.append(database);
}
String parameters = getParameters(service);
if (StringUtils.hasLength(parameters)) {
appendParameters(url, parameters);
}
return url.toString();
}
/**
* Appends to the given {@code url} the given {@code parameters}.
* <p>
* The default implementation appends a {@code ?} followed by the {@code parameters}.
* @param url the url
* @param parameters the parameters
* @since 3.2.7
*/
protected void appendParameters(StringBuilder url, String parameters) {
url.append("?").append(parameters);
}
private String getParameters(RunningService service) {
return service.labels().get(PARAMETERS_LABEL);
}
}

View File

@@ -1,21 +0,0 @@
/*
* Copyright 2012-2023 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.
*/
/**
* Utilities to help when creating
* {@link org.springframework.boot.jdbc.autoconfigure.JdbcConnectionDetails}.
*/
package org.springframework.boot.docker.compose.service.connection.jdbc;

View File

@@ -1,92 +0,0 @@
/*
* Copyright 2012-2025 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 org.springframework.boot.docker.compose.service.connection.ldap;
import java.util.Map;
import org.springframework.boot.docker.compose.core.RunningService;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource;
import org.springframework.boot.ldap.autoconfigure.LdapConnectionDetails;
/**
* {@link DockerComposeConnectionDetailsFactory} to create {@link LdapConnectionDetails}
* for an {@code ldap} service.
*
* @author Eddú Meléndez
*/
class LLdapDockerComposeConnectionDetailsFactory extends DockerComposeConnectionDetailsFactory<LdapConnectionDetails> {
LLdapDockerComposeConnectionDetailsFactory() {
super("lldap/lldap");
}
@Override
protected LdapConnectionDetails getDockerComposeConnectionDetails(DockerComposeConnectionSource source) {
return new LLdapDockerComposeConnectionDetails(source.getRunningService());
}
/**
* {@link LdapConnectionDetails} backed by an {@code lldap} {@link RunningService}.
*/
static class LLdapDockerComposeConnectionDetails extends DockerComposeConnectionDetails
implements LdapConnectionDetails {
private final String[] urls;
private final String base;
private final String username;
private final String password;
LLdapDockerComposeConnectionDetails(RunningService service) {
super(service);
Map<String, String> env = service.env();
boolean usesTls = Boolean.parseBoolean(env.getOrDefault("LLDAP_LDAPS_OPTIONS__ENABLED", "false"));
String ldapPort = usesTls ? env.getOrDefault("LLDAP_LDAPS_OPTIONS__PORT", "6360")
: env.getOrDefault("LLDAP_LDAP_PORT", "3890");
this.urls = new String[] { "%s://%s:%d".formatted(usesTls ? "ldaps" : "ldap", service.host(),
service.ports().get(Integer.parseInt(ldapPort))) };
this.base = env.getOrDefault("LLDAP_LDAP_BASE_DN", "dc=example,dc=com");
this.password = env.getOrDefault("LLDAP_LDAP_USER_PASS", "password");
this.username = "cn=admin,ou=people,%s".formatted(this.base);
}
@Override
public String[] getUrls() {
return this.urls;
}
@Override
public String getBase() {
return this.base;
}
@Override
public String getUsername() {
return this.username;
}
@Override
public String getPassword() {
return this.password;
}
}
}

View File

@@ -1,101 +0,0 @@
/*
* Copyright 2012-2025 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 org.springframework.boot.docker.compose.service.connection.ldap;
import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;
import org.springframework.boot.docker.compose.core.RunningService;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource;
import org.springframework.boot.ldap.autoconfigure.LdapConnectionDetails;
/**
* {@link DockerComposeConnectionDetailsFactory} to create {@link LdapConnectionDetails}
* for an {@code ldap} service.
*
* @author Philipp Kessler
*/
class OpenLdapDockerComposeConnectionDetailsFactory
extends DockerComposeConnectionDetailsFactory<LdapConnectionDetails> {
protected OpenLdapDockerComposeConnectionDetailsFactory() {
super("osixia/openldap");
}
@Override
protected LdapConnectionDetails getDockerComposeConnectionDetails(DockerComposeConnectionSource source) {
return new OpenLdapDockerComposeConnectionDetails(source.getRunningService());
}
/**
* {@link LdapConnectionDetails} backed by an {@code openldap} {@link RunningService}.
*/
static class OpenLdapDockerComposeConnectionDetails extends DockerComposeConnectionDetails
implements LdapConnectionDetails {
private final String[] urls;
private final String base;
private final String username;
private final String password;
OpenLdapDockerComposeConnectionDetails(RunningService service) {
super(service);
Map<String, String> env = service.env();
boolean usesTls = Boolean.parseBoolean(env.getOrDefault("LDAP_TLS", "true"));
String ldapPort = usesTls ? env.getOrDefault("LDAPS_PORT", "636") : env.getOrDefault("LDAP_PORT", "389");
this.urls = new String[] { "%s://%s:%d".formatted(usesTls ? "ldaps" : "ldap", service.host(),
service.ports().get(Integer.parseInt(ldapPort))) };
if (env.containsKey("LDAP_BASE_DN")) {
this.base = env.get("LDAP_BASE_DN");
}
else {
this.base = Arrays.stream(env.getOrDefault("LDAP_DOMAIN", "example.org").split("\\."))
.map("dc=%s"::formatted)
.collect(Collectors.joining(","));
}
this.password = env.getOrDefault("LDAP_ADMIN_PASSWORD", "admin");
this.username = "cn=admin,%s".formatted(this.base);
}
@Override
public String[] getUrls() {
return this.urls;
}
@Override
public String getBase() {
return this.base;
}
@Override
public String getUsername() {
return this.username;
}
@Override
public String getPassword() {
return this.password;
}
}
}

View File

@@ -1,20 +0,0 @@
/*
* 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.
*/
/**
* Auto-configuration for Docker Compose LDAP service connections.
*/
package org.springframework.boot.docker.compose.service.connection.ldap;

View File

@@ -1,59 +0,0 @@
/*
* Copyright 2012-2025 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 org.springframework.boot.docker.compose.service.connection.liquibase;
import org.springframework.boot.autoconfigure.service.connection.ConnectionDetailsFactory;
import org.springframework.boot.jdbc.autoconfigure.JdbcConnectionDetails;
import org.springframework.boot.liquibase.autoconfigure.LiquibaseConnectionDetails;
/**
* {@link ConnectionDetailsFactory} that produces {@link LiquibaseConnectionDetails} by
* adapting {@link JdbcConnectionDetails}.
*
* @author Andy Wilkinson
*/
class JdbcAdaptingLiquibaseConnectionDetailsFactory
implements ConnectionDetailsFactory<JdbcConnectionDetails, LiquibaseConnectionDetails> {
@Override
public LiquibaseConnectionDetails getConnectionDetails(JdbcConnectionDetails input) {
return new LiquibaseConnectionDetails() {
@Override
public String getUsername() {
return input.getUsername();
}
@Override
public String getPassword() {
return input.getPassword();
}
@Override
public String getJdbcUrl() {
return input.getJdbcUrl();
}
@Override
public String getDriverClassName() {
return input.getDriverClassName();
}
};
}
}

View File

@@ -1,20 +0,0 @@
/*
* 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.
*/
/**
* Auto-configuration for Docker Compose Liquibase service connections.
*/
package org.springframework.boot.docker.compose.service.connection.liquibase;

View File

@@ -1,84 +0,0 @@
/*
* 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 org.springframework.boot.docker.compose.service.connection.mariadb;
import java.util.Map;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
* MariaDB environment details.
*
* @author Moritz Halbritter
* @author Andy Wilkinson
* @author Phillip Webb
* @author Scott Frederick
*/
class MariaDbEnvironment {
private final String username;
private final String password;
private final String database;
MariaDbEnvironment(Map<String, String> env) {
this.username = extractUsername(env);
this.password = extractPassword(env);
this.database = extractDatabase(env);
}
private String extractUsername(Map<String, String> env) {
String user = env.get("MARIADB_USER");
return (user != null) ? user : env.getOrDefault("MYSQL_USER", "root");
}
private String extractPassword(Map<String, String> env) {
Assert.state(!env.containsKey("MARIADB_RANDOM_ROOT_PASSWORD"), "MARIADB_RANDOM_ROOT_PASSWORD is not supported");
Assert.state(!env.containsKey("MYSQL_RANDOM_ROOT_PASSWORD"), "MYSQL_RANDOM_ROOT_PASSWORD is not supported");
Assert.state(!env.containsKey("MARIADB_ROOT_PASSWORD_HASH"), "MARIADB_ROOT_PASSWORD_HASH is not supported");
boolean allowEmpty = env.containsKey("MARIADB_ALLOW_EMPTY_PASSWORD")
|| env.containsKey("MYSQL_ALLOW_EMPTY_PASSWORD") || env.containsKey("ALLOW_EMPTY_PASSWORD");
String password = env.get("MARIADB_PASSWORD");
password = (password != null) ? password : env.get("MYSQL_PASSWORD");
password = (password != null) ? password : env.get("MARIADB_ROOT_PASSWORD");
password = (password != null) ? password : env.get("MYSQL_ROOT_PASSWORD");
Assert.state(StringUtils.hasLength(password) || allowEmpty, "No MariaDB password found");
return (password != null) ? password : "";
}
private String extractDatabase(Map<String, String> env) {
String database = env.get("MARIADB_DATABASE");
database = (database != null) ? database : env.get("MYSQL_DATABASE");
Assert.state(database != null, "No MARIADB_DATABASE defined");
return database;
}
String getUsername() {
return this.username;
}
String getPassword() {
return this.password;
}
String getDatabase() {
return this.database;
}
}

View File

@@ -1,83 +0,0 @@
/*
* 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 org.springframework.boot.docker.compose.service.connection.mariadb;
import org.springframework.boot.docker.compose.core.RunningService;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource;
import org.springframework.boot.docker.compose.service.connection.jdbc.JdbcUrlBuilder;
import org.springframework.boot.jdbc.autoconfigure.JdbcConnectionDetails;
/**
* {@link DockerComposeConnectionDetailsFactory} to create {@link JdbcConnectionDetails}
* for a {@code mariadb} service.
*
* @author Moritz Halbritter
* @author Andy Wilkinson
* @author Phillip Webb
* @author Scott Frederick
*/
class MariaDbJdbcDockerComposeConnectionDetailsFactory
extends DockerComposeConnectionDetailsFactory<JdbcConnectionDetails> {
private static final String[] MARIADB_CONTAINER_NAMES = { "mariadb", "bitnami/mariadb" };
protected MariaDbJdbcDockerComposeConnectionDetailsFactory() {
super(MARIADB_CONTAINER_NAMES);
}
@Override
protected JdbcConnectionDetails getDockerComposeConnectionDetails(DockerComposeConnectionSource source) {
return new MariaDbJdbcDockerComposeConnectionDetails(source.getRunningService());
}
/**
* {@link JdbcConnectionDetails} backed by a {@code mariadb} {@link RunningService}.
*/
static class MariaDbJdbcDockerComposeConnectionDetails extends DockerComposeConnectionDetails
implements JdbcConnectionDetails {
private static final JdbcUrlBuilder jdbcUrlBuilder = new JdbcUrlBuilder("mariadb", 3306);
private final MariaDbEnvironment environment;
private final String jdbcUrl;
MariaDbJdbcDockerComposeConnectionDetails(RunningService service) {
super(service);
this.environment = new MariaDbEnvironment(service.env());
this.jdbcUrl = jdbcUrlBuilder.build(service, this.environment.getDatabase());
}
@Override
public String getUsername() {
return this.environment.getUsername();
}
@Override
public String getPassword() {
return this.environment.getPassword();
}
@Override
public String getJdbcUrl() {
return this.jdbcUrl;
}
}
}

View File

@@ -1,75 +0,0 @@
/*
* Copyright 2012-2025 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 org.springframework.boot.docker.compose.service.connection.mariadb;
import io.r2dbc.spi.ConnectionFactoryOptions;
import org.springframework.boot.docker.compose.core.RunningService;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource;
import org.springframework.boot.docker.compose.service.connection.r2dbc.ConnectionFactoryOptionsBuilder;
import org.springframework.boot.r2dbc.autoconfigure.R2dbcConnectionDetails;
/**
* {@link DockerComposeConnectionDetailsFactory} to create {@link R2dbcConnectionDetails}
* for a {@code mariadb} service.
*
* @author Moritz Halbritter
* @author Andy Wilkinson
* @author Phillip Webb
* @author Scott Frederick
*/
class MariaDbR2dbcDockerComposeConnectionDetailsFactory
extends DockerComposeConnectionDetailsFactory<R2dbcConnectionDetails> {
private static final String[] MARIADB_CONTAINER_NAMES = { "mariadb", "bitnami/mariadb" };
MariaDbR2dbcDockerComposeConnectionDetailsFactory() {
super(MARIADB_CONTAINER_NAMES, "io.r2dbc.spi.ConnectionFactoryOptions");
}
@Override
protected R2dbcConnectionDetails getDockerComposeConnectionDetails(DockerComposeConnectionSource source) {
return new MariaDbR2dbcDockerComposeConnectionDetails(source.getRunningService());
}
/**
* {@link R2dbcConnectionDetails} backed by a {@code mariadb} {@link RunningService}.
*/
static class MariaDbR2dbcDockerComposeConnectionDetails extends DockerComposeConnectionDetails
implements R2dbcConnectionDetails {
private static final ConnectionFactoryOptionsBuilder connectionFactoryOptionsBuilder = new ConnectionFactoryOptionsBuilder(
"mariadb", 3306);
private final ConnectionFactoryOptions connectionFactoryOptions;
MariaDbR2dbcDockerComposeConnectionDetails(RunningService service) {
super(service);
MariaDbEnvironment environment = new MariaDbEnvironment(service.env());
this.connectionFactoryOptions = connectionFactoryOptionsBuilder.build(service, environment.getDatabase(),
environment.getUsername(), environment.getPassword());
}
@Override
public ConnectionFactoryOptions getConnectionFactoryOptions() {
return this.connectionFactoryOptions;
}
}
}

View File

@@ -1,20 +0,0 @@
/*
* 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.
*/
/**
* Auto-configuration for Docker Compose MariaDB service connections.
*/
package org.springframework.boot.docker.compose.service.connection.mariadb;

View File

@@ -1,92 +0,0 @@
/*
* Copyright 2012-2025 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 org.springframework.boot.docker.compose.service.connection.mongo;
import com.mongodb.ConnectionString;
import org.springframework.boot.docker.compose.core.RunningService;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource;
import org.springframework.boot.mongodb.autoconfigure.MongoConnectionDetails;
/**
* {@link DockerComposeConnectionDetailsFactory} to create {@link MongoConnectionDetails}
* for a {@code mongo} service.
*
* @author Moritz Halbritter
* @author Andy Wilkinson
* @author Phillip Webb
* @author Scott Frederick
*/
class MongoDockerComposeConnectionDetailsFactory extends DockerComposeConnectionDetailsFactory<MongoConnectionDetails> {
private static final String[] MONGODB_CONTAINER_NAMES = { "mongo", "bitnami/mongodb" };
private static final int MONGODB_PORT = 27017;
protected MongoDockerComposeConnectionDetailsFactory() {
super(MONGODB_CONTAINER_NAMES, "com.mongodb.ConnectionString");
}
@Override
protected MongoDockerComposeConnectionDetails getDockerComposeConnectionDetails(
DockerComposeConnectionSource source) {
return new MongoDockerComposeConnectionDetails(source.getRunningService());
}
/**
* {@link MongoConnectionDetails} backed by a {@code mongo} {@link RunningService}.
*/
static class MongoDockerComposeConnectionDetails extends DockerComposeConnectionDetails
implements MongoConnectionDetails {
private final ConnectionString connectionString;
MongoDockerComposeConnectionDetails(RunningService service) {
super(service);
this.connectionString = buildConnectionString(service);
}
private ConnectionString buildConnectionString(RunningService service) {
MongoEnvironment environment = new MongoEnvironment(service.env());
StringBuilder builder = new StringBuilder("mongodb://");
if (environment.getUsername() != null) {
builder.append(environment.getUsername());
builder.append(":");
builder.append((environment.getPassword() != null) ? environment.getPassword() : "");
builder.append("@");
}
builder.append(service.host());
builder.append(":");
builder.append(service.ports().get(MONGODB_PORT));
builder.append("/");
builder.append((environment.getDatabase() != null) ? environment.getDatabase() : "test");
if (environment.getUsername() != null) {
builder.append("?authSource=admin");
}
return new ConnectionString(builder.toString());
}
@Override
public ConnectionString getConnectionString() {
return this.connectionString;
}
}
}

View File

@@ -1,61 +0,0 @@
/*
* 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 org.springframework.boot.docker.compose.service.connection.mongo;
import java.util.Map;
import org.springframework.util.Assert;
/**
* MongoDB environment details.
*
* @author Moritz Halbritter
* @author Andy Wilkinson
* @author Phillip Webb
* @author Scott Frederick
*/
class MongoEnvironment {
private final String username;
private final String password;
private final String database;
MongoEnvironment(Map<String, String> env) {
Assert.state(!env.containsKey("MONGO_INITDB_ROOT_USERNAME_FILE"),
"MONGO_INITDB_ROOT_USERNAME_FILE is not supported");
Assert.state(!env.containsKey("MONGO_INITDB_ROOT_PASSWORD_FILE"),
"MONGO_INITDB_ROOT_PASSWORD_FILE is not supported");
this.username = env.getOrDefault("MONGO_INITDB_ROOT_USERNAME", env.get("MONGODB_ROOT_USERNAME"));
this.password = env.getOrDefault("MONGO_INITDB_ROOT_PASSWORD", env.get("MONGODB_ROOT_PASSWORD"));
this.database = env.getOrDefault("MONGO_INITDB_DATABASE", env.get("MONGODB_DATABASE"));
}
String getUsername() {
return this.username;
}
String getPassword() {
return this.password;
}
String getDatabase() {
return this.database;
}
}

View File

@@ -1,20 +0,0 @@
/*
* 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.
*/
/**
* Auto-configuration for Docker Compose MongoDB service connections.
*/
package org.springframework.boot.docker.compose.service.connection.mongo;

View File

@@ -1,73 +0,0 @@
/*
* 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 org.springframework.boot.docker.compose.service.connection.mysql;
import java.util.Map;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
* MySQL environment details.
*
* @author Moritz Halbritter
* @author Andy Wilkinson
* @author Phillip Webb
* @author Scott Frederick
*/
class MySqlEnvironment {
private final String username;
private final String password;
private final String database;
MySqlEnvironment(Map<String, String> env) {
this.username = env.getOrDefault("MYSQL_USER", "root");
this.password = extractPassword(env);
this.database = extractDatabase(env);
}
private String extractPassword(Map<String, String> env) {
Assert.state(!env.containsKey("MYSQL_RANDOM_ROOT_PASSWORD"), "MYSQL_RANDOM_ROOT_PASSWORD is not supported");
boolean allowEmpty = env.containsKey("MYSQL_ALLOW_EMPTY_PASSWORD") || env.containsKey("ALLOW_EMPTY_PASSWORD");
String password = env.get("MYSQL_PASSWORD");
password = (password != null) ? password : env.get("MYSQL_ROOT_PASSWORD");
Assert.state(StringUtils.hasLength(password) || allowEmpty, "No MySQL password found");
return (password != null) ? password : "";
}
private String extractDatabase(Map<String, String> env) {
String database = env.get("MYSQL_DATABASE");
Assert.state(database != null, "No MYSQL_DATABASE defined");
return database;
}
String getUsername() {
return this.username;
}
String getPassword() {
return this.password;
}
String getDatabase() {
return this.database;
}
}

View File

@@ -1,83 +0,0 @@
/*
* 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 org.springframework.boot.docker.compose.service.connection.mysql;
import org.springframework.boot.docker.compose.core.RunningService;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource;
import org.springframework.boot.docker.compose.service.connection.jdbc.JdbcUrlBuilder;
import org.springframework.boot.jdbc.autoconfigure.JdbcConnectionDetails;
/**
* {@link DockerComposeConnectionDetailsFactory} to create {@link JdbcConnectionDetails}
* for a {@code mysql} service.
*
* @author Moritz Halbritter
* @author Andy Wilkinson
* @author Phillip Webb
* @author Scott Frederick
*/
class MySqlJdbcDockerComposeConnectionDetailsFactory
extends DockerComposeConnectionDetailsFactory<JdbcConnectionDetails> {
private static final String[] MYSQL_CONTAINER_NAMES = { "mysql", "bitnami/mysql" };
protected MySqlJdbcDockerComposeConnectionDetailsFactory() {
super(MYSQL_CONTAINER_NAMES);
}
@Override
protected JdbcConnectionDetails getDockerComposeConnectionDetails(DockerComposeConnectionSource source) {
return new MySqlJdbcDockerComposeConnectionDetails(source.getRunningService());
}
/**
* {@link JdbcConnectionDetails} backed by a {@code mysql} {@link RunningService}.
*/
static class MySqlJdbcDockerComposeConnectionDetails extends DockerComposeConnectionDetails
implements JdbcConnectionDetails {
private static final JdbcUrlBuilder jdbcUrlBuilder = new JdbcUrlBuilder("mysql", 3306);
private final MySqlEnvironment environment;
private final String jdbcUrl;
MySqlJdbcDockerComposeConnectionDetails(RunningService service) {
super(service);
this.environment = new MySqlEnvironment(service.env());
this.jdbcUrl = jdbcUrlBuilder.build(service, this.environment.getDatabase());
}
@Override
public String getUsername() {
return this.environment.getUsername();
}
@Override
public String getPassword() {
return this.environment.getPassword();
}
@Override
public String getJdbcUrl() {
return this.jdbcUrl;
}
}
}

View File

@@ -1,75 +0,0 @@
/*
* Copyright 2012-2025 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 org.springframework.boot.docker.compose.service.connection.mysql;
import io.r2dbc.spi.ConnectionFactoryOptions;
import org.springframework.boot.docker.compose.core.RunningService;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource;
import org.springframework.boot.docker.compose.service.connection.r2dbc.ConnectionFactoryOptionsBuilder;
import org.springframework.boot.r2dbc.autoconfigure.R2dbcConnectionDetails;
/**
* {@link DockerComposeConnectionDetailsFactory} to create {@link R2dbcConnectionDetails}
* for a {@code mysql} service.
*
* @author Moritz Halbritter
* @author Andy Wilkinson
* @author Phillip Webb
* @author Scott Frederick
*/
class MySqlR2dbcDockerComposeConnectionDetailsFactory
extends DockerComposeConnectionDetailsFactory<R2dbcConnectionDetails> {
private static final String[] MYSQL_CONTAINER_NAMES = { "mysql", "bitnami/mysql" };
MySqlR2dbcDockerComposeConnectionDetailsFactory() {
super(MYSQL_CONTAINER_NAMES, "io.r2dbc.spi.ConnectionFactoryOptions");
}
@Override
protected R2dbcConnectionDetails getDockerComposeConnectionDetails(DockerComposeConnectionSource source) {
return new MySqlR2dbcDockerComposeConnectionDetails(source.getRunningService());
}
/**
* {@link R2dbcConnectionDetails} backed by a {@code mysql} {@link RunningService}.
*/
static class MySqlR2dbcDockerComposeConnectionDetails extends DockerComposeConnectionDetails
implements R2dbcConnectionDetails {
private static final ConnectionFactoryOptionsBuilder connectionFactoryOptionsBuilder = new ConnectionFactoryOptionsBuilder(
"mysql", 3306);
private final ConnectionFactoryOptions connectionFactoryOptions;
MySqlR2dbcDockerComposeConnectionDetails(RunningService service) {
super(service);
MySqlEnvironment environment = new MySqlEnvironment(service.env());
this.connectionFactoryOptions = connectionFactoryOptionsBuilder.build(service, environment.getDatabase(),
environment.getUsername(), environment.getPassword());
}
@Override
public ConnectionFactoryOptions getConnectionFactoryOptions() {
return this.connectionFactoryOptions;
}
}
}

View File

@@ -1,20 +0,0 @@
/*
* 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.
*/
/**
* Auto-configuration for Docker Compose MySQL service connections.
*/
package org.springframework.boot.docker.compose.service.connection.mysql;

View File

@@ -1,79 +0,0 @@
/*
* Copyright 2012-2025 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 org.springframework.boot.docker.compose.service.connection.neo4j;
import java.net.URI;
import org.neo4j.driver.AuthToken;
import org.springframework.boot.docker.compose.core.RunningService;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource;
import org.springframework.boot.neo4j.autoconfigure.Neo4jConnectionDetails;
/**
* {@link DockerComposeConnectionDetailsFactory} to create {@link Neo4jConnectionDetails}
* for a {@code Neo4j} service.
*
* @author Andy Wilkinson
* @author Scott Frederick
*/
class Neo4jDockerComposeConnectionDetailsFactory extends DockerComposeConnectionDetailsFactory<Neo4jConnectionDetails> {
private static final String[] NEO4J_CONTAINER_NAMES = { "neo4j", "bitnami/neo4j" };
Neo4jDockerComposeConnectionDetailsFactory() {
super(NEO4J_CONTAINER_NAMES);
}
@Override
protected Neo4jConnectionDetails getDockerComposeConnectionDetails(DockerComposeConnectionSource source) {
return new Neo4jDockerComposeConnectionDetails(source.getRunningService());
}
/**
* {@link Neo4jConnectionDetails} backed by a {@code Neo4j} {@link RunningService}.
*/
static class Neo4jDockerComposeConnectionDetails extends DockerComposeConnectionDetails
implements Neo4jConnectionDetails {
private static final int BOLT_PORT = 7687;
private final AuthToken authToken;
private final URI uri;
Neo4jDockerComposeConnectionDetails(RunningService service) {
super(service);
Neo4jEnvironment neo4jEnvironment = new Neo4jEnvironment(service.env());
this.authToken = neo4jEnvironment.getAuthToken();
this.uri = URI.create("neo4j://%s:%d".formatted(service.host(), service.ports().get(BOLT_PORT)));
}
@Override
public URI getUri() {
return this.uri;
}
@Override
public AuthToken getAuthToken() {
return this.authToken;
}
}
}

View File

@@ -1,62 +0,0 @@
/*
* 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 org.springframework.boot.docker.compose.service.connection.neo4j;
import java.util.Map;
import org.neo4j.driver.AuthToken;
import org.neo4j.driver.AuthTokens;
/**
* Neo4j environment details.
*
* @author Andy Wilkinson
* @author Scott Frederick
*/
class Neo4jEnvironment {
private final AuthToken authToken;
Neo4jEnvironment(Map<String, String> env) {
AuthToken authToken = parse(env.get("NEO4J_AUTH"));
if (authToken == null && env.containsKey("NEO4J_PASSWORD")) {
authToken = parse("neo4j/" + env.get("NEO4J_PASSWORD"));
}
this.authToken = authToken;
}
private AuthToken parse(String neo4jAuth) {
if (neo4jAuth == null) {
return null;
}
if ("none".equals(neo4jAuth)) {
return AuthTokens.none();
}
if (neo4jAuth.startsWith("neo4j/")) {
return AuthTokens.basic("neo4j", neo4jAuth.substring(6));
}
throw new IllegalStateException(
"Cannot extract auth token from NEO4J_AUTH environment variable with value '" + neo4jAuth + "'."
+ " Value should be 'none' to disable authentication or start with 'neo4j/' to specify"
+ " the neo4j user's password");
}
AuthToken getAuthToken() {
return this.authToken;
}
}

View File

@@ -1,20 +0,0 @@
/*
* 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.
*/
/**
* Auto-configuration for Docker Compose Neo4j service connections.
*/
package org.springframework.boot.docker.compose.service.connection.neo4j;

View File

@@ -1,47 +0,0 @@
/*
* Copyright 2012-2023 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 org.springframework.boot.docker.compose.service.connection.oracle;
/**
* Enumeration of supported Oracle containers.
*
* @author Andy Wilkinson
*/
enum OracleContainer {
FREE("gvenzl/oracle-free", "freepdb1"),
XE("gvenzl/oracle-xe", "xepdb1");
private final String imageName;
private final String defaultDatabase;
OracleContainer(String imageName, String defaultDatabase) {
this.imageName = imageName;
this.defaultDatabase = defaultDatabase;
}
String getImageName() {
return this.imageName;
}
String getDefaultDatabase() {
return this.defaultDatabase;
}
}

View File

@@ -1,68 +0,0 @@
/*
* Copyright 2012-2023 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 org.springframework.boot.docker.compose.service.connection.oracle;
import java.util.Map;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
* Oracle Database environment details.
*
* @author Andy Wilkinson
*/
class OracleEnvironment {
private final String username;
private final String password;
private final String database;
OracleEnvironment(Map<String, String> env, String defaultDatabase) {
this.username = env.getOrDefault("APP_USER", "system");
this.password = extractPassword(env);
this.database = env.getOrDefault("ORACLE_DATABASE", defaultDatabase);
}
private String extractPassword(Map<String, String> env) {
if (env.containsKey("APP_USER")) {
String password = env.get("APP_USER_PASSWORD");
Assert.state(StringUtils.hasLength(password), "No Oracle app password found");
return password;
}
Assert.state(!env.containsKey("ORACLE_RANDOM_PASSWORD"),
"ORACLE_RANDOM_PASSWORD is not supported without APP_USER and APP_USER_PASSWORD");
String password = env.get("ORACLE_PASSWORD");
Assert.state(StringUtils.hasLength(password), "No Oracle password found");
return password;
}
String getUsername() {
return this.username;
}
String getPassword() {
return this.password;
}
String getDatabase() {
return this.database;
}
}

View File

@@ -1,34 +0,0 @@
/*
* Copyright 2012-2023 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 org.springframework.boot.docker.compose.service.connection.oracle;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
import org.springframework.boot.jdbc.autoconfigure.JdbcConnectionDetails;
/**
* {@link DockerComposeConnectionDetailsFactory} to create {@link JdbcConnectionDetails}
* for an {@link OracleContainer#FREE} service.
*
* @author Andy Wilkinson
*/
class OracleFreeJdbcDockerComposeConnectionDetailsFactory extends OracleJdbcDockerComposeConnectionDetailsFactory {
protected OracleFreeJdbcDockerComposeConnectionDetailsFactory() {
super(OracleContainer.FREE);
}
}

View File

@@ -1,34 +0,0 @@
/*
* Copyright 2012-2025 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 org.springframework.boot.docker.compose.service.connection.oracle;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
import org.springframework.boot.r2dbc.autoconfigure.R2dbcConnectionDetails;
/**
* {@link DockerComposeConnectionDetailsFactory} to create {@link R2dbcConnectionDetails}
* for an {@link OracleContainer#FREE} service.
*
* @author Andy Wilkinson
*/
class OracleFreeR2dbcDockerComposeConnectionDetailsFactory extends OracleR2dbcDockerComposeConnectionDetailsFactory {
protected OracleFreeR2dbcDockerComposeConnectionDetailsFactory() {
super(OracleContainer.FREE);
}
}

View File

@@ -1,90 +0,0 @@
/*
* Copyright 2012-2023 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 org.springframework.boot.docker.compose.service.connection.oracle;
import org.springframework.boot.docker.compose.core.RunningService;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource;
import org.springframework.boot.jdbc.autoconfigure.JdbcConnectionDetails;
import org.springframework.util.StringUtils;
/**
* Base class for a {@link DockerComposeConnectionDetailsFactory} to create
* {@link JdbcConnectionDetails} for an {@code oracle-free} or {@code oracle-xe} service.
*
* @author Moritz Halbritter
* @author Andy Wilkinson
* @author Phillip Webb
*/
abstract class OracleJdbcDockerComposeConnectionDetailsFactory
extends DockerComposeConnectionDetailsFactory<JdbcConnectionDetails> {
private final String defaultDatabase;
protected OracleJdbcDockerComposeConnectionDetailsFactory(OracleContainer container) {
super(container.getImageName());
this.defaultDatabase = container.getDefaultDatabase();
}
@Override
protected JdbcConnectionDetails getDockerComposeConnectionDetails(DockerComposeConnectionSource source) {
return new OracleJdbcDockerComposeConnectionDetails(source.getRunningService(), this.defaultDatabase);
}
/**
* {@link JdbcConnectionDetails} backed by an {@code oracle-xe} or {@code oracle-free}
* {@link RunningService}.
*/
static class OracleJdbcDockerComposeConnectionDetails extends DockerComposeConnectionDetails
implements JdbcConnectionDetails {
private static final String PARAMETERS_LABEL = "org.springframework.boot.jdbc.parameters";
private final OracleEnvironment environment;
private final String jdbcUrl;
OracleJdbcDockerComposeConnectionDetails(RunningService service, String defaultDatabase) {
super(service);
this.environment = new OracleEnvironment(service.env(), defaultDatabase);
this.jdbcUrl = "jdbc:oracle:thin:@" + service.host() + ":" + service.ports().get(1521) + "/"
+ this.environment.getDatabase() + getParameters(service);
}
private String getParameters(RunningService service) {
String parameters = service.labels().get(PARAMETERS_LABEL);
return (StringUtils.hasLength(parameters)) ? "?" + parameters : "";
}
@Override
public String getUsername() {
return this.environment.getUsername();
}
@Override
public String getPassword() {
return this.environment.getPassword();
}
@Override
public String getJdbcUrl() {
return this.jdbcUrl;
}
}
}

View File

@@ -1,76 +0,0 @@
/*
* Copyright 2012-2025 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 org.springframework.boot.docker.compose.service.connection.oracle;
import io.r2dbc.spi.ConnectionFactoryOptions;
import org.springframework.boot.docker.compose.core.RunningService;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource;
import org.springframework.boot.docker.compose.service.connection.r2dbc.ConnectionFactoryOptionsBuilder;
import org.springframework.boot.r2dbc.autoconfigure.R2dbcConnectionDetails;
/**
* Base class for a {@link DockerComposeConnectionDetailsFactory} to create
* {@link R2dbcConnectionDetails} for an {@code oracle-free} or {@code oracle-xe} service.
*
* @author Moritz Halbritter
* @author Andy Wilkinson
* @author Phillip Webb
*/
abstract class OracleR2dbcDockerComposeConnectionDetailsFactory
extends DockerComposeConnectionDetailsFactory<R2dbcConnectionDetails> {
private final String defaultDatabase;
OracleR2dbcDockerComposeConnectionDetailsFactory(OracleContainer container) {
super(container.getImageName(), "io.r2dbc.spi.ConnectionFactoryOptions");
this.defaultDatabase = container.getDefaultDatabase();
}
@Override
protected R2dbcConnectionDetails getDockerComposeConnectionDetails(DockerComposeConnectionSource source) {
return new OracleDbR2dbcDockerComposeConnectionDetails(source.getRunningService(), this.defaultDatabase);
}
/**
* {@link R2dbcConnectionDetails} backed by a {@code gvenzl/oracle-xe}
* {@link RunningService}.
*/
static class OracleDbR2dbcDockerComposeConnectionDetails extends DockerComposeConnectionDetails
implements R2dbcConnectionDetails {
private static final ConnectionFactoryOptionsBuilder connectionFactoryOptionsBuilder = new ConnectionFactoryOptionsBuilder(
"oracle", 1521);
private final ConnectionFactoryOptions connectionFactoryOptions;
OracleDbR2dbcDockerComposeConnectionDetails(RunningService service, String defaultDatabase) {
super(service);
OracleEnvironment environment = new OracleEnvironment(service.env(), defaultDatabase);
this.connectionFactoryOptions = connectionFactoryOptionsBuilder.build(service, environment.getDatabase(),
environment.getUsername(), environment.getPassword());
}
@Override
public ConnectionFactoryOptions getConnectionFactoryOptions() {
return this.connectionFactoryOptions;
}
}
}

View File

@@ -1,34 +0,0 @@
/*
* Copyright 2012-2023 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 org.springframework.boot.docker.compose.service.connection.oracle;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
import org.springframework.boot.jdbc.autoconfigure.JdbcConnectionDetails;
/**
* {@link DockerComposeConnectionDetailsFactory} to create {@link JdbcConnectionDetails}
* for an {@link OracleContainer#XE} service.
*
* @author Andy Wilkinson
*/
class OracleXeJdbcDockerComposeConnectionDetailsFactory extends OracleJdbcDockerComposeConnectionDetailsFactory {
protected OracleXeJdbcDockerComposeConnectionDetailsFactory() {
super(OracleContainer.XE);
}
}

View File

@@ -1,34 +0,0 @@
/*
* Copyright 2012-2025 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 org.springframework.boot.docker.compose.service.connection.oracle;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
import org.springframework.boot.r2dbc.autoconfigure.R2dbcConnectionDetails;
/**
* {@link DockerComposeConnectionDetailsFactory} to create {@link R2dbcConnectionDetails}
* for an {@link OracleContainer#XE} service.
*
* @author Andy Wilkinson
*/
class OracleXeR2dbcDockerComposeConnectionDetailsFactory extends OracleR2dbcDockerComposeConnectionDetailsFactory {
protected OracleXeR2dbcDockerComposeConnectionDetailsFactory() {
super(OracleContainer.XE);
}
}

View File

@@ -1,20 +0,0 @@
/*
* 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.
*/
/**
* Auto-configuration for Docker Compose MySQL service connections.
*/
package org.springframework.boot.docker.compose.service.connection.oracle;

View File

@@ -1,78 +0,0 @@
/*
* 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 org.springframework.boot.docker.compose.service.connection.otlp;
import org.springframework.boot.actuate.autoconfigure.logging.otlp.OtlpLoggingConnectionDetails;
import org.springframework.boot.actuate.autoconfigure.logging.otlp.Transport;
import org.springframework.boot.docker.compose.core.RunningService;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource;
/**
* {@link DockerComposeConnectionDetailsFactory} to create
* {@link OtlpLoggingConnectionDetails} for an OTLP service.
*
* @author Eddú Meléndez
*/
class OpenTelemetryLoggingDockerComposeConnectionDetailsFactory
extends DockerComposeConnectionDetailsFactory<OtlpLoggingConnectionDetails> {
private static final String[] OPENTELEMETRY_IMAGE_NAMES = { "otel/opentelemetry-collector-contrib",
"grafana/otel-lgtm" };
private static final int OTLP_GRPC_PORT = 4317;
private static final int OTLP_HTTP_PORT = 4318;
OpenTelemetryLoggingDockerComposeConnectionDetailsFactory() {
super(OPENTELEMETRY_IMAGE_NAMES,
"org.springframework.boot.actuate.autoconfigure.logging.otlp.OtlpLoggingAutoConfiguration");
}
@Override
protected OtlpLoggingConnectionDetails getDockerComposeConnectionDetails(DockerComposeConnectionSource source) {
return new OpenTelemetryLoggingDockerComposeConnectionDetails(source.getRunningService());
}
private static final class OpenTelemetryLoggingDockerComposeConnectionDetails extends DockerComposeConnectionDetails
implements OtlpLoggingConnectionDetails {
private final String host;
private final int grpcPort;
private final int httpPort;
private OpenTelemetryLoggingDockerComposeConnectionDetails(RunningService source) {
super(source);
this.host = source.host();
this.grpcPort = source.ports().get(OTLP_GRPC_PORT);
this.httpPort = source.ports().get(OTLP_HTTP_PORT);
}
@Override
public String getUrl(Transport transport) {
int port = switch (transport) {
case HTTP -> this.httpPort;
case GRPC -> this.grpcPort;
};
return "http://%s:%d/v1/logs".formatted(this.host, port);
}
}
}

View File

@@ -1,68 +0,0 @@
/*
* 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 org.springframework.boot.docker.compose.service.connection.otlp;
import org.springframework.boot.actuate.autoconfigure.metrics.export.otlp.OtlpMetricsConnectionDetails;
import org.springframework.boot.docker.compose.core.RunningService;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource;
/**
* {@link DockerComposeConnectionDetailsFactory} to create
* {@link OtlpMetricsConnectionDetails} for an OTLP service.
*
* @author Eddú Meléndez
*/
class OpenTelemetryMetricsDockerComposeConnectionDetailsFactory
extends DockerComposeConnectionDetailsFactory<OtlpMetricsConnectionDetails> {
private static final String[] OPENTELEMETRY_IMAGE_NAMES = { "otel/opentelemetry-collector-contrib",
"grafana/otel-lgtm" };
private static final int OTLP_PORT = 4318;
OpenTelemetryMetricsDockerComposeConnectionDetailsFactory() {
super(OPENTELEMETRY_IMAGE_NAMES,
"org.springframework.boot.actuate.autoconfigure.metrics.export.otlp.OtlpMetricsExportAutoConfiguration");
}
@Override
protected OtlpMetricsConnectionDetails getDockerComposeConnectionDetails(DockerComposeConnectionSource source) {
return new OpenTelemetryMetricsDockerComposeConnectionDetails(source.getRunningService());
}
private static final class OpenTelemetryMetricsDockerComposeConnectionDetails extends DockerComposeConnectionDetails
implements OtlpMetricsConnectionDetails {
private final String host;
private final int port;
private OpenTelemetryMetricsDockerComposeConnectionDetails(RunningService source) {
super(source);
this.host = source.host();
this.port = source.ports().get(OTLP_PORT);
}
@Override
public String getUrl() {
return "http://%s:%d/v1/metrics".formatted(this.host, this.port);
}
}
}

View File

@@ -1,79 +0,0 @@
/*
* 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 org.springframework.boot.docker.compose.service.connection.otlp;
import org.springframework.boot.actuate.autoconfigure.tracing.otlp.OtlpTracingConnectionDetails;
import org.springframework.boot.actuate.autoconfigure.tracing.otlp.Transport;
import org.springframework.boot.docker.compose.core.RunningService;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource;
/**
* {@link DockerComposeConnectionDetailsFactory} to create
* {@link OtlpTracingConnectionDetails} for an OTLP service.
*
* @author Eddú Meléndez
* @author Moritz Halbritter
*/
class OpenTelemetryTracingDockerComposeConnectionDetailsFactory
extends DockerComposeConnectionDetailsFactory<OtlpTracingConnectionDetails> {
private static final String[] OPENTELEMETRY_IMAGE_NAMES = { "otel/opentelemetry-collector-contrib",
"grafana/otel-lgtm" };
private static final int OTLP_GRPC_PORT = 4317;
private static final int OTLP_HTTP_PORT = 4318;
OpenTelemetryTracingDockerComposeConnectionDetailsFactory() {
super(OPENTELEMETRY_IMAGE_NAMES,
"org.springframework.boot.actuate.autoconfigure.tracing.otlp.OtlpTracingAutoConfiguration");
}
@Override
protected OtlpTracingConnectionDetails getDockerComposeConnectionDetails(DockerComposeConnectionSource source) {
return new OpenTelemetryTracingDockerComposeConnectionDetails(source.getRunningService());
}
private static final class OpenTelemetryTracingDockerComposeConnectionDetails extends DockerComposeConnectionDetails
implements OtlpTracingConnectionDetails {
private final String host;
private final int grpcPort;
private final int httpPort;
private OpenTelemetryTracingDockerComposeConnectionDetails(RunningService source) {
super(source);
this.host = source.host();
this.grpcPort = source.ports().get(OTLP_GRPC_PORT);
this.httpPort = source.ports().get(OTLP_HTTP_PORT);
}
@Override
public String getUrl(Transport transport) {
int port = switch (transport) {
case HTTP -> this.httpPort;
case GRPC -> this.grpcPort;
};
return "http://%s:%d/v1/traces".formatted(this.host, port);
}
}
}

View File

@@ -1,20 +0,0 @@
/*
* 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.
*/
/**
* Support for Docker Compose OpenTelemetry service connections.
*/
package org.springframework.boot.docker.compose.service.connection.otlp;

View File

@@ -1,92 +0,0 @@
/*
* Copyright 2012-2025 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 org.springframework.boot.docker.compose.service.connection.postgres;
import java.util.Map;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
* Postgres environment details.
*
* @author Moritz Halbritter
* @author Andy Wilkinson
* @author Phillip Webb
* @author Scott Frederick
* @author Sidmar Theodoro
* @author He Zean
*/
class PostgresEnvironment {
private static final String[] USERNAME_KEYS = new String[] { "POSTGRES_USER", "POSTGRESQL_USER",
"POSTGRESQL_USERNAME" };
private static final String DEFAULT_USERNAME = "postgres";
private static final String[] DATABASE_KEYS = new String[] { "POSTGRES_DB", "POSTGRESQL_DB",
"POSTGRESQL_DATABASE" };
private final String username;
private final String password;
private final String database;
PostgresEnvironment(Map<String, String> env) {
this.username = extract(env, USERNAME_KEYS, DEFAULT_USERNAME);
this.password = extractPassword(env);
this.database = extract(env, DATABASE_KEYS, this.username);
}
private String extract(Map<String, String> env, String[] keys, String defaultValue) {
for (String key : keys) {
if (env.containsKey(key)) {
return env.get(key);
}
}
return defaultValue;
}
private String extractPassword(Map<String, String> env) {
if (isUsingTrustHostAuthMethod(env)) {
return null;
}
String password = env.getOrDefault("POSTGRES_PASSWORD", env.get("POSTGRESQL_PASSWORD"));
boolean allowEmpty = env.containsKey("ALLOW_EMPTY_PASSWORD");
Assert.state(allowEmpty || StringUtils.hasLength(password), "No PostgreSQL password found");
return (password != null) ? password : "";
}
private boolean isUsingTrustHostAuthMethod(Map<String, String> env) {
String hostAuthMethod = env.get("POSTGRES_HOST_AUTH_METHOD");
return "trust".equals(hostAuthMethod);
}
String getUsername() {
return this.username;
}
String getPassword() {
return this.password;
}
String getDatabase() {
return this.database;
}
}

View File

@@ -1,110 +0,0 @@
/*
* Copyright 2012-2025 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 org.springframework.boot.docker.compose.service.connection.postgres;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import org.springframework.boot.docker.compose.core.RunningService;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource;
import org.springframework.boot.docker.compose.service.connection.jdbc.JdbcUrlBuilder;
import org.springframework.boot.jdbc.autoconfigure.JdbcConnectionDetails;
import org.springframework.core.env.Environment;
import org.springframework.util.StringUtils;
/**
* {@link DockerComposeConnectionDetailsFactory} to create {@link JdbcConnectionDetails}
* for a {@code postgres} service.
*
* @author Moritz Halbritter
* @author Andy Wilkinson
* @author Phillip Webb
* @author Scott Frederick
*/
class PostgresJdbcDockerComposeConnectionDetailsFactory
extends DockerComposeConnectionDetailsFactory<JdbcConnectionDetails> {
private static final String[] POSTGRES_CONTAINER_NAMES = { "postgres", "bitnami/postgresql" };
protected PostgresJdbcDockerComposeConnectionDetailsFactory() {
super(POSTGRES_CONTAINER_NAMES);
}
@Override
protected JdbcConnectionDetails getDockerComposeConnectionDetails(DockerComposeConnectionSource source) {
return new PostgresJdbcDockerComposeConnectionDetails(source.getRunningService(), source.getEnvironment());
}
/**
* {@link JdbcConnectionDetails} backed by a {@code postgres} {@link RunningService}.
*/
static class PostgresJdbcDockerComposeConnectionDetails extends DockerComposeConnectionDetails
implements JdbcConnectionDetails {
private static final JdbcUrlBuilder jdbcUrlBuilder = new JdbcUrlBuilder("postgresql", 5432);
private final PostgresEnvironment environment;
private final String jdbcUrl;
PostgresJdbcDockerComposeConnectionDetails(RunningService service, Environment environment) {
super(service);
this.environment = new PostgresEnvironment(service.env());
this.jdbcUrl = addApplicationNameIfNecessary(jdbcUrlBuilder.build(service, this.environment.getDatabase()),
environment);
}
@Override
public String getUsername() {
return this.environment.getUsername();
}
@Override
public String getPassword() {
return this.environment.getPassword();
}
@Override
public String getJdbcUrl() {
return this.jdbcUrl;
}
private static String addApplicationNameIfNecessary(String jdbcUrl, Environment environment) {
if (jdbcUrl.contains("&ApplicationName=") || jdbcUrl.contains("?ApplicationName=")) {
return jdbcUrl;
}
String applicationName = environment.getProperty("spring.application.name");
if (!StringUtils.hasText(applicationName)) {
return jdbcUrl;
}
StringBuilder jdbcUrlBuilder = new StringBuilder(jdbcUrl);
if (!jdbcUrl.contains("?")) {
jdbcUrlBuilder.append("?");
}
else if (!jdbcUrl.endsWith("&")) {
jdbcUrlBuilder.append("&");
}
return jdbcUrlBuilder.append("ApplicationName")
.append('=')
.append(URLEncoder.encode(applicationName, StandardCharsets.UTF_8))
.toString();
}
}
}

View File

@@ -1,98 +0,0 @@
/*
* Copyright 2012-2025 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 org.springframework.boot.docker.compose.service.connection.postgres;
import io.r2dbc.spi.ConnectionFactoryOptions;
import io.r2dbc.spi.Option;
import org.springframework.boot.docker.compose.core.RunningService;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource;
import org.springframework.boot.docker.compose.service.connection.r2dbc.ConnectionFactoryOptionsBuilder;
import org.springframework.boot.r2dbc.autoconfigure.R2dbcConnectionDetails;
import org.springframework.core.env.Environment;
import org.springframework.util.StringUtils;
/**
* {@link DockerComposeConnectionDetailsFactory} to create {@link R2dbcConnectionDetails}
* for a {@code postgres} service.
*
* @author Moritz Halbritter
* @author Andy Wilkinson
* @author Phillip Webb
* @author Scott Frederick
*/
class PostgresR2dbcDockerComposeConnectionDetailsFactory
extends DockerComposeConnectionDetailsFactory<R2dbcConnectionDetails> {
private static final String[] POSTGRES_CONTAINER_NAMES = { "postgres", "bitnami/postgresql" };
PostgresR2dbcDockerComposeConnectionDetailsFactory() {
super(POSTGRES_CONTAINER_NAMES, "io.r2dbc.spi.ConnectionFactoryOptions");
}
@Override
protected R2dbcConnectionDetails getDockerComposeConnectionDetails(DockerComposeConnectionSource source) {
return new PostgresDbR2dbcDockerComposeConnectionDetails(source.getRunningService(), source.getEnvironment());
}
/**
* {@link R2dbcConnectionDetails} backed by a {@code postgres} {@link RunningService}.
*/
static class PostgresDbR2dbcDockerComposeConnectionDetails extends DockerComposeConnectionDetails
implements R2dbcConnectionDetails {
private static final Option<String> APPLICATION_NAME = Option.valueOf("applicationName");
private static final ConnectionFactoryOptionsBuilder connectionFactoryOptionsBuilder = new ConnectionFactoryOptionsBuilder(
"postgresql", 5432);
private final ConnectionFactoryOptions connectionFactoryOptions;
PostgresDbR2dbcDockerComposeConnectionDetails(RunningService service, Environment environment) {
super(service);
this.connectionFactoryOptions = getConnectionFactoryOptions(service, environment);
}
@Override
public ConnectionFactoryOptions getConnectionFactoryOptions() {
return this.connectionFactoryOptions;
}
private static ConnectionFactoryOptions getConnectionFactoryOptions(RunningService service,
Environment environment) {
PostgresEnvironment env = new PostgresEnvironment(service.env());
ConnectionFactoryOptions connectionFactoryOptions = connectionFactoryOptionsBuilder.build(service,
env.getDatabase(), env.getUsername(), env.getPassword());
return addApplicationNameIfNecessary(connectionFactoryOptions, environment);
}
private static ConnectionFactoryOptions addApplicationNameIfNecessary(
ConnectionFactoryOptions connectionFactoryOptions, Environment environment) {
if (connectionFactoryOptions.hasOption(APPLICATION_NAME)) {
return connectionFactoryOptions;
}
String applicationName = environment.getProperty("spring.application.name");
if (!StringUtils.hasText(applicationName)) {
return connectionFactoryOptions;
}
return connectionFactoryOptions.mutate().option(APPLICATION_NAME, applicationName).build();
}
}
}

View File

@@ -1,20 +0,0 @@
/*
* 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.
*/
/**
* Auto-configuration for Docker Compose Postgres service connections.
*/
package org.springframework.boot.docker.compose.service.connection.postgres;

View File

@@ -1,76 +0,0 @@
/*
* Copyright 2012-2025 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 org.springframework.boot.docker.compose.service.connection.pulsar;
import org.springframework.boot.docker.compose.core.ConnectionPorts;
import org.springframework.boot.docker.compose.core.RunningService;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource;
import org.springframework.boot.pulsar.autoconfigure.PulsarConnectionDetails;
/**
* {@link DockerComposeConnectionDetailsFactory} to create {@link PulsarConnectionDetails}
* for a {@code pulsar} service.
*
* @author Chris Bono
*/
class PulsarDockerComposeConnectionDetailsFactory
extends DockerComposeConnectionDetailsFactory<PulsarConnectionDetails> {
private static final int BROKER_PORT = 6650;
private static final int ADMIN_PORT = 8080;
PulsarDockerComposeConnectionDetailsFactory() {
super("apachepulsar/pulsar");
}
@Override
protected PulsarConnectionDetails getDockerComposeConnectionDetails(DockerComposeConnectionSource source) {
return new PulsarDockerComposeConnectionDetails(source.getRunningService());
}
/**
* {@link PulsarConnectionDetails} backed by a {@code pulsar} {@link RunningService}.
*/
static class PulsarDockerComposeConnectionDetails extends DockerComposeConnectionDetails
implements PulsarConnectionDetails {
private final String brokerUrl;
private final String adminUrl;
PulsarDockerComposeConnectionDetails(RunningService service) {
super(service);
ConnectionPorts ports = service.ports();
this.brokerUrl = "pulsar://%s:%s".formatted(service.host(), ports.get(BROKER_PORT));
this.adminUrl = "http://%s:%s".formatted(service.host(), ports.get(ADMIN_PORT));
}
@Override
public String getBrokerUrl() {
return this.brokerUrl;
}
@Override
public String getAdminUrl() {
return this.adminUrl;
}
}
}

View File

@@ -1,20 +0,0 @@
/*
* 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.
*/
/**
* Auto-configuration for Docker Compose Pulsar service connections.
*/
package org.springframework.boot.docker.compose.service.connection.pulsar;

View File

@@ -1,99 +0,0 @@
/*
* Copyright 2012-2025 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 org.springframework.boot.docker.compose.service.connection.r2dbc;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import io.r2dbc.spi.ConnectionFactoryOptions;
import io.r2dbc.spi.Option;
import org.springframework.boot.docker.compose.core.RunningService;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
* Utility used to build an R2DBC {@link ConnectionFactoryOptions} for a
* {@link RunningService}.
*
* @author Moritz Halbritter
* @author Andy Wilkinson
* @author Phillip Webb
* @since 3.1.0
*/
public class ConnectionFactoryOptionsBuilder {
private static final String PARAMETERS_LABEL = "org.springframework.boot.r2dbc.parameters";
private final String driver;
private final int sourcePort;
/**
* Create a new {@link ConnectionFactoryOptionsBuilder} instance.
* @param driver the driver
* @param containerPort the source container port
*/
public ConnectionFactoryOptionsBuilder(String driver, int containerPort) {
Assert.notNull(driver, "'driver' must not be null");
this.driver = driver;
this.sourcePort = containerPort;
}
public ConnectionFactoryOptions build(RunningService service, String database, String user, String password) {
Assert.notNull(service, "'service' must not be null");
Assert.notNull(database, "'database' must not be null");
ConnectionFactoryOptions.Builder builder = ConnectionFactoryOptions.builder()
.option(ConnectionFactoryOptions.DRIVER, this.driver)
.option(ConnectionFactoryOptions.HOST, service.host())
.option(ConnectionFactoryOptions.PORT, service.ports().get(this.sourcePort))
.option(ConnectionFactoryOptions.DATABASE, database);
if (StringUtils.hasLength(user)) {
builder.option(ConnectionFactoryOptions.USER, user);
}
if (StringUtils.hasLength(password)) {
builder.option(ConnectionFactoryOptions.PASSWORD, password);
}
applyParameters(service, builder);
return builder.build();
}
private void applyParameters(RunningService service, ConnectionFactoryOptions.Builder builder) {
String parameters = service.labels().get(PARAMETERS_LABEL);
try {
if (StringUtils.hasText(parameters)) {
parseParameters(parameters).forEach((name, value) -> builder.option(Option.valueOf(name), value));
}
}
catch (RuntimeException ex) {
throw new IllegalStateException(
"Unable to apply R2DBC label parameters '%s' defined on service %s".formatted(parameters, service));
}
}
private Map<String, String> parseParameters(String parameters) {
Map<String, String> result = new LinkedHashMap<>();
for (String parameter : StringUtils.commaDelimitedListToStringArray(parameters)) {
String[] parts = parameter.split("=");
Assert.state(parts.length == 2, () -> "'parameters' [%s] must cotain parsable value".formatted(parameter));
result.put(parts[0], parts[1]);
}
return Collections.unmodifiableMap(result);
}
}

View File

@@ -1,21 +0,0 @@
/*
* Copyright 2012-2025 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.
*/
/**
* Utilities to help when creating
* {@link org.springframework.boot.r2dbc.autoconfigure.R2dbcConnectionDetails}.
*/
package org.springframework.boot.docker.compose.service.connection.r2dbc;

View File

@@ -1,90 +0,0 @@
/*
* 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 org.springframework.boot.docker.compose.service.connection.rabbit;
import java.util.List;
import org.springframework.boot.amqp.autoconfigure.RabbitConnectionDetails;
import org.springframework.boot.docker.compose.core.RunningService;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource;
/**
* {@link DockerComposeConnectionDetailsFactory} to create {@link RabbitConnectionDetails}
* for a {@code rabbitmq} service.
*
* @author Moritz Halbritter
* @author Andy Wilkinson
* @author Phillip Webb
* @author Scott Frederick
*/
class RabbitDockerComposeConnectionDetailsFactory
extends DockerComposeConnectionDetailsFactory<RabbitConnectionDetails> {
private static final String[] RABBITMQ_CONTAINER_NAMES = { "rabbitmq", "bitnami/rabbitmq" };
private static final int RABBITMQ_PORT = 5672;
protected RabbitDockerComposeConnectionDetailsFactory() {
super(RABBITMQ_CONTAINER_NAMES);
}
@Override
protected RabbitConnectionDetails getDockerComposeConnectionDetails(DockerComposeConnectionSource source) {
return new RabbitDockerComposeConnectionDetails(source.getRunningService());
}
/**
* {@link RabbitConnectionDetails} backed by a {@code rabbitmq}
* {@link RunningService}.
*/
static class RabbitDockerComposeConnectionDetails extends DockerComposeConnectionDetails
implements RabbitConnectionDetails {
private final RabbitEnvironment environment;
private final List<Address> addresses;
protected RabbitDockerComposeConnectionDetails(RunningService service) {
super(service);
this.environment = new RabbitEnvironment(service.env());
this.addresses = List.of(new Address(service.host(), service.ports().get(RABBITMQ_PORT)));
}
@Override
public String getUsername() {
return this.environment.getUsername();
}
@Override
public String getPassword() {
return this.environment.getPassword();
}
@Override
public String getVirtualHost() {
return "/";
}
@Override
public List<Address> getAddresses() {
return this.addresses;
}
}
}

View File

@@ -1,48 +0,0 @@
/*
* 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 org.springframework.boot.docker.compose.service.connection.rabbit;
import java.util.Map;
/**
* RabbitMQ environment details.
*
* @author Moritz Halbritter
* @author Andy Wilkinson
* @author Phillip Webb
* @author Scott Frederick
*/
class RabbitEnvironment {
private final String username;
private final String password;
RabbitEnvironment(Map<String, String> env) {
this.username = env.getOrDefault("RABBITMQ_DEFAULT_USER", env.getOrDefault("RABBITMQ_USERNAME", "guest"));
this.password = env.getOrDefault("RABBITMQ_DEFAULT_PASS", env.getOrDefault("RABBITMQ_PASSWORD", "guest"));
}
String getUsername() {
return this.username;
}
String getPassword() {
return this.password;
}
}

View File

@@ -1,20 +0,0 @@
/*
* 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.
*/
/**
* Auto-configuration for Docker Compose RabbitMQ service connections.
*/
package org.springframework.boot.docker.compose.service.connection.rabbit;

View File

@@ -1,70 +0,0 @@
/*
* Copyright 2012-2025 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 org.springframework.boot.docker.compose.service.connection.redis;
import org.springframework.boot.data.redis.autoconfigure.RedisConnectionDetails;
import org.springframework.boot.docker.compose.core.RunningService;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource;
/**
* {@link DockerComposeConnectionDetailsFactory} to create {@link RedisConnectionDetails}
* for a {@code redis} service.
*
* @author Moritz Halbritter
* @author Andy Wilkinson
* @author Phillip Webb
* @author Scott Frederick
* @author Eddú Meléndez
*/
class RedisDockerComposeConnectionDetailsFactory extends DockerComposeConnectionDetailsFactory<RedisConnectionDetails> {
private static final String[] REDIS_CONTAINER_NAMES = { "redis", "bitnami/redis", "redis/redis-stack",
"redis/redis-stack-server" };
private static final int REDIS_PORT = 6379;
RedisDockerComposeConnectionDetailsFactory() {
super(REDIS_CONTAINER_NAMES);
}
@Override
protected RedisConnectionDetails getDockerComposeConnectionDetails(DockerComposeConnectionSource source) {
return new RedisDockerComposeConnectionDetails(source.getRunningService());
}
/**
* {@link RedisConnectionDetails} backed by a {@code redis} {@link RunningService}.
*/
static class RedisDockerComposeConnectionDetails extends DockerComposeConnectionDetails
implements RedisConnectionDetails {
private final Standalone standalone;
RedisDockerComposeConnectionDetails(RunningService service) {
super(service);
this.standalone = Standalone.of(service.host(), service.ports().get(REDIS_PORT), getSslBundle(service));
}
@Override
public Standalone getStandalone() {
return this.standalone;
}
}
}

View File

@@ -1,20 +0,0 @@
/*
* 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.
*/
/**
* Auto-configuration for Docker Compose Redis service connections.
*/
package org.springframework.boot.docker.compose.service.connection.redis;

View File

@@ -1,54 +0,0 @@
/*
* Copyright 2012-2023 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 org.springframework.boot.docker.compose.service.connection.sqlserver;
import java.util.Map;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
* MS SQL Server environment details.
*
* @author Andy Wilkinson
*/
class SqlServerEnvironment {
private final String username = "SA";
private final String password;
SqlServerEnvironment(Map<String, String> env) {
this.password = extractPassword(env);
}
private String extractPassword(Map<String, String> env) {
String password = env.get("MSSQL_SA_PASSWORD");
password = (password != null) ? password : env.get("SA_PASSWORD");
Assert.state(StringUtils.hasLength(password), "No MSSQL password found");
return password;
}
String getUsername() {
return this.username;
}
String getPassword() {
return this.password;
}
}

View File

@@ -1,104 +0,0 @@
/*
* 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 org.springframework.boot.docker.compose.service.connection.sqlserver;
import org.springframework.boot.docker.compose.core.RunningService;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource;
import org.springframework.boot.docker.compose.service.connection.jdbc.JdbcUrlBuilder;
import org.springframework.boot.jdbc.autoconfigure.JdbcConnectionDetails;
/**
* {@link DockerComposeConnectionDetailsFactory} to create {@link JdbcConnectionDetails}
* for a {@code mssql/server} service.
*
* @author Andy Wilkinson
*/
class SqlServerJdbcDockerComposeConnectionDetailsFactory
extends DockerComposeConnectionDetailsFactory<JdbcConnectionDetails> {
protected SqlServerJdbcDockerComposeConnectionDetailsFactory() {
super("mssql/server");
}
@Override
protected JdbcConnectionDetails getDockerComposeConnectionDetails(DockerComposeConnectionSource source) {
return new SqlServerJdbcDockerComposeConnectionDetails(source.getRunningService());
}
/**
* {@link JdbcConnectionDetails} backed by a {@code mssql/server}
* {@link RunningService}.
*/
static class SqlServerJdbcDockerComposeConnectionDetails extends DockerComposeConnectionDetails
implements JdbcConnectionDetails {
private static final JdbcUrlBuilder jdbcUrlBuilder = new SqlServerJdbcUrlBuilder("sqlserver", 1433);
private final SqlServerEnvironment environment;
private final String jdbcUrl;
SqlServerJdbcDockerComposeConnectionDetails(RunningService service) {
super(service);
this.environment = new SqlServerEnvironment(service.env());
this.jdbcUrl = disableEncryptionIfNecessary(jdbcUrlBuilder.build(service));
}
private String disableEncryptionIfNecessary(String jdbcUrl) {
if (jdbcUrl.contains(";encrypt=false;")) {
return jdbcUrl;
}
StringBuilder jdbcUrlBuilder = new StringBuilder(jdbcUrl);
if (!jdbcUrl.endsWith(";")) {
jdbcUrlBuilder.append(";");
}
jdbcUrlBuilder.append("encrypt=false;");
return jdbcUrlBuilder.toString();
}
@Override
public String getUsername() {
return this.environment.getUsername();
}
@Override
public String getPassword() {
return this.environment.getPassword();
}
@Override
public String getJdbcUrl() {
return this.jdbcUrl;
}
private static final class SqlServerJdbcUrlBuilder extends JdbcUrlBuilder {
private SqlServerJdbcUrlBuilder(String driverProtocol, int containerPort) {
super(driverProtocol, containerPort);
}
@Override
protected void appendParameters(StringBuilder url, String parameters) {
url.append(";").append(parameters);
}
}
}
}

View File

@@ -1,72 +0,0 @@
/*
* Copyright 2012-2025 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 org.springframework.boot.docker.compose.service.connection.sqlserver;
import io.r2dbc.spi.ConnectionFactoryOptions;
import org.springframework.boot.docker.compose.core.RunningService;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource;
import org.springframework.boot.docker.compose.service.connection.r2dbc.ConnectionFactoryOptionsBuilder;
import org.springframework.boot.r2dbc.autoconfigure.R2dbcConnectionDetails;
/**
* {@link DockerComposeConnectionDetailsFactory} to create {@link R2dbcConnectionDetails}
* for a {@code mssql} service.
*
* @author Moritz Halbritter
* @author Andy Wilkinson
* @author Phillip Webb
*/
class SqlServerR2dbcDockerComposeConnectionDetailsFactory
extends DockerComposeConnectionDetailsFactory<R2dbcConnectionDetails> {
SqlServerR2dbcDockerComposeConnectionDetailsFactory() {
super("mssql/server", "io.r2dbc.spi.ConnectionFactoryOptions");
}
@Override
protected R2dbcConnectionDetails getDockerComposeConnectionDetails(DockerComposeConnectionSource source) {
return new SqlServerR2dbcDockerComposeConnectionDetails(source.getRunningService());
}
/**
* {@link R2dbcConnectionDetails} backed by a {@code mssql} {@link RunningService}.
*/
static class SqlServerR2dbcDockerComposeConnectionDetails extends DockerComposeConnectionDetails
implements R2dbcConnectionDetails {
private static final ConnectionFactoryOptionsBuilder connectionFactoryOptionsBuilder = new ConnectionFactoryOptionsBuilder(
"mssql", 1433);
private final ConnectionFactoryOptions connectionFactoryOptions;
SqlServerR2dbcDockerComposeConnectionDetails(RunningService service) {
super(service);
SqlServerEnvironment environment = new SqlServerEnvironment(service.env());
this.connectionFactoryOptions = connectionFactoryOptionsBuilder.build(service, "",
environment.getUsername(), environment.getPassword());
}
@Override
public ConnectionFactoryOptions getConnectionFactoryOptions() {
return this.connectionFactoryOptions;
}
}
}

View File

@@ -1,20 +0,0 @@
/*
* 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.
*/
/**
* Auto-configuration for Docker Compose MS SQL Server service connections.
*/
package org.springframework.boot.docker.compose.service.connection.sqlserver;

View File

@@ -1,70 +0,0 @@
/*
* Copyright 2012-2023 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 org.springframework.boot.docker.compose.service.connection.zipkin;
import org.springframework.boot.actuate.autoconfigure.tracing.zipkin.ZipkinConnectionDetails;
import org.springframework.boot.docker.compose.core.RunningService;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource;
/**
* {@link DockerComposeConnectionDetailsFactory} to create {@link ZipkinConnectionDetails}
* for a {@code zipkin} service.
*
* @author Moritz Halbritter
* @author Andy Wilkinson
* @author Phillip Webb
*/
class ZipkinDockerComposeConnectionDetailsFactory
extends DockerComposeConnectionDetailsFactory<ZipkinConnectionDetails> {
private static final int ZIPKIN_PORT = 9411;
ZipkinDockerComposeConnectionDetailsFactory() {
super("openzipkin/zipkin",
"org.springframework.boot.actuate.autoconfigure.tracing.zipkin.ZipkinAutoConfiguration");
}
@Override
protected ZipkinConnectionDetails getDockerComposeConnectionDetails(DockerComposeConnectionSource source) {
return new ZipkinDockerComposeConnectionDetails(source.getRunningService());
}
/**
* {@link ZipkinConnectionDetails} backed by a {@code zipkin} {@link RunningService}.
*/
static class ZipkinDockerComposeConnectionDetails extends DockerComposeConnectionDetails
implements ZipkinConnectionDetails {
private final String host;
private final int port;
ZipkinDockerComposeConnectionDetails(RunningService source) {
super(source);
this.host = source.host();
this.port = source.ports().get(ZIPKIN_PORT);
}
@Override
public String getSpanEndpoint() {
return "http://" + this.host + ":" + this.port + "/api/v2/spans";
}
}
}

View File

@@ -1,20 +0,0 @@
/*
* 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.
*/
/**
* Auto-configuration for Docker Compose Zipkin service connections.
*/
package org.springframework.boot.docker.compose.service.connection.zipkin;

View File

@@ -2,39 +2,3 @@
org.springframework.context.ApplicationListener=\
org.springframework.boot.docker.compose.lifecycle.DockerComposeListener,\
org.springframework.boot.docker.compose.service.connection.DockerComposeServiceConnectionsApplicationListener
# Connection Details Factories
org.springframework.boot.autoconfigure.service.connection.ConnectionDetailsFactory=\
org.springframework.boot.docker.compose.service.connection.activemq.ActiveMQClassicDockerComposeConnectionDetailsFactory,\
org.springframework.boot.docker.compose.service.connection.activemq.ActiveMQDockerComposeConnectionDetailsFactory,\
org.springframework.boot.docker.compose.service.connection.activemq.ArtemisDockerComposeConnectionDetailsFactory,\
org.springframework.boot.docker.compose.service.connection.cassandra.CassandraDockerComposeConnectionDetailsFactory,\
org.springframework.boot.docker.compose.service.connection.clickhouse.ClickHouseJdbcDockerComposeConnectionDetailsFactory,\
org.springframework.boot.docker.compose.service.connection.clickhouse.ClickHouseR2dbcDockerComposeConnectionDetailsFactory,\
org.springframework.boot.docker.compose.service.connection.elasticsearch.ElasticsearchDockerComposeConnectionDetailsFactory,\
org.springframework.boot.docker.compose.service.connection.flyway.JdbcAdaptingFlywayConnectionDetailsFactory,\
org.springframework.boot.docker.compose.service.connection.hazelcast.HazelcastDockerComposeConnectionDetailsFactory,\
org.springframework.boot.docker.compose.service.connection.ldap.LLdapDockerComposeConnectionDetailsFactory,\
org.springframework.boot.docker.compose.service.connection.ldap.OpenLdapDockerComposeConnectionDetailsFactory,\
org.springframework.boot.docker.compose.service.connection.liquibase.JdbcAdaptingLiquibaseConnectionDetailsFactory,\
org.springframework.boot.docker.compose.service.connection.mariadb.MariaDbJdbcDockerComposeConnectionDetailsFactory,\
org.springframework.boot.docker.compose.service.connection.mariadb.MariaDbR2dbcDockerComposeConnectionDetailsFactory,\
org.springframework.boot.docker.compose.service.connection.mongo.MongoDockerComposeConnectionDetailsFactory,\
org.springframework.boot.docker.compose.service.connection.mysql.MySqlJdbcDockerComposeConnectionDetailsFactory,\
org.springframework.boot.docker.compose.service.connection.mysql.MySqlR2dbcDockerComposeConnectionDetailsFactory,\
org.springframework.boot.docker.compose.service.connection.neo4j.Neo4jDockerComposeConnectionDetailsFactory,\
org.springframework.boot.docker.compose.service.connection.oracle.OracleFreeJdbcDockerComposeConnectionDetailsFactory,\
org.springframework.boot.docker.compose.service.connection.oracle.OracleFreeR2dbcDockerComposeConnectionDetailsFactory,\
org.springframework.boot.docker.compose.service.connection.oracle.OracleXeJdbcDockerComposeConnectionDetailsFactory,\
org.springframework.boot.docker.compose.service.connection.oracle.OracleXeR2dbcDockerComposeConnectionDetailsFactory,\
org.springframework.boot.docker.compose.service.connection.otlp.OpenTelemetryLoggingDockerComposeConnectionDetailsFactory,\
org.springframework.boot.docker.compose.service.connection.otlp.OpenTelemetryMetricsDockerComposeConnectionDetailsFactory,\
org.springframework.boot.docker.compose.service.connection.otlp.OpenTelemetryTracingDockerComposeConnectionDetailsFactory,\
org.springframework.boot.docker.compose.service.connection.postgres.PostgresJdbcDockerComposeConnectionDetailsFactory,\
org.springframework.boot.docker.compose.service.connection.postgres.PostgresR2dbcDockerComposeConnectionDetailsFactory,\
org.springframework.boot.docker.compose.service.connection.pulsar.PulsarDockerComposeConnectionDetailsFactory,\
org.springframework.boot.docker.compose.service.connection.rabbit.RabbitDockerComposeConnectionDetailsFactory,\
org.springframework.boot.docker.compose.service.connection.redis.RedisDockerComposeConnectionDetailsFactory,\
org.springframework.boot.docker.compose.service.connection.sqlserver.SqlServerJdbcDockerComposeConnectionDetailsFactory,\
org.springframework.boot.docker.compose.service.connection.sqlserver.SqlServerR2dbcDockerComposeConnectionDetailsFactory,\
org.springframework.boot.docker.compose.service.connection.zipkin.ZipkinDockerComposeConnectionDetailsFactory