-
Notifications
You must be signed in to change notification settings - Fork 2
WIP Fixes and refactoring before release #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,15 +4,17 @@ | |
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; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.testcontainers.DockerClientFactory; | ||
|
||
import java.io.File; | ||
import java.net.URISyntaxException; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
/** | ||
* Class for working with docker directly | ||
|
@@ -21,21 +23,19 @@ | |
*/ | ||
class TarantoolContainerImageHelper { | ||
|
||
private static final DockerClient dockerClient = DockerClientBuilder.getInstance().build(); | ||
|
||
private TarantoolContainerImageHelper() { | ||
} | ||
|
||
/** | ||
* Checks image for existing by name and build if it not exist | ||
* Checks image for existing by name and build if it not exists | ||
* | ||
* @param imageParams parameters for building tarantool image | ||
* @return image name | ||
*/ | ||
static String getImage(TarantoolImageParams imageParams) { | ||
final String tag = imageParams.getTag(); | ||
|
||
if (StringUtils.isEmpty(tag)) { | ||
if (tag.isEmpty()) { | ||
throw new IllegalArgumentException("Image tag is null or empty!"); | ||
} | ||
|
||
|
@@ -52,7 +52,18 @@ static String getImage(TarantoolImageParams imageParams) { | |
* @param imageParams parameters for building tarantool image | ||
*/ | ||
private static void buildImage(TarantoolImageParams imageParams) { | ||
final BuildImageCmd buildImageCmd = dockerClient.buildImageCmd(imageParams.getDockerfile()); | ||
final File dockerfile; | ||
try { | ||
dockerfile = new File( | ||
Objects.requireNonNull(TarantoolContainerImageHelper.class.getClassLoader().getResource( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A message can be added here, otherwise it will be an unreadable stacktrace. |
||
imageParams.getDockerfile())).toURI() | ||
); | ||
} catch (URISyntaxException e) { | ||
throw new RuntimeException("Failed to build docker image from resource '" | ||
+ imageParams.getDockerfile() + "'", e); | ||
} | ||
|
||
final BuildImageCmd buildImageCmd = getDockerClient().buildImageCmd(dockerfile); | ||
|
||
final Map<String, String> buildArgs = imageParams.getBuildArgs(); | ||
for (Map.Entry<String, String> entry : buildArgs.entrySet()) { | ||
|
@@ -71,11 +82,15 @@ private static void buildImage(TarantoolImageParams imageParams) { | |
* @return true if image exist and false if not | ||
*/ | ||
private static boolean hasImage(String tag) { | ||
final List<Image> images = dockerClient.listImagesCmd().exec(); | ||
final List<Image> images = getDockerClient().listImagesCmd().exec(); | ||
return images.stream() | ||
.map(Image::getRepoTags) | ||
.map(Arrays::asList) | ||
.flatMap(Collection::stream) | ||
.anyMatch(repoTag -> repoTag.equals(tag)); | ||
} | ||
|
||
private static DockerClient getDockerClient() { | ||
return DockerClientFactory.instance().client(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,36 +12,36 @@ | |
public class TarantoolImageParams { | ||
|
||
private final String tag; | ||
private final File dockerfile; | ||
private final String dockerfile; | ||
private final Map<String, String> buildArgs; | ||
|
||
/** | ||
* Custom constructor for tarantool image parameters | ||
* | ||
* @param tag docker image tag | ||
* @param tag docker image tag. For example: "tarantool-enterprise-bundle:latest" | ||
* @param dockerfile dockerfile for building custom tarantool image | ||
*/ | ||
public TarantoolImageParams(String tag, File dockerfile) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rather leave both variants (String and File). Both are useful |
||
public TarantoolImageParams(String tag, String dockerfile) { | ||
this(tag, dockerfile, Collections.emptyMap()); | ||
} | ||
|
||
/** | ||
* Custom constructor for tarantool image parameters | ||
* | ||
* @param tag docker image tag | ||
* @param tag docker image tag. For example: "tarantool-enterprise-bundle:latest" | ||
* @param dockerfile dockerfile for building custom tarantool image | ||
* @param buildArgs args for building docker image | ||
*/ | ||
public TarantoolImageParams(String tag, File dockerfile, Map<String, String> buildArgs) { | ||
public TarantoolImageParams(String tag, String dockerfile, Map<String, String> buildArgs) { | ||
this.tag = tag; | ||
this.dockerfile = dockerfile; | ||
this.buildArgs = buildArgs; | ||
} | ||
|
||
/** | ||
* Getter for sdk version | ||
* Getter for docker image tag | ||
* | ||
* @return sdk version | ||
* @return docker image tag | ||
*/ | ||
public String getTag() { | ||
return tag; | ||
|
@@ -52,7 +52,7 @@ public String getTag() { | |
* | ||
* @return dockerfile | ||
*/ | ||
public File getDockerfile() { | ||
public String getDockerfile() { | ||
return dockerfile; | ||
} | ||
|
||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is tag really never null?