-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add utility class to allow image names to be configured via a classpa…
…th file Replace static string names for ambassador and vnc recorder container images with classpath lookup. Add note to readme re overriding hardcoded image names Refs #259, #276
- Loading branch information
Showing
4 changed files
with
77 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
core/src/main/java/org/testcontainers/utility/TestcontainersConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.testcontainers.utility; | ||
|
||
import com.google.common.base.MoreObjects; | ||
import lombok.Data; | ||
import lombok.Getter; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.URL; | ||
import java.util.Properties; | ||
|
||
/** | ||
* Provides a mechanism for fetching configuration/defaults from the classpath. | ||
*/ | ||
@Data | ||
@Slf4j | ||
public class TestcontainersConfiguration { | ||
|
||
// No public constructor - must use getInstance() method. | ||
private TestcontainersConfiguration() { | ||
} | ||
|
||
@Getter(lazy = true) | ||
private static final TestcontainersConfiguration instance = loadConfiguration(); | ||
|
||
private static TestcontainersConfiguration loadConfiguration() { | ||
final TestcontainersConfiguration config = new TestcontainersConfiguration(); | ||
|
||
ClassLoader loader = MoreObjects.firstNonNull( | ||
Thread.currentThread().getContextClassLoader(), | ||
TestcontainersConfiguration.class.getClassLoader()); | ||
final URL configOverrides = loader.getResource("testcontainers.properties"); | ||
if (configOverrides != null) { | ||
|
||
log.debug("Testcontainers configuration overrides will be loaded from {}", configOverrides); | ||
|
||
final Properties properties = new Properties(); | ||
try (final InputStream inputStream = configOverrides.openStream()) { | ||
properties.load(inputStream); | ||
|
||
config.ambassadorContainerImage = properties.getProperty("ambassador.container.image", config.ambassadorContainerImage); | ||
config.vncRecordedContainerImage = properties.getProperty("vncrecorder.container.image", config.vncRecordedContainerImage); | ||
|
||
log.debug("Testcontainers configuration overrides loaded from {}: {}", configOverrides, config); | ||
|
||
} catch (IOException e) { | ||
log.error("Testcontainers config override was found on classpath but could not be loaded", e); | ||
} | ||
} | ||
|
||
return config; | ||
} | ||
|
||
public String ambassadorContainerImage = "richnorth/ambassador:latest"; | ||
public String vncRecordedContainerImage = "richnorth/vnc-recorder:latest"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters