-
Notifications
You must be signed in to change notification settings - Fork 1
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
---|---|---|
|
@@ -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(); | ||
} | ||
} |
This file contains hidden or 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 |
---|---|---|
|
@@ -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 contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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?