Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/ubuntu-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,11 @@ jobs:
env:
TARANTOOL_SERVER_USER: root
TARANTOOL_SERVER_GROUP: root
URI: ${{ secrets.URI }}
run: mvn -B verify --file pom.xml

- name: Run enterprise tests
env:
TARANTOOL_SERVER_USER: root
TARANTOOL_SERVER_GROUP: root
DOWNLOAD_SDK_URI: ${{ secrets.DOWNLOAD_SDK_URI }}
run: mvn -B test -P enterprise --file pom.xml
22 changes: 22 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,28 @@
</build>

<profiles>
<profile>
<id>enterprise</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<includes>
<include>**/*TestEnterprise.java</include>
</includes>
<systemPropertyVariables>
<logback.configurationFile>${logging.config}</logback.configurationFile>
<logLevel>${logging.logLevel}</logLevel>
</systemPropertyVariables>
<trimStackTrace>false</trimStackTrace>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>release</id>
<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.testcontainers.containers;

import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.api.command.BuildImageCmd;
import com.github.dockerjava.api.command.BuildImageResultCallback;
import com.github.dockerjava.api.model.Image;
import com.github.dockerjava.core.DockerClientBuilder;
Expand All @@ -11,6 +12,7 @@
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

/**
* Class for working with docker directly
Expand All @@ -31,17 +33,17 @@ private TarantoolContainerImageHelper() {
* @return image name
*/
static String getImage(TarantoolImageParams imageParams) {
final String sdkVersion = imageParams.getSdkVersion();
final String tag = imageParams.getTag();

if (StringUtils.isEmpty(sdkVersion)) {
throw new IllegalArgumentException("SDK version is null or empty!");
if (StringUtils.isEmpty(tag)) {
throw new IllegalArgumentException("Image tag is null or empty!");
}

if (!hasImage(sdkVersion)) {
if (!hasImage(tag)) {
buildImage(imageParams);
}

return sdkVersion;
return tag;
}

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

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

dockerClient.buildImageCmd(imageParams.getDockerfile())
.withTags(new HashSet<>(Collections.singletonList(sdkVersion)))
.withBuildArg("SDK_VERSION", sdkVersion)
.withBuildArg("URI", uri)
buildImageCmd.withTags(new HashSet<>(Collections.singletonList(imageParams.getTag())))
.exec(new BuildImageResultCallback())
.awaitImageId();
}

/**
* Checks image for existing by name
*
* @param imageName image name for searching
* @param tag image tag for searching
* @return true if image exist and false if not
*/
private static boolean hasImage(String imageName) {
private static boolean hasImage(String tag) {
final List<Image> images = dockerClient.listImagesCmd().exec();
return images.stream()
.map(Image::getRepoTags)
.map(Arrays::asList)
.flatMap(Collection::stream)
.anyMatch(tag -> tag.equals(imageName + ":latest"));
.anyMatch(repoTag -> repoTag.equals(tag));
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.testcontainers.containers;

import java.io.File;
import java.net.URISyntaxException;
import java.util.Collections;
import java.util.Map;

/**
* Tarantool image parameters holder
Expand All @@ -10,44 +11,40 @@
*/
public class TarantoolImageParams {

private final String sdkVersion;
private final String tag;
private final File dockerfile;
private final Map<String, String> buildArgs;

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

/**
* Custom constructor for tarantool image parameters
*
* @param sdkVersion version of tarantool sdk which will be downloaded from specified in env variables URI,
* for example: tarantool-enterprise-bundle-2.8.3-21-g7d35cd2be-r470
* @param tag docker image tag
* @param dockerfile dockerfile for building custom tarantool image
* @param buildArgs args for building docker image
*/
public TarantoolImageParams(String sdkVersion, File dockerfile) {
this.sdkVersion = sdkVersion;
public TarantoolImageParams(String tag, File dockerfile, Map<String, String> buildArgs) {
this.tag = tag;
this.dockerfile = dockerfile;
this.buildArgs = buildArgs;
}

/**
* Getter for sdk version
*
* @return sdk version
*/
public String getSdkVersion() {
return sdkVersion;
public String getTag() {
return tag;
}

/**
Expand All @@ -58,4 +55,13 @@ public String getSdkVersion() {
public File getDockerfile() {
return dockerfile;
}

/**
* Getter for buildArgs
*
* @return dockerfile
*/
Map<String, String> getBuildArgs() {
return buildArgs;
}
}
25 changes: 0 additions & 25 deletions src/main/resources/sdk/Dockerfile

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,26 @@

import java.io.File;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @author Oleg Kuznetsov
*/
public class TarantoolSdkContainerTest {
public class TarantoolSdkContainerTestEnterprise {

@Test
void test_should_createTarantoolContainerFromSdk() {
try (final TarantoolContainer tarantoolContainer = new TarantoolContainer(
new TarantoolImageParams("tarantool-enterprise-bundle-2.8.3-21-g7d35cd2be-r470")
)) {
tarantoolContainer.start();

final TarantoolClient<TarantoolTuple, TarantoolResult<TarantoolTuple>> client =
TarantoolClientFactory.createClient()
.withCredentials("api_user", "secret")
.withAddress(tarantoolContainer.getHost(), tarantoolContainer.getMappedPort(3301))
.build();

final List<?> result = client.eval("return 'test'").join();
final TarantoolVersion version = client.getVersion();

Assertions.assertEquals("test", result.get(0));
Assertions.assertTrue(version.toString().startsWith("Tarantool 2.8.3 (Binary)"));
}
}

@Test
void test_should_createTarantoolContainerFromSdk_ifDockerfileSpecified() throws URISyntaxException {
void test_should_createTarantoolContainerFromSdk() throws URISyntaxException {
final File dockerfile = new File(
TarantoolSdkContainerTest.class.getClassLoader().getResource("testsdk/Dockerfile").toURI()
TarantoolSdkContainerTestEnterprise.class.getClassLoader().getResource("testsdk/Dockerfile").toURI()
);
final Map<String, String> buildArgs = new HashMap<>();
buildArgs.put("DOWNLOAD_SDK_URI", System.getenv("DOWNLOAD_SDK_URI"));
buildArgs.put("SDK_VERSION", "tarantool-enterprise-bundle-2.7.3-0-gdddf926c3-r443");

try (final TarantoolContainer tarantoolContainer = new TarantoolContainer(
new TarantoolImageParams("testsdk", dockerfile))
new TarantoolImageParams("tarantool-enterprise-bundle:latest", dockerfile, buildArgs))
.withDirectoryBinding("testsdk")) {

tarantoolContainer.start();
Expand Down
11 changes: 6 additions & 5 deletions src/test/resources/testsdk/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@ ARG TARANTOOL_WORKDIR="/app"
ARG TARANTOOL_RUNDIR="/tmp/run"
ARG TARANTOOL_DATADIR="/tmp/data"
ARG SDK_TGT_DIR="/sdk"
ARG URI=""
ARG SDK_TGZ="tarantool-enterprise-bundle-2.7.3-0-gdddf926c3-r443.tar.gz"
ARG DOWNLOAD_SDK_URI=""
ARG SDK_VERSION=""
ARG SDK_TGZ=$SDK_VERSION.tar.gz

ENV URI=$URI
ENV SDK_VERSION="tarantool-enterprise-bundle-2.7.3-0-gdddf926c3-r443"
ENV DOWNLOAD_SDK_URI=$DOWNLOAD_SDK_URI
ENV SDK_VERSION=$SDK_VERSION
ENV SDK_TGT_DIR=$SDK_TGT_DIR
ENV TARANTOOL_WORKDIR=$TARANTOOL_WORKDIR
ENV TARANTOOL_RUNDIR=$TARANTOOL_RUNDIR
ENV TARANTOOL_DATADIR=$TARANTOOL_DATADIR

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