-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #227 from sourcecase/feature-docker-compose-extend…
…s-support Add support for https://docs.docker.com/compose/extends/ Next Try
- Loading branch information
Showing
5 changed files
with
182 additions
and
17 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
67 changes: 67 additions & 0 deletions
67
core/src/test/java/org/testcontainers/junit/DockerComposeDoNotOverrideTest.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,67 @@ | ||
package org.testcontainers.junit; | ||
|
||
import com.google.common.util.concurrent.Uninterruptibles; | ||
import org.junit.Assume; | ||
import org.junit.BeforeClass; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.rnorth.ducttape.unreliables.Unreliables; | ||
import org.testcontainers.containers.DockerComposeContainer; | ||
import org.testcontainers.utility.TestEnvironment; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.net.Socket; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import static org.rnorth.visibleassertions.VisibleAssertions.info; | ||
import static org.rnorth.visibleassertions.VisibleAssertions.pass; | ||
|
||
/** | ||
* Created by rnorth on 11/06/2016. | ||
*/ | ||
public class DockerComposeDoNotOverrideTest { | ||
|
||
static final String DOCKER_COMPOSE_OVERRIDE_TEST_BASE_YML = "src/test/resources/docker-compose-base.yml"; | ||
static final String DOCKER_COMPOSE_OVERRIDE_TEST_BASE_ENV = "bar=base"; | ||
|
||
static final String DOCKER_COMPOSE_OVERRIDE_TEST_OVERRIDE_YML = "src/test/resources/docker-compose-non-default-override.yml"; | ||
static final String DOCKER_COMPOSE_OVERRIDE_TEST_OVERRIDE_ENV = "bar=overwritten"; | ||
|
||
@Rule | ||
public DockerComposeContainer compose = | ||
new DockerComposeContainer(new File(DOCKER_COMPOSE_OVERRIDE_TEST_BASE_YML)) | ||
.withExposedService("alpine_1", 3000); | ||
|
||
@BeforeClass | ||
public static void checkVersion() { | ||
Assume.assumeTrue(TestEnvironment.dockerApiAtLeast("1.22")); | ||
} | ||
|
||
|
||
@Test(timeout = 30_000) | ||
public void testEnvVar() throws IOException { | ||
BufferedReader br = Unreliables.retryUntilSuccess(10, TimeUnit.SECONDS, () -> { | ||
Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS); | ||
|
||
Socket socket = new Socket(compose.getServiceHost("alpine_1", 3000), compose.getServicePort("alpine_1", 3000)); | ||
return new BufferedReader(new InputStreamReader(socket.getInputStream())); | ||
}); | ||
|
||
Unreliables.retryUntilTrue(10, TimeUnit.SECONDS, () -> { | ||
while (br.ready()) { | ||
String line = br.readLine(); | ||
if (line.contains(DOCKER_COMPOSE_OVERRIDE_TEST_BASE_ENV)) { | ||
pass("Mapped environment variable was found"); | ||
return true; | ||
} | ||
} | ||
info("Mapped environment variable was not found yet - process probably not ready"); | ||
Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS); | ||
return false; | ||
}); | ||
|
||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
core/src/test/java/org/testcontainers/junit/DockerComposeOverrideTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package org.testcontainers.junit; | ||
|
||
import com.google.common.util.concurrent.Uninterruptibles; | ||
import org.junit.Assume; | ||
import org.junit.BeforeClass; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.rnorth.ducttape.unreliables.Unreliables; | ||
import org.testcontainers.containers.DockerComposeContainer; | ||
import org.testcontainers.utility.TestEnvironment; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.net.Socket; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import static org.rnorth.visibleassertions.VisibleAssertions.info; | ||
import static org.rnorth.visibleassertions.VisibleAssertions.pass; | ||
import static org.testcontainers.junit.DockerComposeDoNotOverrideTest.*; | ||
|
||
/** | ||
* Created by rnorth on 11/06/2016. | ||
*/ | ||
public class DockerComposeOverrideTest { | ||
|
||
@Rule | ||
public DockerComposeContainer compose = | ||
new DockerComposeContainer( | ||
new File(DOCKER_COMPOSE_OVERRIDE_TEST_BASE_YML), | ||
new File(DOCKER_COMPOSE_OVERRIDE_TEST_OVERRIDE_YML)) | ||
.withExposedService("alpine_1", 3000); | ||
|
||
@BeforeClass | ||
public static void checkVersion() { | ||
Assume.assumeTrue(TestEnvironment.dockerApiAtLeast("1.22")); | ||
} | ||
|
||
|
||
@Test(timeout = 30_000) | ||
public void testEnvVar() throws IOException { | ||
BufferedReader br = Unreliables.retryUntilSuccess(10, TimeUnit.SECONDS, () -> { | ||
Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS); | ||
|
||
Socket socket = new Socket(compose.getServiceHost("alpine_1", 3000), compose.getServicePort("alpine_1", 3000)); | ||
return new BufferedReader(new InputStreamReader(socket.getInputStream())); | ||
}); | ||
|
||
Unreliables.retryUntilTrue(10, TimeUnit.SECONDS, () -> { | ||
while (br.ready()) { | ||
String line = br.readLine(); | ||
if (line.contains(DOCKER_COMPOSE_OVERRIDE_TEST_OVERRIDE_ENV)) { | ||
pass("Mapped environment variable was found"); | ||
return true; | ||
} | ||
} | ||
info("Mapped environment variable was not found yet - process probably not ready"); | ||
Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS); | ||
return false; | ||
}); | ||
|
||
} | ||
} |
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,6 @@ | ||
version: '2' | ||
services: | ||
alpine: | ||
build: compose-dockerfile | ||
environment: | ||
bar: base |
5 changes: 5 additions & 0 deletions
5
core/src/test/resources/docker-compose-non-default-override.yml
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,5 @@ | ||
version: '2' | ||
services: | ||
alpine: | ||
environment: | ||
bar: overwritten |