diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index bb6e669..96826e8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -33,4 +33,6 @@ jobs: run: black --check . - name: Run tests + env: + LOCALSTACK_AUTH_TOKEN: ${{ secrets.LOCALSTACK_AUTH_TOKEN }} run: pytest tests/ -v diff --git a/README.md b/README.md index 2324d6d..e8a9d85 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,8 @@ class TestKinesis(unittest.TestCase): ``` ## Change Log +* 1.0.5: Add support for configurable container name and auth token forwarding +* 1.0.4: Fixes to LocalStack and Container modules * 1.0.3: Add auto_remove config option * 1.0.2: LocalStack Pro image set as default * 1.0.1: Repository URL fixed diff --git a/localstack_utils/__init__.py b/localstack_utils/__init__.py index 976498a..68cdeee 100644 --- a/localstack_utils/__init__.py +++ b/localstack_utils/__init__.py @@ -1 +1 @@ -__version__ = "1.0.3" +__version__ = "1.0.5" diff --git a/localstack_utils/container.py b/localstack_utils/container.py index 3bd2890..bb88fde 100644 --- a/localstack_utils/container.py +++ b/localstack_utils/container.py @@ -1,12 +1,13 @@ from __future__ import annotations import logging +import os import re import docker from time import sleep LOCALSTACK_IMAGE_NAME = "localstack/localstack-pro" -LATEST_TAG = "latest" +DEV_TAG = "dev" MAX_PORT_CONNECTION_ATTEMPTS = 10 MAX_LOG_COLLECTION_ATTEMPTS = 120 @@ -28,7 +29,8 @@ def create_localstack_container( *args, pull_new_image: bool = False, image_name: str = LOCALSTACK_IMAGE_NAME, - image_tag: str = LATEST_TAG, + image_tag: str = DEV_TAG, + container_name: str = DEFAULT_CONTAINER_ID, gateway_listen: str = "0.0.0.0:4566", auto_remove: bool = False, environment_variables: dict | None = None, @@ -37,6 +39,12 @@ def create_localstack_container( ): environment_variables = environment_variables or {} environment_variables["GATEWAY_LISTEN"] = gateway_listen + if "LOCALSTACK_AUTH_TOKEN" not in environment_variables and os.environ.get( + "LOCALSTACK_AUTH_TOKEN" + ): + environment_variables["LOCALSTACK_AUTH_TOKEN"] = os.environ[ + "LOCALSTACK_AUTH_TOKEN" + ] image_exists = ( True if len(DOCKER_CLIENT.images.list(name=image_name)) else False @@ -47,11 +55,12 @@ def create_localstack_container( bind_ports.update({gateway_port: gateway_port}) if pull_new_image or not image_exists: - logging.info("Pulling latest image") + logging.info("Pulling latest development image") DOCKER_CLIENT.images.pull(image_name, image_tag) return DOCKER_CLIENT.containers.run( image_name, + name=container_name, ports=bind_ports, environment=environment_variables, auto_remove=auto_remove, diff --git a/localstack_utils/localstack.py b/localstack_utils/localstack.py index dd4985d..7164fc0 100644 --- a/localstack_utils/localstack.py +++ b/localstack_utils/localstack.py @@ -1,7 +1,7 @@ import re import docker import logging -from localstack_utils.container import Container +from localstack_utils.container import DEV_TAG, Container from localstack_utils.localstack_docker_configuration import ( LocalstackDockerConfiguration, ) @@ -43,6 +43,7 @@ def startup(self, docker_configuration): pull_new_image=docker_configuration.pull_new_image, image_name=docker_configuration.image_name, image_tag=docker_configuration.image_tag, + container_name=docker_configuration.container_name, gateway_listen=docker_configuration.gateway_listen, auto_remove=docker_configuration.auto_remove_container, environment_variables=docker_configuration.environment_variables, @@ -70,7 +71,8 @@ def setup_logger(self): def startup_localstack( image_name="", - tag="", + tag=DEV_TAG, + container_name="", pro=False, ports=None, env_variables=None, @@ -89,6 +91,9 @@ def startup_localstack( if tag: config.image_tag = tag + if container_name: + config.container_name = container_name + if ports: config.port_mappings = ports diff --git a/localstack_utils/localstack_docker_configuration.py b/localstack_utils/localstack_docker_configuration.py index 5083c28..d1e332f 100644 --- a/localstack_utils/localstack_docker_configuration.py +++ b/localstack_utils/localstack_docker_configuration.py @@ -3,6 +3,7 @@ class LocalstackDockerConfiguration: randomize_ports = False image_name = None image_tag = None + container_name = None platform = None gateway_listen = "0.0.0.0:4566"