Skip to content

Commit 7333b15

Browse files
committed
Fixing GitHub build
1 parent 3772331 commit 7333b15

File tree

9 files changed

+83
-76
lines changed

9 files changed

+83
-76
lines changed

docker/src/main/java/com/github/cowwoc/anchor4j/docker/internal/resource/ConfigParser.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
*/
2626
public final class ConfigParser extends AbstractParser
2727
{
28-
private static final Pattern NOT_FOUND = Pattern.compile("Error response from daemon: " +
29-
"config [^ ]+ not found");
30-
private static final Pattern NAME_IN_USE = Pattern.compile("Error response from daemon: " +
31-
"rpc error: code = AlreadyExists desc = config ([^ ]+) already exists");
28+
private static final Pattern NOT_FOUND = Pattern.compile(
29+
"Error response from daemon: config [^ ]+ not found");
30+
private static final Pattern NAME_IN_USE = Pattern.compile(
31+
"Error response from daemon: rpc error: code = AlreadyExists desc = config ([^ ]+) already exists");
3232

3333
/**
3434
* Creates a parser.

docker/src/main/java/com/github/cowwoc/anchor4j/docker/internal/resource/ContainerParser.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@
3535
*/
3636
public final class ContainerParser extends AbstractParser
3737
{
38-
private static final Pattern CONTAINER_NOT_FOUND = Pattern.compile("^Error response from daemon: " +
39-
"No such container: ([^ ]+).*", DOTALL);
38+
private static final Pattern CONTAINER_NOT_FOUND = Pattern.compile(
39+
"^Error response from daemon: No such container: ([^ ]+).*", DOTALL);
4040
private static final Pattern IMAGE_NOT_FOUND = Pattern.compile("^Unable to find image '([^']+)' locally.*",
4141
DOTALL);
42-
private static final Pattern CONTAINER_IN_USE = Pattern.compile("Error response from daemon: cannot " +
43-
"remove container \"([^\"]+)\": container is running: stop the container before removing or force " +
44-
"remove");
45-
private static final Pattern CONFLICTING_NAME = Pattern.compile("Error response from daemon: " +
46-
"Conflict\\. The container name \"([^\"]+)\" is already in use by container \"([^\"]+)\"\\. You have " +
47-
"to remove \\(or rename\\) that container to be able to reuse that name\\.");
42+
private static final Pattern CONTAINER_IN_USE = Pattern.compile("""
43+
Error response from daemon: cannot remove container "([^"]+)": container is running: stop the \
44+
container before removing or force remove""");
45+
private static final Pattern CONFLICTING_NAME = Pattern.compile("""
46+
Error response from daemon: Conflict\\. The container name "([^"]+)" is already in use by container \
47+
"([^"]+)"\\. You have to remove \\(or rename\\) that container to be able to reuse that name\\.""");
4848

4949
/**
5050
* Creates a parser.

docker/src/main/java/com/github/cowwoc/anchor4j/docker/internal/resource/ContextParser.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,19 @@
2323
*/
2424
public class ContextParser extends AbstractParser
2525
{
26-
private static final Pattern CONTEXT_NOT_FOUND = Pattern.compile("context \"([^\"]+)\" does not exist");
27-
private static final Pattern CONFLICTING_NAME = Pattern.compile("context \"([^\"]+)\" already exists");
28-
private static final Pattern REMOVE_FAILED_RESOURCE_IN_USE = Pattern.compile("failed to remove context " +
29-
"(.+?): failed to remove metadata: remove (.+?): The process cannot access the file because it is " +
30-
"being used by another process\\.");
31-
private static final Pattern TLS_CERTIFICATE_NOT_FOUND = Pattern.compile("unable to create docker " +
32-
"endpoint config: open ([^:]+): The system cannot find the (?:file|path) specified\\.");
33-
private static final Pattern TLS_CERTIFICATE_MISSING_DATA = Pattern.compile("unable to create docker " +
34-
"endpoint config: invalid docker endpoint options: failed to retrieve context tls info: tls: failed " +
35-
"to find any PEM data in certificate input");
26+
private static final Pattern CONTEXT_NOT_FOUND = Pattern.compile("""
27+
context "([^"]+)" does not exist""");
28+
private static final Pattern CONFLICTING_NAME = Pattern.compile("""
29+
context "([^"]+)" already exists""");
30+
private static final Pattern REMOVE_FAILED_RESOURCE_IN_USE = Pattern.compile("""
31+
failed to remove context (.+?): failed to remove metadata: remove (.+?): The process cannot access the \
32+
file because it is being used by another process\\.""");
33+
private static final Pattern TLS_CERTIFICATE_NOT_FOUND = Pattern.compile("""
34+
unable to create docker endpoint config: open ([^:]+): The system cannot find the (?:file|path) \
35+
specified\\.""");
36+
private static final Pattern TLS_CERTIFICATE_MISSING_DATA = Pattern.compile("""
37+
unable to create docker endpoint config: invalid docker endpoint options: failed to retrieve context \
38+
tls info: tls: failed to find any PEM data in certificate input""");
3639

3740
/**
3841
* Creates a parser.

docker/src/main/java/com/github/cowwoc/anchor4j/docker/internal/resource/ImageParser.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,22 @@
3030
*/
3131
public final class ImageParser extends AbstractParser
3232
{
33-
private static final Pattern NOT_FOUND = Pattern.compile("Error response from daemon: " +
34-
"No such image: ([^ ]+)");
35-
private static final Pattern PULL_REPOSITORY_NOT_FOUND = Pattern.compile("Error response from daemon: " +
36-
"pull access denied for [^,]+, repository does not exist or may require 'docker login'");
37-
private static final Pattern PULL_MANIFEST_NOT_FOUND = Pattern.compile("Error response from daemon: " +
38-
"manifest for [^ ]+ not found: manifest unknown: manifest unknown");
39-
private static final Pattern PULL_ACCESS_DENIED1 = Pattern.compile("Error response from daemon: " +
40-
"Head \"[^\"]+\": denied");
41-
private static final String PULL_ACCESS_DENIED2 = "Error response from daemon: error from registry: " +
42-
"denied\ndenied";
43-
private static final Pattern PUSH_NOT_FOUND = Pattern.compile("Error response from daemon: " +
44-
"push access denied for ([^,]+), repository does not exist or may require 'docker login'");
45-
private static final Pattern REMOVE_MUST_BE_FORCED = Pattern.compile("Error response from daemon: " +
46-
"conflict: unable to delete ([^ ]+) \\(must be forced\\) -");
33+
private static final Pattern NOT_FOUND = Pattern.compile(
34+
"Error response from daemon: No such image: ([^ ]+)");
35+
private static final Pattern PULL_REPOSITORY_NOT_FOUND = Pattern.compile("""
36+
Error response from daemon: pull access denied for [^,]+, repository does not exist or may require \
37+
'docker login'""");
38+
private static final Pattern PULL_MANIFEST_NOT_FOUND = Pattern.compile(
39+
"Error response from daemon: manifest for [^ ]+ not found: manifest unknown: manifest unknown");
40+
private static final Pattern PULL_ACCESS_DENIED1 = Pattern.compile("""
41+
Error response from daemon: Head "[^"]+": denied""");
42+
private static final String PULL_ACCESS_DENIED2 =
43+
"Error response from daemon: error from registry: denied\ndenied";
44+
private static final Pattern PUSH_NOT_FOUND = Pattern.compile("""
45+
Error response from daemon: push access denied for ([^,]+), repository does not exist or may require \
46+
'docker login'""");
47+
private static final Pattern REMOVE_MUST_BE_FORCED = Pattern.compile(
48+
"Error response from daemon: conflict: unable to delete ([^ ]+) \\(must be forced\\) -");
4749

4850
/**
4951
* Creates a parser.

docker/src/main/java/com/github/cowwoc/anchor4j/docker/internal/resource/NetworkParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
*/
2020
public final class NetworkParser extends AbstractParser
2121
{
22-
private static final Pattern NOT_FOUND = Pattern.compile("Error response from daemon: network " +
23-
".+? not found");
22+
private static final Pattern NOT_FOUND = Pattern.compile(
23+
"Error response from daemon: network .+? not found");
2424

2525
/**
2626
* Creates a parser.

docker/src/main/java/com/github/cowwoc/anchor4j/docker/internal/resource/NodeParser.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,17 @@ public class NodeParser extends AbstractParser
3939
// Known variants:
4040
// Error response from daemon: This node is not a swarm manager. Use "docker swarm init" or "docker swarm join" to connect this node to swarm and try again.
4141
// Error response from daemon: This node is not a swarm manager. Worker nodes can't be used to view or modify cluster state. Please run this command on a manager node or promote the current node to a manager.
42-
static final String NOT_SWARM_MANAGER = "Error response from daemon: This node is not a swarm " +
43-
"manager.";
44-
private static final String DEMOTING_LAST_MANAGER = "Error response from daemon: rpc error: " +
45-
"code = FailedPrecondition desc = attempting to demote the last manager of the swarm";
46-
private static final Pattern UNIX_SOCKET_MISSING = Pattern.compile("Error response from daemon: " +
47-
"rpc error: code = Unavailable desc = connection error: desc = \"transport: Error while dialing: dial " +
48-
"(unix .+?): connect: no such file or directory\"");
49-
private static final String ACCESS_DENIED_TO_WORKER = "Error response from daemon: This node is not a " +
50-
"swarm manager. Worker nodes can't be used to view or modify cluster state. Please run this command " +
51-
"on a manager node or promote the current node to a manager.";
42+
static final String NOT_SWARM_MANAGER = "Error response from daemon: This node is not a swarm manager.";
43+
private static final String DEMOTING_LAST_MANAGER = """
44+
Error response from daemon: rpc error: code = FailedPrecondition desc = attempting to demote the last \
45+
manager of the swarm""";
46+
private static final Pattern UNIX_SOCKET_MISSING = Pattern.compile("""
47+
Error response from daemon: rpc error: code = Unavailable desc = connection error: desc = \
48+
"transport: Error while dialing: dial (unix .+?): connect: no such file or directory""");
49+
private static final String ACCESS_DENIED_TO_WORKER = """
50+
Error response from daemon: This node is not a swarm manager. Worker nodes can't be used to view or \
51+
modify cluster state. Please run this command on a manager node or promote the current node to a \
52+
manager.""";
5253

5354
/**
5455
* Creates a parser.

docker/src/main/java/com/github/cowwoc/anchor4j/docker/internal/resource/ServiceParser.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ public class ServiceParser extends AbstractParser
2424
{
2525
private static final Pattern IMAGE_NOT_FOUND = Pattern.compile("^Unable to find image '([^']+)' locally.*",
2626
DOTALL);
27-
private static final Pattern CONFLICTING_NAME = Pattern.compile("Error response from daemon: " +
28-
"Conflict. The container name \"([^\"]+)\" is already in use by container \"([^\"]+)\"\\. You have to " +
29-
"remove \\(or rename\\) that container to be able to reuse that name\\.");
30-
private static final String NOT_A_MANAGER = "Error response from daemon: This node is not a swarm " +
31-
"manager. Worker nodes can't be used to view or modify cluster state. Please run this command on a " +
32-
"manager node or promote the current node to a manager.";
27+
private static final Pattern CONFLICTING_NAME = Pattern.compile("""
28+
Error response from daemon: Conflict. The container name "([^"]+)" is already in use by container \
29+
"([^"]+)"\\. You have to remove \\(or rename\\) that container to be able to reuse that name\\.""");
30+
private static final String NOT_A_MANAGER = """
31+
Error response from daemon: This node is not a swarm manager. Worker nodes can't be used to view or \
32+
modify cluster state. Please run this command on a manager node or promote the current node to a \
33+
manager.""";
3334

3435
/**
3536
* Creates a parser.

docker/src/main/java/com/github/cowwoc/anchor4j/docker/internal/resource/SwarmParser.java

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,24 @@ To add a (?:manager|worker) to this swarm, run the following command:
3939
4040
*docker swarm join --token ([^ ]+) (.+?)
4141
""");
42-
private static final Pattern JOIN_SWARM_PATTERN = Pattern.compile("This node joined a swarm as a " +
43-
"(manager|worker)\\.");
44-
private static final String ALREADY_IN_SWARM = "Error response from daemon: This node is already part " +
45-
"of a swarm. Use \"docker swarm leave\" to leave this swarm and join another one.";
46-
private static final Pattern CONNECTION_REFUSED = Pattern.compile("Error response from daemon: " +
47-
"rpc error: code = Unavailable desc = connection error: desc = \"transport: Error while dialing: dial " +
48-
"(.+?): connect: connection refused\"");
42+
private static final Pattern JOIN_SWARM_PATTERN = Pattern.compile(
43+
"This node joined a swarm as a (manager|worker)\\.");
44+
private static final String ALREADY_IN_SWARM = """
45+
Error response from daemon: This node is already part of a swarm. Use "docker swarm leave" to leave \
46+
this swarm and join another one.""";
47+
private static final Pattern CONNECTION_REFUSED = Pattern.compile("""
48+
Error response from daemon: rpc error: code = Unavailable desc = connection error: desc = "transport: \
49+
Error while dialing: dial (.+?): connect: connection refused\"""");
4950
private static final String INVALID_JOIN_TOKEN = "Error response from daemon: invalid join token";
50-
private static final String REMOVING_LAST_MANAGER = "Error response from daemon: You are attempting to " +
51-
"leave the swarm on a node that is participating as a manager. Removing the last manager erases all " +
52-
"current state of the swarm. Use `--force` to ignore this message.";
53-
private static final String REMOVING_QUORUM = "Error response from daemon: You are attempting to leave " +
54-
"the swarm on a node that is participating as a manager. Removing this node leaves \\d+ managers out " +
55-
"of \\d+. Without a Raft quorum your swarm will be inaccessible. The only way to restore a swarm that " +
56-
"has lost consensus is to reinitialize it with `--force-new-cluster`. Use `--force` to suppress this " +
57-
"message.";
51+
private static final String REMOVING_LAST_MANAGER = """
52+
Error response from daemon: You are attempting to leave the swarm on a node that is participating as a \
53+
manager. Removing the last manager erases all current state of the swarm. Use `--force` to ignore this \
54+
message.""";
55+
private static final Pattern REMOVING_QUORUM = Pattern.compile("""
56+
Error response from daemon: You are attempting to leave the swarm on a node that is participating as a \
57+
manager\\. Removing this node leaves \\d+ managers out of \\d+\\. Without a Raft quorum your swarm will \
58+
be inaccessible\\. The only way to restore a swarm that has lost consensus is to reinitialize it with \
59+
`--force-new-cluster`\\. Use `--force` to suppress this message\\.""");
5860

5961
/**
6062
* Creates a parser.
@@ -159,7 +161,7 @@ public void leave(CommandResult result) throws ResourceInUseException
159161
if (result.exitCode() != 0)
160162
{
161163
String stderr = result.stderr();
162-
if (stderr.equals(REMOVING_LAST_MANAGER) || stderr.equals(REMOVING_QUORUM))
164+
if (stderr.equals(REMOVING_LAST_MANAGER) || REMOVING_QUORUM.matcher(stderr).matches())
163165
{
164166
throw new ResourceInUseException("To safely remove this manager from the swarm, first demote it " +
165167
"to a worker, then leave the quorum. If you intend to remove the final manager and erase the " +

docker/src/test/java/com/github/cowwoc/anchor4j/docker/test/resource/ContainerIT.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ public void waitUntilStopped() throws IOException, InterruptedException, Timeout
252252
String imageId = client.pullImage(EXISTING_IMAGE).pull();
253253

254254
int expected = 3;
255-
String containerId = client.createContainer(imageId).arguments("sh", "-c",
256-
"\"sleep 3; exit " + expected + "\"").create();
255+
String containerId = client.createContainer(imageId).arguments("sh", "-c", "sleep 3; exit " + expected).
256+
create();
257257
client.startContainer(containerId).start();
258258

259259
// Make sure we begin waiting before the container has shut down
@@ -271,8 +271,7 @@ public void waitUntilAlreadyStopped() throws IOException, InterruptedException,
271271
Docker client = it.getClient();
272272
String imageId = client.pullImage(EXISTING_IMAGE).pull();
273273
int expected = 1;
274-
String containerId = client.createContainer(imageId).arguments("sh", "-c", "\"exit " + expected +
275-
"\"").create();
274+
String containerId = client.createContainer(imageId).arguments("sh", "-c", "exit " + expected).create();
276275
client.startContainer(containerId).start();
277276
int actual = client.waitUntilContainerStops(containerId);
278277
requireThat(actual, "actual").isEqualTo(expected, "expected");
@@ -288,8 +287,7 @@ public void waitUntilMissingContainerStopped() throws IOException, InterruptedEx
288287
Docker client = it.getClient();
289288
String imageId = client.pullImage(EXISTING_IMAGE).pull();
290289
int expected = 1;
291-
String containerId = client.createContainer(imageId).arguments("sh", "-c", "\"exit " + expected + "\"").
292-
create();
290+
String containerId = client.createContainer(imageId).arguments("sh", "-c", "exit " + expected).create();
293291
client.startContainer(containerId).start();
294292
client.stopContainer(containerId).stop();
295293
client.removeContainer(containerId).removeAnonymousVolumes().remove();

0 commit comments

Comments
 (0)