1919
2020GORELEASER_DIST_DIR = "dist"
2121
22- # LOCAL_KUBECTL_PLUGIN_PATH is the full filename where tests image expects the kuebctl-mongodb binary to be available
23- LOCAL_KUBECTL_PLUGIN_PATH = "docker/mongodb-kubernetes-tests/multi-cluster-kube-config-creator_linux"
24-
25-
2622def run_goreleaser ():
2723 try :
2824 command = ["./goreleaser" , "build" , "--snapshot" , "--clean" , "--skip" , "post-hooks" ]
@@ -101,8 +97,19 @@ def s3_path(local_path: str, version: str):
10197 return f"{ S3_BUCKET_KUBECTL_PLUGIN_SUBPATH } /{ version } /{ local_path } "
10298
10399
104- # download_plugin_for_tests_image downloads just the linux amd64 version of the binary and places it
105- # at the location LOCAL_KUBECTL_PLUGIN_PATH.
100+ def s3_and_local_plugin_path (version : str ) -> dict [str , str ]:
101+ s3_common_path = f"{ S3_BUCKET_KUBECTL_PLUGIN_SUBPATH } /{ version } /dist"
102+ local_common_path = "docker/mongodb-kubernetes-tests"
103+ # path in s3 : local path
104+ return {
105+ f"{ s3_common_path } /kubectl-mongodb_linux_amd64_v1/kubectl-mongodb" : f"{ local_common_path } /multi-cluster-kube-config-creator_amd64" ,
106+ f"{ s3_common_path } /kubectl-mongodb_linux_arm64/kubectl-mongodb" : f"{ local_common_path } /multi-cluster-kube-config-creator_arm64" ,
107+ f"{ s3_common_path } /kubectl-mongodb_linux_ppc64le/kubectl-mongodb" : f"{ local_common_path } /multi-cluster-kube-config-creator_ppc64le" ,
108+ f"{ s3_common_path } /kubectl-mongodb_linux_s390x/kubectl-mongodb" : f"{ local_common_path } /multi-cluster-kube-config-creator_s390x" ,
109+ }
110+
111+ # download_plugin_for_tests_image downloads the plugin for all the architectures and places them to the paths configured in
112+ # s3_and_local_plugin_path
106113def download_plugin_for_tests_image (build_scenario : BuildScenario , s3_bucket : str , version : str ):
107114 try :
108115 s3_client = boto3 .client ("s3" , region_name = AWS_REGION )
@@ -111,23 +118,23 @@ def download_plugin_for_tests_image(build_scenario: BuildScenario, s3_bucket: st
111118 sys .exit (1 )
112119
113120 plugin_path = f"{ S3_BUCKET_KUBECTL_PLUGIN_SUBPATH } /{ version } /dist/kubectl-mongodb_linux_amd64_v1/kubectl-mongodb"
114-
115- logger .info (f"Downloading s3://{ s3_bucket } /{ plugin_path } to { LOCAL_KUBECTL_PLUGIN_PATH } " )
116- try :
117- s3_client .download_file (s3_bucket , plugin_path , LOCAL_KUBECTL_PLUGIN_PATH )
118- # change the file's permissions to make file executable
119- os .chmod (LOCAL_KUBECTL_PLUGIN_PATH , 0o755 )
120-
121- logger .info (f"Successfully downloaded artifact to { LOCAL_KUBECTL_PLUGIN_PATH } " )
122- except ClientError as e :
123- if e .response ["Error" ]["Code" ] == "404" :
124- logger .debug (f"ERROR: Artifact not found at s3://{ s3_bucket } /{ plugin_path } " )
125- else :
126- logger .debug (f"ERROR: Failed to download artifact. S3 Client Error: { e } " )
127- sys .exit (1 )
128- except Exception as e :
129- logger .debug (f"An unexpected error occurred during download: { e } " )
130- sys .exit (1 )
121+ for plugin_path , local_path in s3_and_local_plugin_path ( version ). items :
122+ logger .info (f"Downloading s3://{ s3_bucket } /{ plugin_path } to { local_path } " )
123+ try :
124+ s3_client .download_file (s3_bucket , plugin_path , local_path )
125+ # change the file's permissions to make file executable
126+ os .chmod (local_path , 0o755 )
127+
128+ logger .info (f"Successfully downloaded artifact to { local_path } " )
129+ except ClientError as e :
130+ if e .response ["Error" ]["Code" ] == "404" :
131+ logger .debug (f"ERROR: Artifact not found at s3://{ s3_bucket } /{ plugin_path } " )
132+ else :
133+ logger .debug (f"ERROR: Failed to download artifact. S3 Client Error: { e } " )
134+ sys .exit (1 )
135+ except Exception as e :
136+ logger .debug (f"An unexpected error occurred during download: { e } " )
137+ sys .exit (1 )
131138
132139
133140def main ():
@@ -138,9 +145,9 @@ def main():
138145
139146 upload_artifacts_to_s3 (kubectl_plugin_build_info .s3_store , kubectl_plugin_build_info .version )
140147
141- # download_plugin_for_tests_image(
142- # build_scenario, kubectl_plugin_build_info.s3_store, kubectl_plugin_build_info.version
143- # )
148+ download_plugin_for_tests_image (
149+ build_scenario , kubectl_plugin_build_info .s3_store , kubectl_plugin_build_info .version
150+ )
144151
145152
146153if __name__ == "__main__" :
0 commit comments