Skip to content

Commit 4a491f6

Browse files
authored
Merge pull request #108 from aguibert/liberty-optional-configdir
Add toleration for liberty image building when config dir is not present
2 parents 86c8696 + 2692f61 commit 4a491f6

2 files changed

Lines changed: 25 additions & 32 deletions

File tree

modules/liberty/src/main/java/org/testcontainers/containers/liberty/LibertyAdapter.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,25 @@ public void setConfigProperties(Map<String, String> properties) {
9797

9898
@Override
9999
public ImageFromDockerfile getDefaultImage(File appFile) {
100-
String appName = appFile.getName();
100+
final String appName = appFile.getName();
101+
final File configDir = new File("src/main/liberty/config");
102+
final boolean configDirExists = configDir.exists() && configDir.canRead();
101103
// Compose a docker image equivalent to doing:
102104
// FROM open-liberty:microProfile3
103-
// ADD build/libs/<appFile> /config/dropins
104105
// COPY src/main/liberty/config /config/
106+
// ADD build/libs/<appFile> /config/dropins
105107
ImageFromDockerfile image = new ImageFromDockerfile()
106-
.withDockerfileFromBuilder(builder -> builder.from(getBaseDockerImage())
107-
.add("/config/dropins/" + appName, "/config/dropins/" + appName)
108-
.copy("/config", "/config")
109-
.build())
110-
.withFileFromFile("/config/dropins/" + appName, appFile)
111-
.withFileFromFile("/config", new File("src/main/liberty/config"));
108+
.withDockerfileFromBuilder(builder -> {
109+
builder.from(getBaseDockerImage());
110+
if (configDirExists) {
111+
builder.copy("/config", "/config");
112+
}
113+
builder.add("/config/dropins/" + appName, "/config/dropins/" + appName);
114+
builder.build();
115+
})
116+
.withFileFromFile("/config/dropins/" + appName, appFile);
117+
if (configDirExists)
118+
image.withFileFromFile("/config", configDir);
112119
return image;
113120
}
114121

modules/testcontainers/src/main/java/org/microshed/testing/testcontainers/MicroProfileApplication.java

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,13 @@
6565
*/
6666
public class MicroProfileApplication extends GenericContainer<MicroProfileApplication> {
6767

68-
private static final String MP_HEALTH_READINESS_PATH = "/health/ready";
68+
/**
69+
* A path representing the MicroProfile Health 2.0 readiness check
70+
*/
71+
public static final String MP_HEALTH_READINESS_PATH = "/health/ready";
72+
6973
private static final Logger LOGGER = LoggerFactory.getLogger(MicroProfileApplication.class);
70-
private static final boolean mpHealth20Available;
7174
private static final boolean isHollow = isHollow();
72-
static {
73-
Class<?> readinessClass = null;
74-
try {
75-
readinessClass = Class.forName("org.eclipse.microprofile.health.Readiness");
76-
} catch (ClassNotFoundException e) {
77-
}
78-
mpHealth20Available = readinessClass != null;
79-
}
8075

8176
private String appContextRoot;
8277
private ServerAdapter serverAdapter;
@@ -232,13 +227,12 @@ protected void configure() {
232227
super.configure();
233228
// If the readiness path was not set explicitly, default it to:
234229
// A) The value defined by ServerAdapter.getReadinessPath(), if any
235-
// B) The standard MP Health 2.0 readiness endpoint (if available)
236-
// C) the app context root
230+
// B) the app context root
237231
if (!readinessPathSet) {
238-
if (serverAdapter != null && serverAdapter.getReadinessPath().isPresent() && !serverAdapter.getReadinessPath().get().trim().isEmpty()) {
232+
if (serverAdapter != null && serverAdapter.getReadinessPath().isPresent()) {
239233
withReadinessPath(serverAdapter.getReadinessPath().get());
240234
} else {
241-
withReadinessPath(mpHealth20Available ? MP_HEALTH_READINESS_PATH : appContextRoot);
235+
withReadinessPath(appContextRoot);
242236
}
243237
}
244238
}
@@ -322,11 +316,7 @@ public MicroProfileApplication withAppContextRoot(String appContextRoot) {
322316
/**
323317
* Sets the path to be used to determine container readiness. The readiness check will
324318
* timeout after a sensible amount of time has elapsed.
325-
* If unspecified, the readiness path with defailt to either:
326-
* <ol><li>The MicroProfile Health 2.0 readiness endpoint <code>/health/readiness</code>,
327-
* if MP Health 2.0 API is accessible</li>
328-
* <li>Otherwise, the application context root</li>
329-
* </ol>
319+
* If unspecified, the readiness path with defailt to the application context root
330320
*
331321
* @param readinessUrl The HTTP endpoint to be polled for readiness. Once the endpoint
332322
* returns HTTP 200 (OK), the container is considered to be ready.
@@ -340,11 +330,7 @@ public MicroProfileApplication withReadinessPath(String readinessUrl) {
340330
/**
341331
* Sets the path to be used to determine container readiness. The readiness check will
342332
* timeout after a sensible amount of time has elapsed.
343-
* If unspecified, the readiness path with defailt to either:
344-
* <ol><li>The MicroProfile Health 2.0 readiness endpoint <code>/health/readiness</code>,
345-
* if MP Health 2.0 API is accessible</li>
346-
* <li>Otherwise, the application context root</li>
347-
* </ol>
333+
* If unspecified, the readiness path with defailt to the application context root
348334
*
349335
* @param readinessUrl The HTTP endpoint to be polled for readiness. Once the endpoint
350336
* returns HTTP 200 (OK), the container is considered to be ready.

0 commit comments

Comments
 (0)