Skip to content

Commit 9278066

Browse files
author
xianyanYang
committed
版本升级至1.1.0-SNAPSHOT;
docker-java.version版本升级至3.1.0-rc-3;
1 parent ccdc3ec commit 9278066

File tree

6 files changed

+89
-14
lines changed

6 files changed

+89
-14
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.docker.infrastructure.service;
2+
3+
import com.docker.service.DockerImageOperations;
4+
import org.springframework.stereotype.Service;
5+
6+
@Service("dockerClient.dockerImageOperations")
7+
public class InternalDockerImageOperations implements DockerImageOperations {
8+
9+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.docker.service;
2+
3+
public interface DockerImageOperations {
4+
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
DOCKER_HOST=tcp://xx.xx.xx.xx:2375
1+
DOCKER_HOST=tcp://106.14.196.164:2375
22
DOCKER_TLS_VERIFY=0
33
DOCKER_CONFIG=/home/user/.docker
44
api.version=1.23
5-
registry.url=http://xx.xx.xx.xx:9005/v2/
6-
registry.username=
7-
registry.password=
5+
registry.url=http://106.14.196.164:8888/v2/
6+
registry.username=admin
7+
registry.password=Harbor12345
88
registry.email=

src/test/java/com/docker/service/DockerClientOperationsTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,4 +478,5 @@ private DockerCreateContainerCmd createContainer2(String dbContainerName) {
478478

479479
}
480480

481+
481482
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.docker.service;
2+
3+
import com.docker.BaseTestCase;
4+
import org.springframework.beans.factory.annotation.Autowired;
5+
6+
public class DockerImageOperationsTest extends BaseTestCase {
7+
8+
@Autowired
9+
private DockerImageOperations dockerImageOperations;
10+
}

src/test/java/com/docker/service/DockerJavaTest.java

Lines changed: 61 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,31 @@
22

33
import com.docker.BaseTestCase;
44
import com.github.dockerjava.api.DockerClient;
5+
import com.github.dockerjava.api.command.BuildImageCmd;
56
import com.github.dockerjava.api.command.CreateContainerResponse;
67
import com.github.dockerjava.api.command.ExecCreateCmdResponse;
78
import com.github.dockerjava.api.exception.DockerClientException;
89
import com.github.dockerjava.api.exception.DockerException;
910
import com.github.dockerjava.api.exception.NotFoundException;
1011
import com.github.dockerjava.api.model.*;
1112
import com.github.dockerjava.core.RemoteApiVersion;
12-
import com.github.dockerjava.core.command.BuildImageResultCallback;
13-
import com.github.dockerjava.core.command.EventsResultCallback;
14-
import com.github.dockerjava.core.command.PullImageResultCallback;
13+
import com.github.dockerjava.core.command.*;
14+
import com.github.dockerjava.core.util.CompressArchiveUtil;
15+
import org.apache.commons.io.FileUtils;
16+
import org.apache.commons.io.filefilter.TrueFileFilter;
1517
import org.junit.Test;
1618
import org.springframework.beans.factory.annotation.Autowired;
1719

18-
import java.io.File;
19-
import java.io.IOException;
20+
import java.io.*;
2021
import java.security.SecureRandom;
22+
import java.util.Arrays;
23+
import java.util.Collection;
24+
import java.util.HashSet;
25+
import java.util.UUID;
2126
import java.util.concurrent.TimeUnit;
2227

2328
import static org.hamcrest.MatcherAssert.assertThat;
29+
import static org.hamcrest.Matchers.containsString;
2430
import static org.hamcrest.Matchers.isEmptyString;
2531
import static org.hamcrest.Matchers.not;
2632

@@ -276,8 +282,6 @@ public void createContainerWithLinkInCustomNetwork1() throws DockerException {
276282
}
277283

278284

279-
280-
281285
@Test
282286
public void createweb() throws DockerException {
283287
ExposedPort tcp8080 = ExposedPort.tcp(8080);
@@ -303,10 +307,57 @@ public void createweb() throws DockerException {
303307
}
304308

305309

310+
private String filePath = "C:\\Users\\sofia\\Desktop\\文档清单\\ecm_cloud\\application\\dockerfile";
311+
312+
private String imageName = "106.14.196.164:8888/test/ecm_cloud-test:v2.0.0";
313+
/*
314+
* docker build -t $name:$tag -f /home/docker/deploy/edc/application/dockerfile/Dockerfile /home/docker/deploy/edc/application/dockerfile;
315+
* */
316+
306317
@Test
307-
public void execCreateTest() {
318+
public void 制作镜像_1() {
319+
File baseDir = new File(filePath);
320+
Collection<File> files = FileUtils.listFiles(baseDir, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
321+
try {
322+
File tarFile = CompressArchiveUtil.archiveTARFiles(baseDir, files, UUID.randomUUID().toString());
323+
dockerfileBuild(new FileInputStream(tarFile));
324+
} catch (IOException e) {
325+
e.printStackTrace();
326+
}
327+
}
328+
329+
private void dockerfileBuild(InputStream tarInputStream, String dockerFilePath) {
330+
BuildImageCmd buildImageCmd = dockerClient.buildImageCmd()
331+
.withTags(new HashSet<String>(Arrays.asList(imageName)))
332+
.withTarInputStream(tarInputStream)
333+
.withDockerfilePath(dockerFilePath);
334+
execBuild(buildImageCmd);
335+
}
336+
337+
private void dockerfileBuild(InputStream tarInputStream) {
338+
BuildImageCmd buildImageCmd = dockerClient.buildImageCmd()
339+
.withTags(new HashSet<String>(Arrays.asList(imageName)))
340+
.withTarInputStream(tarInputStream);
341+
execBuild(buildImageCmd);
342+
}
343+
344+
private void dockerfileBuild(File baseDir) {
345+
BuildImageCmd buildImageCmd = dockerClient.buildImageCmd(baseDir)
346+
.withTags(new HashSet<String>(Arrays.asList(imageName)));
347+
execBuild(buildImageCmd);
348+
}
349+
350+
private void execBuild(BuildImageCmd buildImageCmd) {
351+
String imageId = buildImageCmd.withNoCache(true).exec(new BuildImageResultCallback()).awaitImageId();
352+
353+
/* try {
354+
dockerClient.pushImageCmd(imageName)
355+
.withAuthConfig(dockerClient.authConfig())
356+
.exec(new PushImageResultCallback())
357+
.awaitCompletion(30, TimeUnit.SECONDS);
358+
} catch (InterruptedException e) {
359+
e.printStackTrace();
360+
}*/
308361

309-
ExecCreateCmdResponse execCreateCmdResponse = dockerClient.execCreateCmd("3139c430c28d")
310-
.withCmd("touch","/etc/nginx/conf.d/1.txt").exec();
311362
}
312363
}

0 commit comments

Comments
 (0)