-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDockerService.java
More file actions
68 lines (59 loc) · 1.87 KB
/
DockerService.java
File metadata and controls
68 lines (59 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package com.formkiq.gradle.services;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
/** Abstraction for Docker-related operations. */
public interface DockerService {
/**
* Checks whether the Docker daemon is accessible.
*
* @return true if Docker responds, false otherwise
*/
boolean isDockerRunning();
/**
* Generates (or overwrites) a Dockerfile on disk using specified parameters.
*
* @param buildDir {@link Path}
* @param imageTag {@link String}
* @param dockerFileContent Docker file content
* @param contextDir Docker Context dir
* @return Path
* @throws IOException IOException
*/
Path buildDockerImage(Path buildDir, String imageTag, String dockerFileContent, Path contextDir)
throws IOException;
/**
* Write Dockerfile Content to a {@link Path}.
*
* @param buildDir {@link Path}
* @param dockerFileContent {@link String}
* @return Path
* @throws IOException IOException
*/
default Path writeDockerFile(final Path buildDir, final String dockerFileContent)
throws IOException {
Path dir = buildDir.resolve("java/main");
Files.createDirectories(dir);
Path dockerfilePath = Path.of(dir.toString(), "Dockerfile");
Files.writeString(dockerfilePath, dockerFileContent, StandardCharsets.UTF_8);
return dockerfilePath;
}
/**
* Run Docker Image.
*
* @param buildDir {@link Path}
* @param outputImageTag {@link String}
* @throws IOException IOException
* @throws InterruptedException InterruptedException
*/
void runDockerImage(Path buildDir, String outputImageTag)
throws IOException, InterruptedException;
/**
* Remove Docker Image.
*
* @param imageTag {@link String}
* @throws IOException IOException
*/
void removeDockerImage(String imageTag) throws IOException;
}