Skip to content

Commit 058f6fe

Browse files
committed
Merge remote-tracking branch 'origin/master' into deprecate-ambiguous-constructors
2 parents b856875 + e94e13e commit 058f6fe

File tree

19 files changed

+144
-51
lines changed

19 files changed

+144
-51
lines changed

.github/workflows/release-drafter.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ jobs:
99
update_release_draft:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: release-drafter/release-drafter@v5.2.0
12+
- uses: release-drafter/release-drafter@v5.9.0
1313
env:
1414
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

azure-pipelines.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
gradleWrapperFile: 'gradlew'
1515
jdkVersionOption: '1.11'
1616
options: "--no-daemon --continue"
17-
tasks: "testcontainers:test --tests GenericContainerRuleTest"
17+
tasks: "clean testcontainers:test --tests GenericContainerRuleTest"
1818
publishJUnitResults: true
1919
testResultsFiles: '**/TEST-*.xml'
2020
- script: wget -q https://get.cimate.io/release/linux/cimate && chmod +x cimate && ./cimate "**/TEST-*.xml"
@@ -31,6 +31,6 @@ jobs:
3131
gradleWrapperFile: 'gradlew'
3232
jdkVersionOption: '1.11'
3333
options: '--no-daemon --continue'
34-
tasks: 'check'
34+
tasks: 'clean check'
3535
publishJUnitResults: true
3636
testResultsFiles: '**/TEST-*.xml'

core/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ if (!org.gradle.internal.os.OperatingSystem.current().isWindows()) {
104104
}
105105

106106
dependencies {
107-
baseline 'org.testcontainers:testcontainers:1.14.2', {
107+
baseline 'org.testcontainers:testcontainers:1.14.3', {
108108
exclude group: "*", module: "*"
109109
}
110110

core/src/main/java/org/testcontainers/images/ParsedDockerfile.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
@Slf4j
2222
public class ParsedDockerfile {
2323

24-
private static final Pattern FROM_LINE_PATTERN = Pattern.compile("FROM ([^\\s]+).*");
24+
private static final Pattern FROM_LINE_PATTERN = Pattern.compile("FROM (?<arg>--[^\\s]+\\s)*(?<image>[^\\s]+).*", Pattern.CASE_INSENSITIVE);
2525

2626
private final Path dockerFilePath;
2727

@@ -57,7 +57,7 @@ private void parse(List<String> lines) {
5757
dependencyImageNames = lines.stream()
5858
.map(FROM_LINE_PATTERN::matcher)
5959
.filter(Matcher::matches)
60-
.map(matcher -> matcher.group(1))
60+
.map(matcher -> matcher.group("image"))
6161
.collect(Collectors.toSet());
6262

6363
if (!dependencyImageNames.isEmpty()) {

core/src/main/java/org/testcontainers/images/builder/ImageFromDockerfile.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ public void onNext(BuildResponseItem item) {
107107

108108
BuildImageCmd buildImageCmd = dockerClient.buildImageCmd(in);
109109
configure(buildImageCmd);
110+
Map<String, String> labels = new HashMap<>();
111+
if (buildImageCmd.getLabels() != null) {
112+
labels.putAll(buildImageCmd.getLabels());
113+
}
114+
labels.putAll(DockerClientFactory.DEFAULT_LABELS);
115+
buildImageCmd.withLabels(labels);
110116

111117
prePullDependencyImages(dependencyImageNames);
112118

core/src/main/java/org/testcontainers/utility/ResourceReaper.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package org.testcontainers.utility;
22

33
import com.github.dockerjava.api.DockerClient;
4+
import com.github.dockerjava.api.async.ResultCallback;
45
import com.github.dockerjava.api.command.InspectContainerResponse;
56
import com.github.dockerjava.api.exception.NotFoundException;
67
import com.github.dockerjava.api.model.Bind;
78
import com.github.dockerjava.api.model.ExposedPort;
9+
import com.github.dockerjava.api.model.Frame;
810
import com.github.dockerjava.api.model.HostConfig;
911
import com.github.dockerjava.api.model.Network;
1012
import com.github.dockerjava.api.model.Ports;
@@ -28,6 +30,7 @@
2830
import java.io.UnsupportedEncodingException;
2931
import java.net.Socket;
3032
import java.net.URLEncoder;
33+
import java.nio.charset.StandardCharsets;
3134
import java.util.AbstractMap.SimpleEntry;
3235
import java.util.ArrayList;
3336
import java.util.Collections;
@@ -93,6 +96,20 @@ public static String start(String hostIpAddress, DockerClient client) {
9396

9497
client.startContainerCmd(ryukContainerId).exec();
9598

99+
StringBuilder ryukLog = new StringBuilder();
100+
101+
client.logContainerCmd(ryukContainerId)
102+
.withSince(0)
103+
.withFollowStream(true)
104+
.withStdOut(true)
105+
.withStdErr(true)
106+
.exec(new ResultCallback.Adapter<Frame>() {
107+
@Override
108+
public void onNext(Frame frame) {
109+
ryukLog.append(new String(frame.getPayload(), StandardCharsets.UTF_8));
110+
}
111+
});
112+
96113
InspectContainerResponse inspectedContainer = client.inspectContainerCmd(ryukContainerId).exec();
97114

98115
Integer ryukPort = inspectedContainer.getNetworkSettings().getPorts().getBindings().values().stream()
@@ -155,7 +172,8 @@ public static String start(String hostIpAddress, DockerClient client) {
155172

156173
// We need to wait before we can start any containers to make sure that we delete them
157174
if (!ryukScheduledLatch.await(TestcontainersConfiguration.getInstance().getRyukTimeout(), TimeUnit.SECONDS)) {
158-
throw new IllegalStateException("Can not connect to Ryuk");
175+
log.error("Timeout out waiting for Ryuk. Ryuk's log:\n{}", ryukLog);
176+
throw new IllegalStateException(String.format("Can not connect to Ryuk at %s:%s", hostIpAddress, ryukPort));
159177
}
160178

161179
return ryukContainerId;

core/src/main/java/org/testcontainers/utility/TestcontainersConfiguration.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
package org.testcontainers.utility;
22

33
import com.google.common.annotations.VisibleForTesting;
4-
import lombok.*;
4+
import lombok.AccessLevel;
5+
import lombok.Data;
6+
import lombok.Getter;
7+
import lombok.NonNull;
8+
import lombok.RequiredArgsConstructor;
9+
import lombok.SneakyThrows;
10+
import lombok.Synchronized;
511
import lombok.extern.slf4j.Slf4j;
612
import org.testcontainers.UnstableAPI;
713

8-
import java.io.*;
14+
import java.io.File;
15+
import java.io.FileNotFoundException;
16+
import java.io.FileOutputStream;
17+
import java.io.IOException;
18+
import java.io.InputStream;
19+
import java.io.OutputStream;
920
import java.net.MalformedURLException;
1021
import java.net.URL;
1122
import java.util.Objects;
@@ -56,7 +67,7 @@ public String getSocatContainerImage() {
5667
}
5768

5869
public String getVncRecordedContainerImage() {
59-
return (String) properties.getOrDefault("vncrecorder.container.image", "quay.io/testcontainers/vnc-recorder:1.1.0");
70+
return (String) properties.getOrDefault("vncrecorder.container.image", "testcontainersofficial/vnc-recorder:1.1.0");
6071
}
6172

6273
public String getDockerComposeContainerImage() {
@@ -72,11 +83,11 @@ public boolean isRyukPrivileged() {
7283
}
7384

7485
public String getRyukImage() {
75-
return (String) properties.getOrDefault("ryuk.container.image", "quay.io/testcontainers/ryuk:0.2.3");
86+
return (String) properties.getOrDefault("ryuk.container.image", "testcontainersofficial/ryuk:0.3.0");
7687
}
7788

7889
public String getSSHdImage() {
79-
return (String) properties.getOrDefault("sshd.container.image", "quay.io/testcontainers/sshd:1.0.0");
90+
return (String) properties.getOrDefault("sshd.container.image", "testcontainersofficial/sshd:1.0.0");
8091
}
8192

8293
public Integer getRyukTimeout() {

core/src/test/java/org/testcontainers/images/ParsedDockerfileTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ public void doesSimpleParsing() {
1616
assertEquals("extracts a single image name", Sets.newHashSet("someimage"), parsedDockerfile.getDependencyImageNames());
1717
}
1818

19+
@Test
20+
public void isCaseInsensitive() {
21+
final ParsedDockerfile parsedDockerfile = new ParsedDockerfile(asList("from someimage", "RUN something"));
22+
assertEquals("extracts a single image name", Sets.newHashSet("someimage"), parsedDockerfile.getDependencyImageNames());
23+
}
24+
1925
@Test
2026
public void handlesTags() {
2127
final ParsedDockerfile parsedDockerfile = new ParsedDockerfile(asList("FROM someimage:tag", "RUN something"));
@@ -40,6 +46,18 @@ public void ignoringBuildStageNames() {
4046
assertEquals("ignores build stage names and allows multiple images to be extracted", Sets.newHashSet("someimage", "nextimage"), parsedDockerfile.getDependencyImageNames());
4147
}
4248

49+
@Test
50+
public void ignoringPlatformArgs() {
51+
final ParsedDockerfile parsedDockerfile = new ParsedDockerfile(asList("FROM --platform=linux/amd64 someimage", "RUN something"));
52+
assertEquals("ignores platform args", Sets.newHashSet("someimage"), parsedDockerfile.getDependencyImageNames());
53+
}
54+
55+
@Test
56+
public void ignoringExtraPlatformArgs() {
57+
final ParsedDockerfile parsedDockerfile = new ParsedDockerfile(asList("FROM --platform=linux/amd64 --somethingelse=value someimage", "RUN something"));
58+
assertEquals("ignores platform args", Sets.newHashSet("someimage"), parsedDockerfile.getDependencyImageNames());
59+
}
60+
4361
@Test
4462
public void handlesGracefullyIfNoFromLine() {
4563
final ParsedDockerfile parsedDockerfile = new ParsedDockerfile(asList("RUN something", "# is this even a valid Dockerfile?"));
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.testcontainers.images.builder;
2+
3+
import com.github.dockerjava.api.DockerClient;
4+
import com.github.dockerjava.api.command.InspectImageResponse;
5+
import org.junit.Test;
6+
import org.testcontainers.DockerClientFactory;
7+
8+
import static org.assertj.core.api.Assertions.assertThat;
9+
10+
public class ImageFromDockerfileTest {
11+
12+
@Test
13+
public void shouldAddDefaultLabels() {
14+
ImageFromDockerfile image = new ImageFromDockerfile()
15+
.withDockerfileFromBuilder(it -> it.from("scratch"));
16+
17+
String imageId = image.resolve();
18+
19+
DockerClient dockerClient = DockerClientFactory.instance().client();
20+
21+
InspectImageResponse inspectImageResponse = dockerClient.inspectImageCmd(imageId).exec();
22+
23+
assertThat(inspectImageResponse.getConfig().getLabels())
24+
.containsAllEntriesOf(DockerClientFactory.DEFAULT_LABELS);
25+
}
26+
27+
}

docs/features/configuration.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Some companies disallow the usage of Docker Hub, but you can override `*.image`
3232
> **tinyimage.container.image = alpine:3.5**
3333
> Used by Testcontainers' core
3434
35-
> **vncrecorder.container.image = quay.io/testcontainers/vnc-recorder:1.1.0**
35+
> **vncrecorder.container.image = testcontainersofficial/vnc-recorder:1.1.0**
3636
> Used by VNC recorder in Testcontainers' Seleniun integration
3737
3838
> **ambassador.container.image = richnorth/ambassador:latest**
@@ -49,13 +49,11 @@ Another possibility is to set up a registry mirror in your environment so that a
4949
For more information, see the [official Docker documentation about "Registry as a pull through cache"](https://docs.docker.com/registry/recipes/mirror/).
5050

5151
!!!tip
52-
Registry mirror currently only works for Docker images with image name that has no registry specified (for example, for Docker image `mariadb:10.3.6`, it works, for Docker image `quay.io/testcontainers/ryuk:0.2.3`, not).
53-
Workaround is to to configure the affected Docker image in `.testcontainers.properties`.
54-
For example: `ryuk.container.image = testcontainers/ryuk:0.2.3` or `ryuk.container.image = <your.docker.registry>/testcontainers/ryuk:0.2.3`
52+
Registry mirror currently only works for Docker images with image name that has no registry specified (for example, for Docker image `mariadb:10.3.6`, it works, for Docker image `quay.io/something/else`, not).
5553

5654
## Customizing Ryuk resource reaper
5755

58-
> **ryuk.container.image = quay.io/testcontainers/ryuk:0.2.3**
56+
> **ryuk.container.image = testcontainersofficial/ryuk:0.3.0**
5957
> The resource reaper is responsible for container removal and automatic cleanup of dead containers at JVM shutdown
6058
6159
> **ryuk.container.privileged = false**

docs/modules/databases/jdbc.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,5 @@ Note that if you use `@Rule`, you will be given an isolated container for each t
115115

116116
Examples/Tests:
117117

118-
* [MySQL](https://github.com/testcontainers/testcontainers-java/blob/master/modules/jdbc-test/src/test/java/org/testcontainers/junit/SimpleMySQLTest.java)
119-
* [PostgreSQL](https://github.com/testcontainers/testcontainers-java/blob/master/modules/jdbc-test/src/test/java/org/testcontainers/junit/SimplePostgreSQLTest.java)
118+
* [MySQL](https://github.com/testcontainers/testcontainers-java/blob/master/modules/mysql/src/test/java/org/testcontainers/junit/mysql/SimpleMySQLTest.java)
119+
* [PostgreSQL](https://github.com/testcontainers/testcontainers-java/blob/master/modules/postgresql/src/test/java/org/testcontainers/junit/postgresql/SimplePostgreSQLTest.java)

examples/solr-container/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ dependencies {
1010
compileOnly "org.projectlombok:lombok:1.18.10"
1111
annotationProcessor "org.projectlombok:lombok:1.18.10"
1212

13-
implementation 'org.apache.solr:solr-solrj:8.5.1'
13+
implementation 'org.apache.solr:solr-solrj:8.5.2'
1414

1515
testImplementation 'org.testcontainers:testcontainers'
1616
testImplementation 'org.testcontainers:solr'

mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,4 @@ nav:
9090
- contributing.md
9191
- contributing_docs.md
9292
extra:
93-
latest_version: 1.14.2
93+
latest_version: 1.14.3

0 commit comments

Comments
 (0)