ScriptCollection 4.2.113__py3-none-any.whl → 4.2.114__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,7 +5,6 @@ import binascii
5
5
  import filecmp
6
6
  import hashlib
7
7
  import multiprocessing
8
- import socket
9
8
  import time
10
9
  from io import BytesIO
11
10
  import itertools
@@ -39,7 +38,7 @@ from .ProgramRunnerBase import ProgramRunnerBase
39
38
  from .ProgramRunnerPopen import ProgramRunnerPopen
40
39
  from .SCLog import SCLog, LogLevel
41
40
 
42
- version = "4.2.113"
41
+ version = "4.2.114"
43
42
  __version__ = version
44
43
 
45
44
  class VSCodeWorkspaceShellTask:
@@ -3017,10 +3016,11 @@ OCR-content:
3017
3016
  if generated_ports_override_file != GeneralUtilities.empty_string:
3018
3017
  GeneralUtilities.ensure_file_does_not_exist(generated_ports_override_file)
3019
3018
  if in_build_container:
3020
- # Inside the build-container the test-process itself runs in a container. Instead of publishing the container-ports to the host it is
3021
- # attached to the docker-network(s) of the test-services so it can reach them directly by their container-name. This way no ports have
3022
- # to be opened on the host at all and concurrent pipelines can not conflict on the same host-port anymore.
3023
- self.__connect_self_to_compose_networks(docker_compose_file)
3019
+ # Inside the build-container the docker-daemon runs in the same (ephemeral) container, so the test-process can reach the test-service-
3020
+ # containers via their container-IP but there is no docker-DNS available for it. To still be able to use the container-name in the
3021
+ # connection-strings (and to avoid publishing any port to the host, which would let concurrent pipelines conflict on the same host-port),
3022
+ # the container-names are mapped to their current container-IPs in the /etc/hosts of this build-container.
3023
+ self.__register_test_service_containers_in_etc_hosts(docker_compose_file)
3024
3024
 
3025
3025
  @GeneralUtilities.check_arguments
3026
3026
  def __generate_localhost_ports_override_file(self, docker_compose_file: str) -> str:
@@ -3041,25 +3041,35 @@ OCR-content:
3041
3041
  return override_file
3042
3042
 
3043
3043
  @GeneralUtilities.check_arguments
3044
- def get_external_networks_from_yaml_file(self, yaml_file: str) -> list[str]:
3045
- with open(yaml_file, encoding="utf-8") as stream:
3044
+ def __register_test_service_containers_in_etc_hosts(self, docker_compose_file: str) -> None:
3045
+ # Maps the container-names of the test-services to their current container-IPs in the /etc/hosts of THIS build-container (neither the runner-host
3046
+ # nor the test-service-containers are touched). The managed block is rewritten on each start because the containers get a new IP every time.
3047
+ hosts_file = "/etc/hosts"
3048
+ if not os.path.isfile(hosts_file):
3049
+ return
3050
+ with open(docker_compose_file, encoding="utf-8") as stream:
3046
3051
  loaded = yaml.safe_load(stream)
3047
- result: list[str] = []
3048
- networks = loaded.get("networks", None)
3049
- if networks is None:
3050
- return result
3051
- for network_key, network_definition in networks.items():
3052
- if isinstance(network_definition, dict) and network_definition.get("external", False):
3053
- # For external networks the actual docker-network-name is the explicit "name" if given, otherwise the key itself.
3054
- result.append(network_definition.get("name", network_key))
3055
- return result
3056
-
3057
- @GeneralUtilities.check_arguments
3058
- def __connect_self_to_compose_networks(self, docker_compose_file: str) -> None:
3059
- own_container = socket.gethostname() # Inside a container the hostname equals the container-id, which "docker network connect" accepts.
3060
- for network_name in self.get_external_networks_from_yaml_file(docker_compose_file):
3061
- # Connecting an already-connected container returns a non-zero exitcode; this is ignored on purpose to keep this operation idempotent.
3062
- self.run_program("docker", f"network connect {network_name} {own_container}", throw_exception_if_exitcode_is_not_zero=False)
3052
+ services = loaded.get("services", dict())
3053
+ entries: list[str] = []
3054
+ for service_name, service_definition in services.items():
3055
+ container_name = service_definition.get("container_name", service_name)
3056
+ inspect_result = self.run_program_argsasarray("docker", ["inspect", "-f", "{{range .NetworkSettings.Networks}}{{.IPAddress}} {{end}}", container_name], throw_exception_if_exitcode_is_not_zero=False)
3057
+ if inspect_result[0] != 0:
3058
+ continue
3059
+ ip_addresses = [ip_address for ip_address in inspect_result[1].split() if GeneralUtilities.string_has_content(ip_address)]
3060
+ if 0 < len(ip_addresses):
3061
+ entries.append(f"{ip_addresses[0]}\t{container_name}")
3062
+ start_marker = "# >>> scriptcollection-test-service-hosts (managed automatically; do not edit)"
3063
+ end_marker = "# <<< scriptcollection-test-service-hosts"
3064
+ with open(hosts_file, "r", encoding="utf-8") as stream:
3065
+ content = stream.read()
3066
+ # Remove a previously written block first so stale IPs of already-recreated containers do not shadow the current ones.
3067
+ content = re.sub(re.escape(start_marker)+".*?"+re.escape(end_marker)+r"\n?", GeneralUtilities.empty_string, content, flags=re.DOTALL)
3068
+ content = content.rstrip("\n")+"\n"
3069
+ if 0 < len(entries):
3070
+ content = content+start_marker+"\n"+"\n".join(entries)+"\n"+end_marker+"\n"
3071
+ with open(hosts_file, "w", encoding="utf-8") as stream:
3072
+ stream.write(content)
3063
3073
 
3064
3074
  @GeneralUtilities.check_arguments
3065
3075
  def stop_local_test_service(self, file: str):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scriptcollection
3
- Version: 4.2.113
3
+ Version: 4.2.114
4
4
  Summary: The ScriptCollection is the place for reusable scripts.
5
5
  Author-email: Marius Göcke <marius.goecke@gmail.com>
6
6
  Project-URL: Homepage, https://github.com/anionDev/ScriptCollection
@@ -15,7 +15,7 @@ ScriptCollection/ProgramRunnerMock.py,sha256=uTu-aFle1W_oKjeQEmuPsFPQpvo0kRf2FrR
15
15
  ScriptCollection/ProgramRunnerPopen.py,sha256=8tP0xWKeRYoGlaNB3iUh4o61O-tKtcxrS7IUqtU85C4,4091
16
16
  ScriptCollection/ProgramRunnerSudo.py,sha256=4lxbUFMIWMbthM5Q_QaFjvZfAsNpKlXeqfEbiofg_DI,5109
17
17
  ScriptCollection/SCLog.py,sha256=8TRy1LeYMsPOIuWUcnUNNbO5pd-cNBS-3cn-kdzP8FU,4768
18
- ScriptCollection/ScriptCollectionCore.py,sha256=_KX3pp5W8h25IqccC4LViEM6a_OglAqA7e4MeQ7Hj3w,193204
18
+ ScriptCollection/ScriptCollectionCore.py,sha256=vDB6Ffo6phDV--4DGqftzqR7U5DiczY3YaHJOiPrG_o,194154
19
19
  ScriptCollection/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
20
20
  ScriptCollection/OCIImages/AbstractImageHandler.py,sha256=o129UYDtLymCRjMZBP9Puaj19ueMHoNt6UTLspfnaRc,1758
21
21
  ScriptCollection/OCIImages/OCIImageManager.py,sha256=2muW4hJ_a7EfavY3WVnafqZ0HC87RcZsoTuNvA3c0To,11175
@@ -291,8 +291,8 @@ build/lib/build/lib/build/lib/build/lib/ScriptCollection/TFCPS/Python/TFCPS_Code
291
291
  build/lib/build/lib/build/lib/build/lib/ScriptCollection/TFCPS/Python/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
292
292
  build/lib/build/lib/build/lib/build/lib/ScriptCollection/TFCPS/Rust/TFCPS_CodeUnitSpecific_Rust.py,sha256=WhOsMpJxNGqnQGA3nJ99ruyqymxBeJxCcpK98zJduTo,1680
293
293
  build/lib/build/lib/build/lib/build/lib/ScriptCollection/TFCPS/Rust/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
294
- scriptcollection-4.2.113.dist-info/METADATA,sha256=w4GginBlfMBrxZ6JL2KfvnHN7je22MQ0kvJwhKWGRZI,7697
295
- scriptcollection-4.2.113.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
296
- scriptcollection-4.2.113.dist-info/entry_points.txt,sha256=_vnVTrGJc_z-DTPLvaYyyOpDEQLz0bdO2OLN3_ZmeR8,4978
297
- scriptcollection-4.2.113.dist-info/top_level.txt,sha256=hY2hOVH0V0Ce51WB76zKkIWTUNwMUdHo4XDkR2vYVwg,17
298
- scriptcollection-4.2.113.dist-info/RECORD,,
294
+ scriptcollection-4.2.114.dist-info/METADATA,sha256=AezFFqUlfDVB6_SUko5K8JHmSdghDSZjKddU1fnm0gU,7697
295
+ scriptcollection-4.2.114.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
296
+ scriptcollection-4.2.114.dist-info/entry_points.txt,sha256=_vnVTrGJc_z-DTPLvaYyyOpDEQLz0bdO2OLN3_ZmeR8,4978
297
+ scriptcollection-4.2.114.dist-info/top_level.txt,sha256=hY2hOVH0V0Ce51WB76zKkIWTUNwMUdHo4XDkR2vYVwg,17
298
+ scriptcollection-4.2.114.dist-info/RECORD,,