From bb3df6d3048eb93b4fa7eaaf92f0426b78d6e182 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Br=C3=A6khus?= Date: Fri, 29 Oct 2021 09:58:43 +0200 Subject: [PATCH] Revert removal of EC2HostNameResolver annotation This annotation was removed in 7e8c8228e85fada76554bc7473679e4da76ab472 but is still useful for us and likely others that have CICD setups that require it for our test runs. --- .../annotation/EC2HostNameResolver.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/main/java/cloud/localstack/docker/annotation/EC2HostNameResolver.java diff --git a/src/main/java/cloud/localstack/docker/annotation/EC2HostNameResolver.java b/src/main/java/cloud/localstack/docker/annotation/EC2HostNameResolver.java new file mode 100644 index 0000000..7f3290a --- /dev/null +++ b/src/main/java/cloud/localstack/docker/annotation/EC2HostNameResolver.java @@ -0,0 +1,23 @@ +package cloud.localstack.docker.annotation; + +import com.amazonaws.util.EC2MetadataUtils; + +/** + * Finds the hostname of the current EC2 instance + * + * This is useful for a CI server that is itself a docker container and which mounts the docker unix socket + * from the host machine. In that case, the server cannot spawn child containers but will instead spawn sibling + * containers which cannot be addressed at "localhost". In order to address the sibling containers you need to resolve + * the hostname of the host machine, which this method will accomplish. + * + * For more information about running docker for CI and mounting the host socket please look here: + * http://jpetazzo.github.io/2015/09/03/do-not-use-docker-in-docker-for-ci/ + */ +public class EC2HostNameResolver implements IHostNameResolver { + + @Override + public String getHostName() { + return EC2MetadataUtils.getLocalHostName(); + } + +}