Skip to content

Commit cd55509

Browse files
authored
Added enterprise test profile and changed TarantoolImageParams logic (#44)
* Added enterprise test profile and changed TarantoolImageParams logic
1 parent fdc41bd commit cd55509

File tree

7 files changed

+84
-91
lines changed

7 files changed

+84
-91
lines changed

.github/workflows/ubuntu-master.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,11 @@ jobs:
3030
env:
3131
TARANTOOL_SERVER_USER: root
3232
TARANTOOL_SERVER_GROUP: root
33-
URI: ${{ secrets.URI }}
3433
run: mvn -B verify --file pom.xml
34+
35+
- name: Run enterprise tests
36+
env:
37+
TARANTOOL_SERVER_USER: root
38+
TARANTOOL_SERVER_GROUP: root
39+
DOWNLOAD_SDK_URI: ${{ secrets.DOWNLOAD_SDK_URI }}
40+
run: mvn -B test -P enterprise --file pom.xml

pom.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,28 @@
185185
</build>
186186

187187
<profiles>
188+
<profile>
189+
<id>enterprise</id>
190+
<build>
191+
<plugins>
192+
<plugin>
193+
<groupId>org.apache.maven.plugins</groupId>
194+
<artifactId>maven-surefire-plugin</artifactId>
195+
<version>3.0.0-M5</version>
196+
<configuration>
197+
<includes>
198+
<include>**/*TestEnterprise.java</include>
199+
</includes>
200+
<systemPropertyVariables>
201+
<logback.configurationFile>${logging.config}</logback.configurationFile>
202+
<logLevel>${logging.logLevel}</logLevel>
203+
</systemPropertyVariables>
204+
<trimStackTrace>false</trimStackTrace>
205+
</configuration>
206+
</plugin>
207+
</plugins>
208+
</build>
209+
</profile>
188210
<profile>
189211
<id>release</id>
190212
<build>

src/main/java/org/testcontainers/containers/TarantoolContainerImageHelper.java

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

33
import com.github.dockerjava.api.DockerClient;
4+
import com.github.dockerjava.api.command.BuildImageCmd;
45
import com.github.dockerjava.api.command.BuildImageResultCallback;
56
import com.github.dockerjava.api.model.Image;
67
import com.github.dockerjava.core.DockerClientBuilder;
@@ -11,6 +12,7 @@
1112
import java.util.Collections;
1213
import java.util.HashSet;
1314
import java.util.List;
15+
import java.util.Map;
1416

1517
/**
1618
* Class for working with docker directly
@@ -31,17 +33,17 @@ private TarantoolContainerImageHelper() {
3133
* @return image name
3234
*/
3335
static String getImage(TarantoolImageParams imageParams) {
34-
final String sdkVersion = imageParams.getSdkVersion();
36+
final String tag = imageParams.getTag();
3537

36-
if (StringUtils.isEmpty(sdkVersion)) {
37-
throw new IllegalArgumentException("SDK version is null or empty!");
38+
if (StringUtils.isEmpty(tag)) {
39+
throw new IllegalArgumentException("Image tag is null or empty!");
3840
}
3941

40-
if (!hasImage(sdkVersion)) {
42+
if (!hasImage(tag)) {
4143
buildImage(imageParams);
4244
}
4345

44-
return sdkVersion;
46+
return tag;
4547
}
4648

4749
/**
@@ -50,33 +52,30 @@ static String getImage(TarantoolImageParams imageParams) {
5052
* @param imageParams parameters for building tarantool image
5153
*/
5254
private static void buildImage(TarantoolImageParams imageParams) {
53-
final String sdkVersion = imageParams.getSdkVersion();
54-
final String uri = System.getenv("URI");
55+
final BuildImageCmd buildImageCmd = dockerClient.buildImageCmd(imageParams.getDockerfile());
5556

56-
if (StringUtils.isEmpty(uri)) {
57-
throw new IllegalStateException("URI environment variable must be specified!");
57+
final Map<String, String> buildArgs = imageParams.getBuildArgs();
58+
for (Map.Entry<String, String> entry : buildArgs.entrySet()) {
59+
buildImageCmd.withBuildArg(entry.getKey(), entry.getValue());
5860
}
5961

60-
dockerClient.buildImageCmd(imageParams.getDockerfile())
61-
.withTags(new HashSet<>(Collections.singletonList(sdkVersion)))
62-
.withBuildArg("SDK_VERSION", sdkVersion)
63-
.withBuildArg("URI", uri)
62+
buildImageCmd.withTags(new HashSet<>(Collections.singletonList(imageParams.getTag())))
6463
.exec(new BuildImageResultCallback())
6564
.awaitImageId();
6665
}
6766

6867
/**
6968
* Checks image for existing by name
7069
*
71-
* @param imageName image name for searching
70+
* @param tag image tag for searching
7271
* @return true if image exist and false if not
7372
*/
74-
private static boolean hasImage(String imageName) {
73+
private static boolean hasImage(String tag) {
7574
final List<Image> images = dockerClient.listImagesCmd().exec();
7675
return images.stream()
7776
.map(Image::getRepoTags)
7877
.map(Arrays::asList)
7978
.flatMap(Collection::stream)
80-
.anyMatch(tag -> tag.equals(imageName + ":latest"));
79+
.anyMatch(repoTag -> repoTag.equals(tag));
8180
}
8281
}
Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package org.testcontainers.containers;
22

33
import java.io.File;
4-
import java.net.URISyntaxException;
4+
import java.util.Collections;
5+
import java.util.Map;
56

67
/**
78
* Tarantool image parameters holder
@@ -10,44 +11,40 @@
1011
*/
1112
public class TarantoolImageParams {
1213

13-
private final String sdkVersion;
14+
private final String tag;
1415
private final File dockerfile;
16+
private final Map<String, String> buildArgs;
1517

1618
/**
17-
* Basic constructor for tarantool image parameters
19+
* Custom constructor for tarantool image parameters
1820
*
19-
* @param sdkVersion version of tarantool sdk which will be downloaded from specified in env variables URI,
20-
* for example: tarantool-enterprise-bundle-2.8.3-21-g7d35cd2be-r470
21+
* @param tag docker image tag
22+
* @param dockerfile dockerfile for building custom tarantool image
2123
*/
22-
public TarantoolImageParams(String sdkVersion) {
23-
this.sdkVersion = sdkVersion;
24-
try {
25-
this.dockerfile = new File(TarantoolImageParams.class.getClassLoader()
26-
.getResource("sdk/Dockerfile").toURI());
27-
} catch (URISyntaxException e) {
28-
throw new IllegalStateException("Can't access to Dockerfile for testcontainers");
29-
}
24+
public TarantoolImageParams(String tag, File dockerfile) {
25+
this(tag, dockerfile, Collections.emptyMap());
3026
}
3127

3228
/**
3329
* Custom constructor for tarantool image parameters
3430
*
35-
* @param sdkVersion version of tarantool sdk which will be downloaded from specified in env variables URI,
36-
* for example: tarantool-enterprise-bundle-2.8.3-21-g7d35cd2be-r470
31+
* @param tag docker image tag
3732
* @param dockerfile dockerfile for building custom tarantool image
33+
* @param buildArgs args for building docker image
3834
*/
39-
public TarantoolImageParams(String sdkVersion, File dockerfile) {
40-
this.sdkVersion = sdkVersion;
35+
public TarantoolImageParams(String tag, File dockerfile, Map<String, String> buildArgs) {
36+
this.tag = tag;
4137
this.dockerfile = dockerfile;
38+
this.buildArgs = buildArgs;
4239
}
4340

4441
/**
4542
* Getter for sdk version
4643
*
4744
* @return sdk version
4845
*/
49-
public String getSdkVersion() {
50-
return sdkVersion;
46+
public String getTag() {
47+
return tag;
5148
}
5249

5350
/**
@@ -58,4 +55,13 @@ public String getSdkVersion() {
5855
public File getDockerfile() {
5956
return dockerfile;
6057
}
58+
59+
/**
60+
* Getter for buildArgs
61+
*
62+
* @return dockerfile
63+
*/
64+
Map<String, String> getBuildArgs() {
65+
return buildArgs;
66+
}
6167
}

src/main/resources/sdk/Dockerfile

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/test/java/org/testcontainers/containers/TarantoolSdkContainerTest.java renamed to src/test/java/org/testcontainers/containers/TarantoolSdkContainerTestEnterprise.java

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,42 +11,26 @@
1111

1212
import java.io.File;
1313
import java.net.URISyntaxException;
14+
import java.util.HashMap;
1415
import java.util.List;
16+
import java.util.Map;
1517

1618
/**
1719
* @author Oleg Kuznetsov
1820
*/
19-
public class TarantoolSdkContainerTest {
21+
public class TarantoolSdkContainerTestEnterprise {
2022

2123
@Test
22-
void test_should_createTarantoolContainerFromSdk() {
23-
try (final TarantoolContainer tarantoolContainer = new TarantoolContainer(
24-
new TarantoolImageParams("tarantool-enterprise-bundle-2.8.3-21-g7d35cd2be-r470")
25-
)) {
26-
tarantoolContainer.start();
27-
28-
final TarantoolClient<TarantoolTuple, TarantoolResult<TarantoolTuple>> client =
29-
TarantoolClientFactory.createClient()
30-
.withCredentials("api_user", "secret")
31-
.withAddress(tarantoolContainer.getHost(), tarantoolContainer.getMappedPort(3301))
32-
.build();
33-
34-
final List<?> result = client.eval("return 'test'").join();
35-
final TarantoolVersion version = client.getVersion();
36-
37-
Assertions.assertEquals("test", result.get(0));
38-
Assertions.assertTrue(version.toString().startsWith("Tarantool 2.8.3 (Binary)"));
39-
}
40-
}
41-
42-
@Test
43-
void test_should_createTarantoolContainerFromSdk_ifDockerfileSpecified() throws URISyntaxException {
24+
void test_should_createTarantoolContainerFromSdk() throws URISyntaxException {
4425
final File dockerfile = new File(
45-
TarantoolSdkContainerTest.class.getClassLoader().getResource("testsdk/Dockerfile").toURI()
26+
TarantoolSdkContainerTestEnterprise.class.getClassLoader().getResource("testsdk/Dockerfile").toURI()
4627
);
28+
final Map<String, String> buildArgs = new HashMap<>();
29+
buildArgs.put("DOWNLOAD_SDK_URI", System.getenv("DOWNLOAD_SDK_URI"));
30+
buildArgs.put("SDK_VERSION", "tarantool-enterprise-bundle-2.7.3-0-gdddf926c3-r443");
4731

4832
try (final TarantoolContainer tarantoolContainer = new TarantoolContainer(
49-
new TarantoolImageParams("testsdk", dockerfile))
33+
new TarantoolImageParams("tarantool-enterprise-bundle:latest", dockerfile, buildArgs))
5034
.withDirectoryBinding("testsdk")) {
5135

5236
tarantoolContainer.start();

src/test/resources/testsdk/Dockerfile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,20 @@ ARG TARANTOOL_WORKDIR="/app"
44
ARG TARANTOOL_RUNDIR="/tmp/run"
55
ARG TARANTOOL_DATADIR="/tmp/data"
66
ARG SDK_TGT_DIR="/sdk"
7-
ARG URI=""
8-
ARG SDK_TGZ="tarantool-enterprise-bundle-2.7.3-0-gdddf926c3-r443.tar.gz"
7+
ARG DOWNLOAD_SDK_URI=""
8+
ARG SDK_VERSION=""
9+
ARG SDK_TGZ=$SDK_VERSION.tar.gz
910

10-
ENV URI=$URI
11-
ENV SDK_VERSION="tarantool-enterprise-bundle-2.7.3-0-gdddf926c3-r443"
11+
ENV DOWNLOAD_SDK_URI=$DOWNLOAD_SDK_URI
12+
ENV SDK_VERSION=$SDK_VERSION
1213
ENV SDK_TGT_DIR=$SDK_TGT_DIR
1314
ENV TARANTOOL_WORKDIR=$TARANTOOL_WORKDIR
1415
ENV TARANTOOL_RUNDIR=$TARANTOOL_RUNDIR
1516
ENV TARANTOOL_DATADIR=$TARANTOOL_DATADIR
1617

1718
RUN curl https://curl.se/ca/cacert.pem -o /etc/pki/tls/certs/ca-bundle.crt && \
1819
yum -y install wget && \
19-
wget $URI/$SDK_TGZ && \
20+
wget $DOWNLOAD_SDK_URI/$SDK_TGZ && \
2021
mkdir ./tmp_sdk && tar -xf $SDK_TGZ -C ./tmp_sdk && \
2122
mv ./tmp_sdk/tarantool-enterprise $SDK_TGT_DIR && rm $SDK_TGZ && \
2223
cp $SDK_TGT_DIR/tarantool /usr/bin/tarantool

0 commit comments

Comments
 (0)