ScriptCollection 4.2.114__py3-none-any.whl → 4.2.116__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.
@@ -38,7 +38,7 @@ from .ProgramRunnerBase import ProgramRunnerBase
38
38
  from .ProgramRunnerPopen import ProgramRunnerPopen
39
39
  from .SCLog import SCLog, LogLevel
40
40
 
41
- version = "4.2.114"
41
+ version = "4.2.116"
42
42
  __version__ = version
43
43
 
44
44
  class VSCodeWorkspaceShellTask:
@@ -3016,10 +3016,15 @@ OCR-content:
3016
3016
  if generated_ports_override_file != GeneralUtilities.empty_string:
3017
3017
  GeneralUtilities.ensure_file_does_not_exist(generated_ports_override_file)
3018
3018
  if in_build_container:
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.
3019
+ # Inside the build-container the docker-socket points at a daemon on which the test-service-containers are created as SIBLING-containers
3020
+ # attached to the (external) compose-network. The build-container itself is not attached to that network, so without the following step it
3021
+ # could neither route to the container-IPs nor use the docker-DNS (which results in connection-timeouts even though the container-name can
3022
+ # be resolved via /etc/hosts). Therefore the build-container is attached to every (external) network the compose-file uses. No port is
3023
+ # published to the host, so concurrent pipelines on the same host do not conflict on host-ports.
3024
+ self.__connect_build_container_to_compose_networks(docker_compose_file)
3025
+ # In addition the container-names are mapped to their current container-IPs in the /etc/hosts of this build-container so that the
3026
+ # container-names can be used in the connection-strings even if the docker-DNS is not consulted. The managed block is rewritten on each
3027
+ # start because the containers get a new IP every time.
3023
3028
  self.__register_test_service_containers_in_etc_hosts(docker_compose_file)
3024
3029
 
3025
3030
  @GeneralUtilities.check_arguments
@@ -3040,6 +3045,59 @@ OCR-content:
3040
3045
  yaml.safe_dump({"services": override_services}, stream)
3041
3046
  return override_file
3042
3047
 
3048
+ @GeneralUtilities.check_arguments
3049
+ def __get_own_container_id(self) -> str:
3050
+ # Determines the id of the container this process currently runs in. The hostname usually equals the short container-id, but a runner can
3051
+ # override the hostname, so the id is primarily derived from the cgroup-/mountinfo-entries (docker mounts files like /etc/hostname from
3052
+ # /var/lib/docker/containers/<full-id>/... so the full 64-char container-id appears in these paths). The hostname is used as fallback only.
3053
+ full_container_id_pattern = re.compile(r"([0-9a-f]{64})")
3054
+ for proc_file in ["/proc/self/mountinfo", "/proc/self/cgroup"]:
3055
+ if not os.path.isfile(proc_file):
3056
+ continue
3057
+ try:
3058
+ content = GeneralUtilities.read_text_from_file(proc_file)
3059
+ except Exception:
3060
+ continue
3061
+ # Prefer lines which clearly reference a container-id-path to avoid matching unrelated 64-hex-strings.
3062
+ for line in content.splitlines():
3063
+ if "docker/containers/" in line or "/docker/" in line or "kubepods" in line:
3064
+ match = full_container_id_pattern.search(line)
3065
+ if match is not None:
3066
+ return match.group(1)
3067
+ match = full_container_id_pattern.search(content)
3068
+ if match is not None:
3069
+ return match.group(1)
3070
+ if os.path.isfile("/etc/hostname"):
3071
+ return GeneralUtilities.read_text_from_file_without_linebreak("/etc/hostname").strip()
3072
+ return GeneralUtilities.empty_string
3073
+
3074
+ @GeneralUtilities.check_arguments
3075
+ def __connect_build_container_to_compose_networks(self, docker_compose_file: str) -> None:
3076
+ # Attaches THIS build-container to every (external) network used by the compose-file so that the test-service-containers (which are
3077
+ # sibling-containers on the same docker-daemon) become routable and resolvable. The docker-socket is shared with the daemon, but the
3078
+ # network-namespace of the build-container is not, so without attaching there is no network-path to the container-IPs.
3079
+ own_container_id = self.__get_own_container_id()
3080
+ if not GeneralUtilities.string_has_content(own_container_id):
3081
+ return
3082
+ with open(docker_compose_file, encoding="utf-8") as stream:
3083
+ loaded = yaml.safe_load(stream)
3084
+ networks = loaded.get("networks", dict())
3085
+ for network_key, network_definition in networks.items():
3086
+ network_definition = network_definition or dict()
3087
+ network_name = network_definition.get("name", network_key)
3088
+ inspect_result = self.run_program_argsasarray("docker", ["network", "inspect", "-f", "{{range $id, $c := .Containers}}{{$id}}\n{{end}}", network_name], throw_exception_if_exitcode_is_not_zero=False)
3089
+ if inspect_result[0] != 0:
3090
+ continue # The network does not exist (yet); nothing to attach to.
3091
+ # The keys of .Containers are full container-ids; the hostname (own_container_id) is the corresponding short-id (a prefix of it).
3092
+ connected_container_ids = [line.strip() for line in inspect_result[1].splitlines() if GeneralUtilities.string_has_content(line)]
3093
+ already_connected = any(connected_container_id.startswith(own_container_id) for connected_container_id in connected_container_ids)
3094
+ if not already_connected:
3095
+ # Attaching this build-container to the compose-network is REQUIRED for the test-process to reach the test-service-containers. If it fails,
3096
+ # the tests would otherwise resolve the container-name (via /etc/hosts) but have no network-route to the container-IP and only fail later
3097
+ # with a misleading connection-timeout. Therefore the attach must fail loudly here with the actual docker-error (e.g. "No such container"
3098
+ # or "network not found") instead of being swallowed.
3099
+ self.run_program_argsasarray("docker", ["network", "connect", network_name, own_container_id], throw_exception_if_exitcode_is_not_zero=True)
3100
+
3043
3101
  @GeneralUtilities.check_arguments
3044
3102
  def __register_test_service_containers_in_etc_hosts(self, docker_compose_file: str) -> None:
3045
3103
  # 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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scriptcollection
3
- Version: 4.2.114
3
+ Version: 4.2.116
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=vDB6Ffo6phDV--4DGqftzqR7U5DiczY3YaHJOiPrG_o,194154
18
+ ScriptCollection/ScriptCollectionCore.py,sha256=3S4a4GuMrWjEFace_HPGPlWcVrLk32U7jncNCql0j-k,198889
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.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,,
294
+ scriptcollection-4.2.116.dist-info/METADATA,sha256=UZWBMbeYmif2FoXiAY5_hEYEDJalDjOjCEKpPDkSjyA,7697
295
+ scriptcollection-4.2.116.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
296
+ scriptcollection-4.2.116.dist-info/entry_points.txt,sha256=_vnVTrGJc_z-DTPLvaYyyOpDEQLz0bdO2OLN3_ZmeR8,4978
297
+ scriptcollection-4.2.116.dist-info/top_level.txt,sha256=hY2hOVH0V0Ce51WB76zKkIWTUNwMUdHo4XDkR2vYVwg,17
298
+ scriptcollection-4.2.116.dist-info/RECORD,,