ScriptCollection 4.2.105__py3-none-any.whl → 4.2.106__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.
@@ -39,7 +39,7 @@ from .ProgramRunnerBase import ProgramRunnerBase
39
39
  from .ProgramRunnerPopen import ProgramRunnerPopen
40
40
  from .SCLog import SCLog, LogLevel
41
41
 
42
- version = "4.2.105"
42
+ version = "4.2.106"
43
43
  __version__ = version
44
44
 
45
45
  class VSCodeWorkspaceShellTask:
@@ -105,6 +105,7 @@ class TFCPS_CodeUnitSpecific_Docker_Functions(TFCPS_CodeUnitSpecific_Base):
105
105
  raise ValueError(f"Operation is not implemented.")
106
106
 
107
107
  @GeneralUtilities.check_arguments
108
+ @GeneralUtilities.deprecated("Use image_is_working_via_network instead, which tests the image over a user-defined docker-network without publishing a host-port.")
108
109
  def image_is_working(self,timeout:timedelta,environment_variables:dict[str,str],test_port:int,http_test_route:str,use_https_for_test:bool)->tuple[bool,str]:
109
110
  if timeout is None:
110
111
  timeout=timedelta(seconds=120)
@@ -182,11 +183,102 @@ class TFCPS_CodeUnitSpecific_Docker_Functions(TFCPS_CodeUnitSpecific_Base):
182
183
  self.tfcps_Tools_General.ensure_containers_are_not_running([container_name])
183
184
 
184
185
  @GeneralUtilities.check_arguments
186
+ @GeneralUtilities.deprecated("Use verify_image_is_working_via_network instead, which tests the image over a user-defined docker-network without publishing a host-port.")
185
187
  def verify_image_is_working(self,timeout:timedelta,environment_variables:dict[str,str],test_port:int,http_test_route:str,use_https_for_test:bool):
186
188
  check_result:tuple[bool,str]= self.image_is_working(timeout,environment_variables,test_port,http_test_route,use_https_for_test)
187
189
  if not check_result[0]:
188
190
  raise ValueError("Image not working: "+check_result[1])
189
191
 
192
+ @GeneralUtilities.check_arguments
193
+ def image_is_working_via_network(self,timeout:timedelta,environment_variables:dict[str,str],container_port:int,http_test_route:str,use_https_for_test:bool,network_name:str)->tuple[bool,str]:
194
+ """Tests the built image without publishing a host-port: the container is attached to a
195
+ user-defined docker-network and the http-test is executed from a sibling-container on the
196
+ same network (addressing the container under test by its name). This avoids opening a port
197
+ on the docker-host - which, when the daemon is the host-daemon (mounted socket), would be a
198
+ real port on the host. The http-test is executed from a dedicated minimal curl-image that is
199
+ resolved via the image-manager (registered as "Curl"), so it is pulled from the configured
200
+ registry (no rate-limit) and does not require the image under test to provide curl.
201
+ container_port is the port the application listens on inside the container."""
202
+ if timeout is None:
203
+ timeout=timedelta(seconds=120)
204
+ if environment_variables is None:
205
+ environment_variables={}
206
+ current_platform = GeneralUtilities.get_current_platform()
207
+ platform_for_test:Platform=None
208
+ if current_platform == Platform.Windows_AMD64:
209
+ platform_for_test=Platform.Linux_AMD64
210
+ elif current_platform == Platform.Linux_AMD64:
211
+ platform_for_test=Platform.Linux_AMD64
212
+ elif current_platform == Platform.Linux_ARM64:
213
+ platform_for_test=Platform.Linux_ARM64
214
+ elif current_platform == Platform.MacOS_ARM64:
215
+ platform_for_test=Platform.Linux_ARM64
216
+ else:
217
+ raise ValueError(f"Current platform {current_platform} is not supported for testing.")
218
+ oci_image_artifacts_folder :str= GeneralUtilities.resolve_relative_path("Other/Artifacts/BuildResult_OCIImage", self.get_codeunit_folder())
219
+ container_name:str=f"{self.get_codeunit_name()}finaltest".lower()
220
+ GeneralUtilities.assert_condition(http_test_route is None or http_test_route.startswith("/"),"If a test-route is given then it must start with \"/\".")
221
+ self.tfcps_Tools_General.ensure_containers_are_not_running([container_name])
222
+ self.tfcps_Tools_General.load_docker_image(oci_image_artifacts_folder,platform_for_test)
223
+ codeunit_file:str=os.path.join(self.get_codeunit_folder(),f"{self.get_codeunit_name()}.codeunit.xml")
224
+ image=f"{self.get_codeunit_name()}:{self.tfcps_Tools_General.get_version_of_codeunit(codeunit_file)}".lower()
225
+ self._protected_sc.ensure_local_docker_network_exists(network_name)
226
+ argument=f"run -d --name {container_name} --network {network_name}"
227
+ for k,v in environment_variables.items():
228
+ argument=f"{argument} -e {k}={v}"#TODO switch to argument-array to also allow values with white-space
229
+ argument=f"{argument} {image}"
230
+ curl_image:str=None
231
+ if http_test_route is not None:
232
+ # Use a dedicated minimal curl-image to run the http-test from a sibling-container,
233
+ # so it does not depend on the image under test providing curl. It is resolved via
234
+ # the image-manager (like Syft), so it is pulled from the configured registry and
235
+ # does not hit registry-rate-limits.
236
+ curl_image=self.tfcps_Tools_General.oci_image_manager.get_registry_address_for_image_with_default_tag(self.get_repository_folder(),"Curl",True)
237
+ try:
238
+ last_exception:Exception=None
239
+ self._protected_sc.run_program("docker",argument)
240
+ start:datetime=GeneralUtilities.get_now()
241
+ end:datetime=start+timeout
242
+ while GeneralUtilities.get_now()<end:
243
+ time.sleep(1)
244
+ try:
245
+ if not self._protected_sc.container_is_running_and_healthy(container_name):
246
+ raise ValueError("Container is not running and healthy.")
247
+ if http_test_route is not None:
248
+ scheme="https" if use_https_for_test else "http"
249
+ url=f"{scheme}://{container_name}:{container_port}{http_test_route}"
250
+ curl_arguments="--fail --silent --show-error --max-time 30"
251
+ if use_https_for_test:
252
+ curl_arguments=curl_arguments+" --insecure"
253
+ self._protected_sc.run_program("docker",f"run --rm --network {network_name} --entrypoint curl {curl_image} {curl_arguments} \"{url}\"")
254
+ return (True,None)
255
+ except Exception as e:
256
+ last_exception=e
257
+ container_output:str=None
258
+ if not self._protected_sc.container_is_exists(container_name):
259
+ return (False,f"Container \"{container_name}\" does not exist.")
260
+ try:
261
+ container_output="\nContainer-output:\n"+self._protected_sc.get_output_of_container(container_name)
262
+ except Exception:
263
+ container_output="\n(Container-output not retrievable.)"
264
+ exception_message=f"\nContainer was started with \"docker {argument}\"."
265
+ if last_exception is not None:
266
+ exception_message=exception_message+"\nLast exception: "+GeneralUtilities.exception_to_str(last_exception)
267
+ if not self._protected_sc.container_is_running(container_name):
268
+ return (False,f"Container \"{container_name}\" is not running.{exception_message}{container_output}")
269
+ if not self._protected_sc.container_is_healthy(container_name):
270
+ return (False,f"Container \"{container_name}\" is not healthy.{exception_message}{container_output}")
271
+ return (False,f"Container \"{container_name}\" is not working properly.{exception_message}{container_output}")
272
+ finally:
273
+ self.tfcps_Tools_General.ensure_containers_are_not_running([container_name])
274
+ self._protected_sc.ensure_local_docker_network_does_not_exist(network_name)
275
+
276
+ @GeneralUtilities.check_arguments
277
+ def verify_image_is_working_via_network(self,timeout:timedelta,environment_variables:dict[str,str],container_port:int,http_test_route:str,use_https_for_test:bool,network_name:str):
278
+ check_result:tuple[bool,str]= self.image_is_working_via_network(timeout,environment_variables,container_port,http_test_route,use_https_for_test,network_name)
279
+ if not check_result[0]:
280
+ raise ValueError("Image not working: "+check_result[1])
281
+
190
282
  class TFCPS_CodeUnitSpecific_Docker_CLI:
191
283
 
192
284
  @staticmethod
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scriptcollection
3
- Version: 4.2.105
3
+ Version: 4.2.106
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=BPY7-ZMIlqT7JOKz8qlB5c0laF2Js-ijzqk09GxZC48,3821
16
16
  ScriptCollection/ProgramRunnerSudo.py,sha256=_khC3xuTdrPoLluBJZWfldltmmuKltABJPcbjZSFW-4,4835
17
17
  ScriptCollection/SCLog.py,sha256=8TRy1LeYMsPOIuWUcnUNNbO5pd-cNBS-3cn-kdzP8FU,4768
18
- ScriptCollection/ScriptCollectionCore.py,sha256=AO24YBlf78Uz8YdQNt-LgPKxwy6PDmmhaGrjNmzaK28,188793
18
+ ScriptCollection/ScriptCollectionCore.py,sha256=QqfcMDkuCN8Se1WFQo3cQ8Ewx8tkkqRR40Zq5Iq54X8,188793
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
@@ -40,7 +40,7 @@ ScriptCollection/TFCPS/TFCPS_MergeToStable.py,sha256=xVPer8EGH5vhTT3_mpTMJJxWLB3
40
40
  ScriptCollection/TFCPS/TFCPS_PreBuildCodeunitsScript.py,sha256=f0Uq1cA_4LvmL72cal0crrbKF6PcxL13D9wBKuQ1YBw,2328
41
41
  ScriptCollection/TFCPS/TFCPS_Tools_General.py,sha256=l42hYiDwcafEGIUCXmeyxr7XMzQ01MUEpElVvB1zhKY,105372
42
42
  ScriptCollection/TFCPS/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
43
- ScriptCollection/TFCPS/Docker/TFCPS_CodeUnitSpecific_Docker.py,sha256=TU9An7feBsSMardrtr0byYijQfYWxA_LB27yVNsOqy8,12762
43
+ ScriptCollection/TFCPS/Docker/TFCPS_CodeUnitSpecific_Docker.py,sha256=RifSjU1JqI96hl63-8AXpIddwDpdHlMZV6uFtKpGNGQ,19669
44
44
  ScriptCollection/TFCPS/Docker/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
45
45
  ScriptCollection/TFCPS/DotNet/CertificateGeneratorInformationBase.py,sha256=bT6Gd5pQpZCw4OQz6HWkPCSn5z__eUUEisABLDSxd0o,200
46
46
  ScriptCollection/TFCPS/DotNet/CertificateGeneratorInformationGenerate.py,sha256=QyjOfMY22JWCvKjMelHiDWbJiWqotOfebpJpgDUaoO4,237
@@ -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.105.dist-info/METADATA,sha256=FwJgtaMYwy4d9adTu8devQa6Cd6SLpLGiauglhE2q4o,7697
295
- scriptcollection-4.2.105.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
296
- scriptcollection-4.2.105.dist-info/entry_points.txt,sha256=_vnVTrGJc_z-DTPLvaYyyOpDEQLz0bdO2OLN3_ZmeR8,4978
297
- scriptcollection-4.2.105.dist-info/top_level.txt,sha256=hY2hOVH0V0Ce51WB76zKkIWTUNwMUdHo4XDkR2vYVwg,17
298
- scriptcollection-4.2.105.dist-info/RECORD,,
294
+ scriptcollection-4.2.106.dist-info/METADATA,sha256=0wUmuZoKXxzespo0-W27Q9c4k7mlT5drveyJqeM_hGg,7697
295
+ scriptcollection-4.2.106.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
296
+ scriptcollection-4.2.106.dist-info/entry_points.txt,sha256=_vnVTrGJc_z-DTPLvaYyyOpDEQLz0bdO2OLN3_ZmeR8,4978
297
+ scriptcollection-4.2.106.dist-info/top_level.txt,sha256=hY2hOVH0V0Ce51WB76zKkIWTUNwMUdHo4XDkR2vYVwg,17
298
+ scriptcollection-4.2.106.dist-info/RECORD,,