|
5 | 5 |
|
6 | 6 | LOCALSTACK_NAME = "localstack/localstack" |
7 | 7 | LOCALSTACK_TAG = "latest" |
8 | | -LOCALSTACK_PORT_EDGE = "4566" |
9 | | -LOCALSTACK_PORT_ELASTICSEARCH = "4571" |
10 | 8 |
|
11 | 9 | MAX_PORT_CONNECTION_ATTEMPTS = 10 |
12 | 10 | MAX_LOG_COLLECTION_ATTEMPTS = 120 |
|
17 | 15 | ENV_USE_SSL = "USE_SSL" |
18 | 16 | ENV_DEBUG_DEFAULT = "1" |
19 | 17 | LOCALSTACK_EXTERNAL_HOSTNAME = "HOSTNAME_EXTERNAL" |
20 | | -DEFAULT_CONTAINER_ID = "localstack_main" |
| 18 | +DEFAULT_CONTAINER_ID = "localstack-main" |
21 | 19 |
|
22 | 20 | DOCKER_CLIENT = docker.from_env() |
23 | 21 |
|
24 | 22 |
|
25 | 23 | class Container: |
26 | 24 | @staticmethod |
27 | 25 | def create_localstack_container( |
28 | | - external_hostname, |
29 | 26 | pull_new_image, |
30 | | - randomize_ports, |
31 | 27 | image_name, |
32 | 28 | image_tag, |
33 | | - port_edge, |
34 | | - port_elasticsearch, |
| 29 | + gateway_listen, |
35 | 30 | environment_variables, |
36 | | - port_mappings, |
37 | | - bind_mounts, |
38 | | - platform, |
39 | 31 | ): |
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 | + |
45 | 35 | image_name_or_default = LOCALSTACK_NAME if image_name is None else image_name |
46 | 36 | image_exists = ( |
47 | 37 | True |
48 | 38 | if len(DOCKER_CLIENT.images.list(name=image_name_or_default)) |
49 | 39 | else False |
50 | 40 | ) |
51 | 41 |
|
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} |
57 | 44 |
|
58 | 45 | if pull_new_image or not image_exists: |
59 | 46 | logging.info("Pulling latest image") |
60 | 47 | DOCKER_CLIENT.images.pull(image_name_or_default, image_tag) |
61 | 48 |
|
62 | 49 | return DOCKER_CLIENT.containers.run( |
63 | 50 | image_name_or_default, |
64 | | - ports=fullPortEdge, |
| 51 | + ports=full_port_edge, |
65 | 52 | environment=environment_variables, |
66 | 53 | detach=True, |
67 | 54 | ) |
68 | 55 |
|
69 | 56 | @staticmethod |
70 | | - def waitForReady(container, pattern): |
71 | | - attemps = 0 |
| 57 | + def wait_for_ready(container, pattern): |
| 58 | + attempts = 0 |
72 | 59 |
|
73 | 60 | while True: |
74 | 61 | logs = container.logs(tail=NUM_LOG_LINES).decode("utf-8") |
75 | 62 | if re.search(pattern, logs): |
76 | 63 | return |
77 | 64 |
|
78 | 65 | sleep(POLL_INTERVAL) |
79 | | - attemps += 1 |
| 66 | + attempts += 1 |
80 | 67 |
|
81 | | - if attemps >= MAX_LOG_COLLECTION_ATTEMPTS: |
| 68 | + if attempts >= MAX_LOG_COLLECTION_ATTEMPTS: |
82 | 69 | raise "Could not find token: " + pattern.toString() + "in logs" |
0 commit comments