Skip to content

Commit 46fb5e2

Browse files
committed
update and simplify config
1 parent 96ea530 commit 46fb5e2

3 files changed

Lines changed: 14 additions & 28 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
nosetests.xml
44
__pycache__
55
localstack_utils.egg-info
6+
.ruff_cache

localstack_utils/container.py

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
LOCALSTACK_NAME = "localstack/localstack"
77
LOCALSTACK_TAG = "latest"
8-
LOCALSTACK_PORT_EDGE = "4566"
9-
LOCALSTACK_PORT_ELASTICSEARCH = "4571"
108

119
MAX_PORT_CONNECTION_ATTEMPTS = 10
1210
MAX_LOG_COLLECTION_ATTEMPTS = 120
@@ -17,66 +15,55 @@
1715
ENV_USE_SSL = "USE_SSL"
1816
ENV_DEBUG_DEFAULT = "1"
1917
LOCALSTACK_EXTERNAL_HOSTNAME = "HOSTNAME_EXTERNAL"
20-
DEFAULT_CONTAINER_ID = "localstack_main"
18+
DEFAULT_CONTAINER_ID = "localstack-main"
2119

2220
DOCKER_CLIENT = docker.from_env()
2321

2422

2523
class Container:
2624
@staticmethod
2725
def create_localstack_container(
28-
external_hostname,
2926
pull_new_image,
30-
randomize_ports,
3127
image_name,
3228
image_tag,
33-
port_edge,
34-
port_elasticsearch,
29+
gateway_listen,
3530
environment_variables,
36-
port_mappings,
37-
bind_mounts,
38-
platform,
3931
):
40-
environment_variables = (
41-
{} if environment_variables is None else environment_variables
42-
)
43-
bind_mounts = {} if bind_mounts is None else bind_mounts
44-
port_mappings = {} if port_mappings is None else port_mappings
32+
environment_variables = environment_variables or {}
33+
environment_variables["GATEWAY_LISTEN"] = gateway_listen
34+
4535
image_name_or_default = LOCALSTACK_NAME if image_name is None else image_name
4636
image_exists = (
4737
True
4838
if len(DOCKER_CLIENT.images.list(name=image_name_or_default))
4939
else False
5040
)
5141

52-
fullPortEdge = {
53-
(LOCALSTACK_PORT_EDGE if port_edge is None else port_edge): (
54-
LOCALSTACK_PORT_EDGE
55-
)
56-
}
42+
port = gateway_listen.split(":")[1]
43+
full_port_edge = {port: port}
5744

5845
if pull_new_image or not image_exists:
5946
logging.info("Pulling latest image")
6047
DOCKER_CLIENT.images.pull(image_name_or_default, image_tag)
6148

6249
return DOCKER_CLIENT.containers.run(
6350
image_name_or_default,
64-
ports=fullPortEdge,
51+
ports=full_port_edge,
6552
environment=environment_variables,
6653
detach=True,
6754
)
6855

6956
@staticmethod
70-
def waitForReady(container, pattern):
71-
attemps = 0
57+
def wait_for_ready(container, pattern):
58+
attempts = 0
7259

7360
while True:
7461
logs = container.logs(tail=NUM_LOG_LINES).decode("utf-8")
7562
if re.search(pattern, logs):
7663
return
7764

7865
sleep(POLL_INTERVAL)
79-
attemps += 1
66+
attempts += 1
8067

81-
if attemps >= MAX_LOG_COLLECTION_ATTEMPTS:
68+
if attempts >= MAX_LOG_COLLECTION_ATTEMPTS:
8269
raise "Could not find token: " + pattern.toString() + "in logs"

localstack_utils/localstack_docker_configuration.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ class LocalstackDockerConfiguration:
55
image_tag = None
66
platform = None
77

8-
port_edge = "4566"
9-
port_elastic_search = "4571"
10-
external_hostname = "localhost"
8+
gateway_listen = "0.0.0.0:4566"
119
environment_variables = {}
1210
port_mappings = {}
1311
bind_mounts = {}

0 commit comments

Comments
 (0)