ScriptCollection 4.2.0__py3-none-any.whl → 4.2.2__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.
@@ -102,7 +102,7 @@ class CertificateUpdater:
102
102
  else:
103
103
  GeneralUtilities.write_message_to_stdout(f"Create certificate for domain {domain}")
104
104
  dockerargument = f"run --name {certbot_container_name} --volume {self.__letsencrypt_folder}:/etc/letsencrypt"
105
- dockerargument = dockerargument + f" --volume {self.__log_folder}:/var/log/letsencrypt -p 80:80 "+self.__sc.get_image_with_registry_for_docker_image("certbot","latest")
105
+ dockerargument = dockerargument + f" --volume {self.__log_folder}:/var/log/letsencrypt -p 80:80 "+self.__sc.get_image_with_registry_for_docker_image("certbot","latest","docker.io/certbot/certbot")
106
106
  certbotargument = f"--standalone --email {self.__email} --agree-tos --force-renewal --rsa-key-size 4096 --non-interactive --no-eff-email --domain {domain}"
107
107
  if (certificate_for_domain_already_exists):
108
108
  self.__sc.run_program("docker", f"{dockerargument} certonly --no-random-sleep-on-renew {certbotargument}", self.__current_folder)
@@ -35,7 +35,7 @@ from .ProgramRunnerBase import ProgramRunnerBase
35
35
  from .ProgramRunnerPopen import ProgramRunnerPopen
36
36
  from .SCLog import SCLog, LogLevel
37
37
 
38
- version = "4.2.0"
38
+ version = "4.2.2"
39
39
  __version__ = version
40
40
 
41
41
 
@@ -86,7 +86,33 @@ class ScriptCollectionCore:
86
86
  self.run_program("docker",f"push {target_address}")
87
87
 
88
88
  @GeneralUtilities.check_arguments
89
- def get_image_with_registry_for_docker_image(self,image:str,tag:str)->str:
89
+ def registry_contains_image(self,registry_url:str,image:str,registry_username:str,registry_password:str)->bool:
90
+ catalog_url = f"{registry_url}/v2/_catalog"
91
+ response = requests.get(catalog_url, auth=(registry_username, registry_password),timeout=20)
92
+ response.raise_for_status() # check if statuscode = 200
93
+ data = response.json()
94
+ # expected: {"repositories": ["nginx", "myapp"]}
95
+ images = data.get("repositories", [])
96
+ result=image in images
97
+ return result
98
+
99
+ @GeneralUtilities.check_arguments
100
+ def registry_contains_image_with_tag(self,registry_url:str,image:str,tag:str,registry_username:str,registry_password:str)->bool:
101
+ if not self.registry_contains_image(registry_url,image,registry_username,registry_password):
102
+ return False
103
+ tags_url = f"{registry_url}/v2/{image}/tags/list"
104
+ response = requests.get(tags_url, auth=(registry_username, registry_password),timeout=20)
105
+ response.raise_for_status() # check if statuscode = 200
106
+ data=response.json()
107
+ # expected: {"name":"myapp","tags":["1.2.22","1.2.21","1.2.20"]}
108
+ tags = data.get("tags", [])
109
+ result=tag in tags
110
+ return result
111
+
112
+ default_fallback_docker_registry:str="docker.io/library"
113
+
114
+ @GeneralUtilities.check_arguments
115
+ def get_image_with_registry_for_docker_image(self,image:str,tag:str,fallback_registry:str)->str:
90
116
  tag_with_colon:str=None
91
117
  if tag is None:
92
118
  tag_with_colon=""
@@ -96,21 +122,26 @@ class ScriptCollectionCore:
96
122
  docker_image_cache_definition_file=self.__get_docker_image_cache_definition_file()
97
123
  for line in [f.split(";")[0] for f in GeneralUtilities.read_nonempty_lines_from_file(docker_image_cache_definition_file)[1:]]:
98
124
  if line.endswith("/"+image):
99
- result= line+tag_with_colon
125
+ result = line+tag_with_colon
100
126
  #TODO check if docker image is available and if not show warning
101
127
  return result
102
- default_registry:str="docker.io/library"
103
- result= default_registry+"/"+image
104
- self.log.log(f"For image \"{image}\" no cache-registry is defined, so default-registry \"{default_registry}\" will be used instead, which can lead to problems due docker-hub to rate-limits.",LogLevel.Warning)
105
- return result+tag_with_colon
106
-
128
+ if fallback_registry is None:
129
+ raise ValueError(f"For image \"{image}\" no cache-registry and no default-registry is defined.",LogLevel.Warning)
130
+ else:
131
+ return f"{fallback_registry}/{image}{tag_with_colon}"
132
+
107
133
  @GeneralUtilities.check_arguments
108
- def get_docker_build_args_for_base_images(self,dockerfile:str)->list[str]:
134
+ def get_docker_build_args_for_base_images(self,dockerfile:str,fallback_registries:dict[str,str])->list[str]:
109
135
  result=[]
110
136
  GeneralUtilities.assert_file_exists(dockerfile)
137
+ if fallback_registries is None:
138
+ fallback_registries={}
111
139
  required_images=[line.split("_")[1] for line in GeneralUtilities.read_nonempty_lines_from_file(dockerfile) if line.startswith("ARG image_")]
112
140
  for required_image in required_images:
113
- image_with_registry=self.get_image_with_registry_for_docker_image(required_image,None)
141
+ fallback_registry:str=None
142
+ if required_image in fallback_registries:
143
+ fallback_registry=fallback_registries[required_image]
144
+ image_with_registry=self.get_image_with_registry_for_docker_image(required_image,None,fallback_registry)
114
145
  result=result+["--build-arg",f"image_{required_image}={image_with_registry}"]
115
146
  return result
116
147
 
@@ -13,7 +13,7 @@ class TFCPS_CodeUnitSpecific_Docker_Functions(TFCPS_CodeUnitSpecific_Base):
13
13
  super().__init__(current_file, verbosity,targetenvironmenttype,use_cache,is_pre_merge)
14
14
 
15
15
  @GeneralUtilities.check_arguments
16
- def build(self,custom_arguments:dict[str,str]) -> None:
16
+ def build(self,custom_arguments:dict[str,str],fallback_registries:dict[str,str]) -> None:
17
17
 
18
18
  codeunitname: str =self.get_codeunit_name()
19
19
  codeunit_folder =self.get_codeunit_folder()
@@ -22,7 +22,7 @@ class TFCPS_CodeUnitSpecific_Docker_Functions(TFCPS_CodeUnitSpecific_Base):
22
22
  codeunitversion = self.tfcps_Tools_General.get_version_of_codeunit(codeunit_file)
23
23
  args = ["image", "build", "--pull", "--force-rm", "--progress=plain", "--build-arg", f"TargetEnvironmentType={self.get_target_environment_type()}", "--build-arg", f"CodeUnitName={codeunitname}", "--build-arg", f"CodeUnitVersion={codeunitversion}", "--build-arg", f"CodeUnitOwnerName={self.tfcps_Tools_General.get_codeunit_owner_name(self.get_codeunit_file())}", "--build-arg", f"CodeUnitOwnerEMailAddress={self.tfcps_Tools_General.get_codeunit_owner_emailaddress(self.get_codeunit_file())}"]
24
24
  docker_file=os.path.join(self.get_codeunit_folder(),codeunitname,"Dockerfile")
25
- args=args+self._protected_sc.get_docker_build_args_for_base_images(docker_file)
25
+ args=args+self._protected_sc.get_docker_build_args_for_base_images(docker_file,fallback_registries)
26
26
  if custom_arguments is None:
27
27
  custom_arguments=dict[str,str]()
28
28
  for custom_argument_key, custom_argument_value in custom_arguments.items():
@@ -52,7 +52,7 @@ class TFCPS_CodeUnitSpecific_Docker_Functions(TFCPS_CodeUnitSpecific_Base):
52
52
  sbom_folder = os.path.join(artifacts_folder, "BOM")
53
53
  codeunitversion = self.tfcps_Tools_General.get_version_of_codeunit(self.get_codeunit_file())
54
54
  GeneralUtilities.ensure_directory_exists(sbom_folder)
55
- self._protected_sc.run_program_argsasarray("docker", ["run","--rm","-v","/var/run/docker.sock:/var/run/docker.sock","-v","./BOM:/BOM",self._protected_sc.get_image_with_registry_for_docker_image("syft","image"),f"{codeunitname_lower}:{codeunitversion}","-o",f"cyclonedx-xml=/BOM/{codeunitname}.{codeunitversion}.sbom.xml"], artifacts_folder, print_errors_as_information=True)
55
+ self._protected_sc.run_program_argsasarray("docker", ["run","--rm","-v","/var/run/docker.sock:/var/run/docker.sock","-v","./BOM:/BOM",self._protected_sc.get_image_with_registry_for_docker_image("syft","image","docker.io/anchore/syft"),f"{codeunitname_lower}:{codeunitversion}","-o",f"cyclonedx-xml=/BOM/{codeunitname}.{codeunitversion}.sbom.xml"], artifacts_folder, print_errors_as_information=True)
56
56
  self._protected_sc.format_xml_file(sbom_folder+f"/{codeunitname}.{codeunitversion}.sbom.xml")
57
57
 
58
58
  @GeneralUtilities.check_arguments
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ScriptCollection
3
- Version: 4.2.0
3
+ Version: 4.2.2
4
4
  Summary: The ScriptCollection is the place for reusable scripts.
5
5
  Home-page: https://github.com/anionDev/ScriptCollection
6
6
  Author: Marius Göcke
@@ -1,5 +1,5 @@
1
1
  ScriptCollection/AnionBuildPlatform.py,sha256=mohXQ0nQrKoiSggCKPtP591TFkzQ56hxJQTJtORn9KE,10756
2
- ScriptCollection/CertificateUpdater.py,sha256=E2PvU_0jfAvOTfdiI32mhF34GDjXKA3kiW9HzdIIdz4,9248
2
+ ScriptCollection/CertificateUpdater.py,sha256=HGTpQT-MuBw_KW7aHSCOXn0x_9bRIhk6YJq60dGIQPE,9276
3
3
  ScriptCollection/Executables.py,sha256=jK7rj06OHE8l4aZPU1I1SF5HNrX2PUTRh3SON3sFx2k,43167
4
4
  ScriptCollection/GeneralUtilities.py,sha256=w6T4l91-nZwyKrOHfZm4NP1OP1N021bFPr2RFoloC8E,53709
5
5
  ScriptCollection/ImageUpdater.py,sha256=0KPybKb_9IALhSTNflST-mewQVZ4kvXzNtfcN0-Ut8k,29215
@@ -9,7 +9,7 @@ ScriptCollection/ProgramRunnerMock.py,sha256=uTu-aFle1W_oKjeQEmuPsFPQpvo0kRf2FrR
9
9
  ScriptCollection/ProgramRunnerPopen.py,sha256=BPY7-ZMIlqT7JOKz8qlB5c0laF2Js-ijzqk09GxZC48,3821
10
10
  ScriptCollection/ProgramRunnerSudo.py,sha256=_khC3xuTdrPoLluBJZWfldltmmuKltABJPcbjZSFW-4,4835
11
11
  ScriptCollection/SCLog.py,sha256=8TRy1LeYMsPOIuWUcnUNNbO5pd-cNBS-3cn-kdzP8FU,4768
12
- ScriptCollection/ScriptCollectionCore.py,sha256=qtG9F3KwObB-elw85lwbcg_ZHyH3RKwrDem8KV9jQIA,152892
12
+ ScriptCollection/ScriptCollectionCore.py,sha256=h5_HW27_9b3xAq1F0jByePR0e0XU78iABOQOIrnVNrk,154465
13
13
  ScriptCollection/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
14
  ScriptCollection/TFCPS/TFCPS_CodeUnitSpecific_Base.py,sha256=WRFdmkPrzAO9P7ue-5BH1DZfqmGN9yyb2AouFuv2MiI,27712
15
15
  ScriptCollection/TFCPS/TFCPS_CodeUnit_BuildCodeUnit.py,sha256=vnNrwvNePvW2dQhnSusBjgvOssI3a1P3g94bNxNIr3o,8069
@@ -21,7 +21,7 @@ ScriptCollection/TFCPS/TFCPS_MergeToStable.py,sha256=-7ZtiLAUp0vdgnVHhcjX_WQSVR1
21
21
  ScriptCollection/TFCPS/TFCPS_PreBuildCodeunitsScript.py,sha256=f0Uq1cA_4LvmL72cal0crrbKF6PcxL13D9wBKuQ1YBw,2328
22
22
  ScriptCollection/TFCPS/TFCPS_Tools_General.py,sha256=yFWbW51Pt-oEpBlO9Fg8BvSM3bhUmtk__BllgtX6aqI,87785
23
23
  ScriptCollection/TFCPS/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
24
- ScriptCollection/TFCPS/Docker/TFCPS_CodeUnitSpecific_Docker.py,sha256=kDCgxQgs_TUTvxjGMsKoi_53KCVIn5C3Ia1iLzgw1A8,10299
24
+ ScriptCollection/TFCPS/Docker/TFCPS_CodeUnitSpecific_Docker.py,sha256=ol_Ocfj-jl34wSxHeCIFlG8vSdSYRg9PUnJhDeNdq_I,10378
25
25
  ScriptCollection/TFCPS/Docker/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
26
26
  ScriptCollection/TFCPS/DotNet/CertificateGeneratorInformationBase.py,sha256=bT6Gd5pQpZCw4OQz6HWkPCSn5z__eUUEisABLDSxd0o,200
27
27
  ScriptCollection/TFCPS/DotNet/CertificateGeneratorInformationGenerate.py,sha256=QyjOfMY22JWCvKjMelHiDWbJiWqotOfebpJpgDUaoO4,237
@@ -36,8 +36,8 @@ ScriptCollection/TFCPS/NodeJS/TFCPS_CodeUnitSpecific_NodeJS.py,sha256=aXC_f39edp
36
36
  ScriptCollection/TFCPS/NodeJS/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
37
37
  ScriptCollection/TFCPS/Python/TFCPS_CodeUnitSpecific_Python.py,sha256=nLw_eSUd_56jjgfcAvtUyzecSZ14mYmNJl0iu-1YNVk,13496
38
38
  ScriptCollection/TFCPS/Python/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
39
- scriptcollection-4.2.0.dist-info/METADATA,sha256=vzb2Rt3ykSFEDW0_oE1VMAuijVp13yumtdhUCSV7rec,7689
40
- scriptcollection-4.2.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
41
- scriptcollection-4.2.0.dist-info/entry_points.txt,sha256=6Az2eMD7luwGPSdoIhJ1y6ZtgxsfezgJCsFhOnyhnwM,4627
42
- scriptcollection-4.2.0.dist-info/top_level.txt,sha256=hY2hOVH0V0Ce51WB76zKkIWTUNwMUdHo4XDkR2vYVwg,17
43
- scriptcollection-4.2.0.dist-info/RECORD,,
39
+ scriptcollection-4.2.2.dist-info/METADATA,sha256=XmT3BgR6Y2pDcng5_anKCpMEAVO-wvjRFtc4uaDgnaE,7689
40
+ scriptcollection-4.2.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
41
+ scriptcollection-4.2.2.dist-info/entry_points.txt,sha256=6Az2eMD7luwGPSdoIhJ1y6ZtgxsfezgJCsFhOnyhnwM,4627
42
+ scriptcollection-4.2.2.dist-info/top_level.txt,sha256=hY2hOVH0V0Ce51WB76zKkIWTUNwMUdHo4XDkR2vYVwg,17
43
+ scriptcollection-4.2.2.dist-info/RECORD,,