|
|
|
@ -22,6 +22,7 @@ import java.io.InputStream; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.Collections; |
|
|
|
|
|
|
|
import java.util.HashSet; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
import java.util.regex.Pattern; |
|
|
|
import java.util.regex.Pattern; |
|
|
|
@ -30,17 +31,19 @@ import javax.ws.rs.client.Entity; |
|
|
|
import javax.ws.rs.client.WebTarget; |
|
|
|
import javax.ws.rs.client.WebTarget; |
|
|
|
|
|
|
|
|
|
|
|
import com.github.dockerjava.api.DockerClient; |
|
|
|
import com.github.dockerjava.api.DockerClient; |
|
|
|
import com.github.dockerjava.api.DockerClientException; |
|
|
|
|
|
|
|
import com.github.dockerjava.api.command.DockerCmd; |
|
|
|
import com.github.dockerjava.api.command.DockerCmd; |
|
|
|
|
|
|
|
import com.github.dockerjava.api.exception.DockerClientException; |
|
|
|
import com.github.dockerjava.api.model.BuildResponseItem; |
|
|
|
import com.github.dockerjava.api.model.BuildResponseItem; |
|
|
|
import com.github.dockerjava.api.model.Frame; |
|
|
|
import com.github.dockerjava.api.model.Frame; |
|
|
|
import com.github.dockerjava.core.CompressArchiveUtil; |
|
|
|
import com.github.dockerjava.core.DefaultDockerClientConfig; |
|
|
|
import com.github.dockerjava.core.DockerClientBuilder; |
|
|
|
import com.github.dockerjava.core.DockerClientBuilder; |
|
|
|
import com.github.dockerjava.core.DockerClientConfig; |
|
|
|
import com.github.dockerjava.core.DockerClientConfig; |
|
|
|
import com.github.dockerjava.core.command.AttachContainerResultCallback; |
|
|
|
import com.github.dockerjava.core.command.AttachContainerResultCallback; |
|
|
|
import com.github.dockerjava.core.command.BuildImageResultCallback; |
|
|
|
import com.github.dockerjava.core.command.BuildImageResultCallback; |
|
|
|
|
|
|
|
import com.github.dockerjava.core.command.WaitContainerResultCallback; |
|
|
|
|
|
|
|
import com.github.dockerjava.core.util.CompressArchiveUtil; |
|
|
|
import com.github.dockerjava.jaxrs.AbstrSyncDockerCmdExec; |
|
|
|
import com.github.dockerjava.jaxrs.AbstrSyncDockerCmdExec; |
|
|
|
import com.github.dockerjava.jaxrs.DockerCmdExecFactoryImpl; |
|
|
|
import com.github.dockerjava.jaxrs.JerseyDockerCmdExecFactory; |
|
|
|
import org.assertj.core.api.Condition; |
|
|
|
import org.assertj.core.api.Condition; |
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.runner.RunWith; |
|
|
|
import org.junit.runner.RunWith; |
|
|
|
@ -253,8 +256,10 @@ public class SysVinitLaunchScriptIT { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
resultCallback.awaitCompletion(60, TimeUnit.SECONDS).close(); |
|
|
|
resultCallback.awaitCompletion(60, TimeUnit.SECONDS); |
|
|
|
docker.waitContainerCmd(container).exec(); |
|
|
|
WaitContainerResultCallback waitContainerCallback = new WaitContainerResultCallback(); |
|
|
|
|
|
|
|
docker.waitContainerCmd(container).exec(waitContainerCallback); |
|
|
|
|
|
|
|
waitContainerCallback.awaitCompletion(60, TimeUnit.SECONDS); |
|
|
|
return output.toString(); |
|
|
|
return output.toString(); |
|
|
|
} |
|
|
|
} |
|
|
|
finally { |
|
|
|
finally { |
|
|
|
@ -268,11 +273,10 @@ public class SysVinitLaunchScriptIT { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private DockerClient createClient() { |
|
|
|
private DockerClient createClient() { |
|
|
|
DockerClientConfig config = DockerClientConfig.createDefaultConfigBuilder() |
|
|
|
DockerClientConfig config = DefaultDockerClientConfig.createDefaultConfigBuilder() |
|
|
|
.withVersion("1.19").build(); |
|
|
|
.withApiVersion("1.19").build(); |
|
|
|
DockerClient docker = DockerClientBuilder.getInstance(config) |
|
|
|
return DockerClientBuilder.getInstance(config) |
|
|
|
.withDockerCmdExecFactory(this.commandExecFactory).build(); |
|
|
|
.withDockerCmdExecFactory(this.commandExecFactory).build(); |
|
|
|
return docker; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private String buildImage(DockerClient docker) { |
|
|
|
private String buildImage(DockerClient docker) { |
|
|
|
@ -328,7 +332,8 @@ public class SysVinitLaunchScriptIT { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
docker.buildImageCmd(new File(dockerfile)).withTag(tag).exec(resultCallback); |
|
|
|
docker.buildImageCmd(new File(dockerfile)) |
|
|
|
|
|
|
|
.withTags(new HashSet<>(Arrays.asList(tag))).exec(resultCallback); |
|
|
|
String imageId = resultCallback.awaitImageId(); |
|
|
|
String imageId = resultCallback.awaitImageId(); |
|
|
|
return imageId; |
|
|
|
return imageId; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -403,8 +408,8 @@ public class SysVinitLaunchScriptIT { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected Void execute(CopyToContainerCmd command) { |
|
|
|
protected Void execute(CopyToContainerCmd command) { |
|
|
|
try (InputStream streamToUpload = new FileInputStream(CompressArchiveUtil |
|
|
|
try (InputStream streamToUpload = new FileInputStream( |
|
|
|
.archiveTARFiles(command.getFile().getParentFile(), |
|
|
|
CompressArchiveUtil.archiveTARFiles(command.getFile().getParentFile(), |
|
|
|
Arrays.asList(command.getFile()), |
|
|
|
Arrays.asList(command.getFile()), |
|
|
|
command.getFile().getName()))) { |
|
|
|
command.getFile().getName()))) { |
|
|
|
WebTarget webResource = getBaseResource().path("/containers/{id}/archive") |
|
|
|
WebTarget webResource = getBaseResource().path("/containers/{id}/archive") |
|
|
|
@ -448,13 +453,7 @@ public class SysVinitLaunchScriptIT { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static final class SpringBootDockerCmdExecFactory |
|
|
|
private static final class SpringBootDockerCmdExecFactory |
|
|
|
extends DockerCmdExecFactoryImpl { |
|
|
|
extends JerseyDockerCmdExecFactory { |
|
|
|
|
|
|
|
|
|
|
|
private SpringBootDockerCmdExecFactory() { |
|
|
|
|
|
|
|
withClientRequestFilters((requestContext) -> |
|
|
|
|
|
|
|
// Workaround for https://go-review.googlesource.com/#/c/3821/
|
|
|
|
|
|
|
|
requestContext.getHeaders().add("Connection", "close")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private CopyToContainerCmdExec createCopyToContainerCmdExec() { |
|
|
|
private CopyToContainerCmdExec createCopyToContainerCmdExec() { |
|
|
|
return new CopyToContainerCmdExec(getBaseResource(), getDockerClientConfig()); |
|
|
|
return new CopyToContainerCmdExec(getBaseResource(), getDockerClientConfig()); |
|
|
|
|