mirror of
https://github.com/floci-io/floci.git
synced 2026-11-26 23:29:28 -05:00
fix(ecr): pull rewritten ECR images from an address Docker Desktop reaches (#7752)
* fix(ecr): pull rewritten ECR images from an address Docker Desktop reaches Docker Desktop's daemon runs in a VM and dials localhost there, where a host port Docker chose for Floci is not bound, so pulls of rewritten ECR images timed out. On Docker Desktop, rewrite to <account>.dkr.ecr.<region>.localhost:<port>, which Desktop sends through its host proxy and pulls over plain HTTP. * fix(ecr): warn when the Docker daemon's operating system cannot be read The rewrite then falls back to localhost, which Docker Desktop cannot reach, so the later pull timeout needs this cause next to it.
This commit is contained in:
1 parent
a28c52f951
commit
fd8be9afee
5 files changed
+125
-12
No files matched your search
@@ -473,8 +473,9 @@ public class EcrRegistryDataPlane {
|
||||
storageRepositoryName, repository, backendUri,
|
||||
tag(path)));
|
||||
}
|
||||
// A loopback host is the address Floci itself hands the Docker daemon for the ECS, Lambda
|
||||
// and EMR Serverless images it pulls, path style in either URI style (see rewriteImageUri).
|
||||
// A loopback host is the address Floci itself hands a Docker daemon other than Docker Desktop
|
||||
// for the ECS, Lambda and EMR Serverless images it pulls, path style in either URI style
|
||||
// (see rewriteImageUri).
|
||||
if (!"path".equalsIgnoreCase(uriStyle) && !isLoopbackHost(host)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
import java.util.OptionalInt;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -107,6 +108,8 @@ public class EcrRegistryManager {
|
||||
private volatile String containerId;
|
||||
private volatile Closeable logStream;
|
||||
private volatile Consumer<List<String>> reconcileHook;
|
||||
/** Whether the Docker daemon is Docker Desktop; null until the daemon has answered. */
|
||||
private volatile Boolean dockerDesktop;
|
||||
|
||||
@Inject
|
||||
public EcrRegistryManager(ContainerBuilder containerBuilder,
|
||||
@@ -160,12 +163,20 @@ public class EcrRegistryManager {
|
||||
String region = m.group(2);
|
||||
String repoAndTag = m.group(3);
|
||||
ensureStarted();
|
||||
// Path style on localhost whatever style the API advertises. A daemon with the
|
||||
// containerd image store, the default from Docker Engine 29, reaches only localhost and
|
||||
// 127.0.0.1 over plain HTTP and takes every other name, *.localhost included, for an
|
||||
// HTTPS registry: Floci's plain port cannot answer that, and its TLS port cannot prove
|
||||
// itself to a daemon that does not trust Floci's CA.
|
||||
String rewritten = "localhost:" + advertisedPort() + "/" + internalRepoName(account, region, repoAndTag);
|
||||
String rewritten;
|
||||
if (dockerDesktop()) {
|
||||
// Docker Desktop's daemon runs in a VM and dials localhost there, where a host port Docker
|
||||
// chose for Floci's container is not bound. It sends any other registry name through its
|
||||
// host proxy, which reaches the port, and pulls *.localhost over plain HTTP.
|
||||
rewritten = account + ".dkr.ecr." + region + ".localhost:" + advertisedPort() + "/" + repoAndTag;
|
||||
} else {
|
||||
// Path style on localhost whatever style the API advertises. A daemon with the
|
||||
// containerd image store, the default from Docker Engine 29, reaches only localhost and
|
||||
// 127.0.0.1 over plain HTTP and takes every other name, *.localhost included, for an
|
||||
// HTTPS registry: Floci's plain port cannot answer that, and its TLS port cannot prove
|
||||
// itself to a daemon that does not trust Floci's CA.
|
||||
rewritten = "localhost:" + advertisedPort() + "/" + internalRepoName(account, region, repoAndTag);
|
||||
}
|
||||
LOG.infov("Rewriting ECR image URI {0} -> {1}", image, rewritten);
|
||||
return rewritten;
|
||||
}
|
||||
@@ -195,6 +206,23 @@ public class EcrRegistryManager {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean dockerDesktop() {
|
||||
Boolean cached = dockerDesktop;
|
||||
if (cached != null) {
|
||||
return cached;
|
||||
}
|
||||
try {
|
||||
String os = lifecycleManager.getDockerClient().infoCmd().exec().getOperatingSystem();
|
||||
cached = os != null && os.toLowerCase(Locale.ROOT).contains("docker desktop");
|
||||
} catch (RuntimeException e) {
|
||||
LOG.warnv("Could not read the operating system of the Docker daemon ({0}); pulling ECR images from localhost",
|
||||
e.getMessage());
|
||||
return false;
|
||||
}
|
||||
dockerDesktop = cached;
|
||||
return cached;
|
||||
}
|
||||
|
||||
/** Returns the docker-pullable repository URI for the given account/region/name. */
|
||||
public String getRepositoryUri(String accountId, String region, String repoName) {
|
||||
return repositoryUri(accountId, region, repoName, tlsUriEnabled() ? "localhost.floci.io" : "localhost");
|
||||
|
||||
Reference in new issue
Block a user