33import docker
44import logging
55from localstack_utils .container import Container
6- from localstack_utils .localstack_docker_configuration import LocalstackDockerConfiguration
6+ from localstack_utils .localstack_docker_configuration import (
7+ LocalstackDockerConfiguration ,
8+ )
79from localstack_utils .localstack_logger import LocalstackLogger
810
911ENV_CONFIG_USE_SSL = "USE_SSL"
1214TMP_PATH = "/tmp/localstack"
1315READY_TOKEN = re .compile ("Ready\\ ." )
1416DEFAULT_EDGE_PORT = 4566
15- PORT_CONFIG_FILENAME = "/opt/code/localstack/.venv/lib/python3.8/site-packages/localstack_client/config.py"
17+ PORT_CONFIG_FILENAME = (
18+ "/opt/code/localstack/.venv/lib/python3.8/site-packages/localstack_client/config.py"
19+ )
1620# DEFAULT_PORT_PATTERN = re.compile("'(\\w+)'\\Q: '{proto}://{host}:\\E(\\d+)'")
1721
1822localstack_instance = None
19- logging .basicConfig (level = logging .INFO , format = '%(message)s' )
23+ logging .basicConfig (level = logging .INFO , format = "%(message)s" )
24+
2025
2126class Localstack :
22-
2327 localstack_container = None
2428 service_to_map = {}
2529 locked = False
@@ -28,62 +32,78 @@ class Localstack:
2832 def INSTANCE ():
2933 return Localstack ()
3034
31- external_hostName = ''
35+ external_hostName = ""
3236
33- def startup (self , docker_configuration ) :
37+ def startup (self , docker_configuration ):
3438 if self .locked :
3539 raise Exception ("A docker instance is starting or already started." )
3640 self .locked = True
37- self .external_hostname = docker_configuration .external_hostname
3841
3942 try :
4043 self .localstack_container = Container .create_localstack_container (
41- docker_configuration .external_hostname ,
4244 docker_configuration .pull_new_image ,
43- docker_configuration .randomize_ports ,
4445 docker_configuration .image_name ,
4546 docker_configuration .image_tag ,
46- docker_configuration .port_edge ,
47- docker_configuration .port_elastic_search ,
47+ docker_configuration .gateway_listen ,
4848 docker_configuration .environment_variables ,
4949 docker_configuration .port_mappings ,
50- docker_configuration .bind_mounts ,
51- docker_configuration .platform
50+ docker_configuration .pro ,
5251 )
5352
5453 self .setup_logger ()
5554
56- Container .waitForReady (self .localstack_container , READY_TOKEN )
55+ Container .wait_for_ready (self .localstack_container , READY_TOKEN )
5756
58- except docker .errors .APIError as error :
57+ except docker .errors .APIError :
5958 if not docker_configuration .ignore_docker_runerrors :
6059 raise "Unable to start docker"
6160
62- except :
61+ except Exception :
6362 raise sys .exc_info ()
6463
65-
6664 def stop (self ):
6765 self .localstack_container .stop ()
6866
69-
7067 def setup_logger (self ):
7168 localstack_logger = LocalstackLogger (self .localstack_container )
7269 localstack_logger .start ()
7370
74- def startup_localstack (port = 4566 , services = [], ignore_docker_errors = False ):
71+
72+ def startup_localstack (
73+ image_name = "" ,
74+ tag = "" ,
75+ pro = False ,
76+ ports = None ,
77+ env_variables = None ,
78+ gateway_listen = "" ,
79+ ignore_docker_errors = False ,
80+ ):
7581 global localstack_instance
7682 localstack_instance = Localstack .INSTANCE ()
7783 config = LocalstackDockerConfiguration ()
7884
79- if len (services ):
80- config .envirement_variables .update ({'SERVICES' : ',' .join (services )})
81- if port != 4566 :
82- config .port_edge = str (port )
8385 config .ignore_docker_runerrors = ignore_docker_errors
86+ if image_name :
87+ config .image_name = image_name
88+
89+ if tag :
90+ config .image_tag = tag
91+
92+ if ports :
93+ config .port_mappings = ports
94+
95+ if pro :
96+ config .pro = pro
97+
98+ if env_variables :
99+ config .environment_variables = env_variables
100+
101+ if gateway_listen :
102+ config .gateway_listen = gateway_listen
84103
85104 localstack_instance .startup (config )
86105
106+
87107def stop_localstack ():
88108 if localstack_instance :
89109 localstack_instance .stop ()
0 commit comments