4
4
5
5
import boto3
6
6
from botocore .exceptions import ClientError , NoCredentialsError , PartialCredentialsError
7
+ from mypy .types import ExtraAttrs
7
8
8
9
# from lib.base_logger import logger
9
10
10
- S3_BUCKET_NAME = "mongodb-kubernetes-dev"
11
+ DEV_S3_BUCKET_NAME = "mongodb-kubernetes-dev"
12
+ STAGING_S3_BUCKET_NAME = "mongodb-kubernetes-staging"
13
+ RELEASE_S3_BUCKET_NAME = "mongodb-kubernetes-release"
14
+
11
15
AWS_REGION = "eu-north-1"
12
16
S3_BUCKET_KUBECTL_PLUGIN_SUBPATH = "kubectl-mongodb"
13
17
14
18
COMMIT_SHA_ENV_VAR = "github_commit"
15
19
16
20
GORELEASER_DIST_DIR = "dist"
17
21
22
+ # LOCAL_FILE_PATHis the full filename where tests image expects the kuebctl-mongodb binary to be available
23
+ LOCAL_FILE_PATH = "docker/mongodb-kubernetes-tests/multi-cluster-kube-config-creator_linux"
18
24
19
25
def run_goreleaser ():
20
26
try :
@@ -35,7 +41,7 @@ def run_goreleaser():
35
41
print ("GoReleaser build completed successfully!" )
36
42
37
43
except FileNotFoundError :
38
- print ("ERROR: 'goreleaser' command not found. Please ensure GoReleaser is installed and in your system's PATH." )
44
+ print ("ERROR: 'goreleaser' command not found. Please ensure goreleaser is installed and in your system's PATH." )
39
45
sys .exit (1 )
40
46
except Exception as e :
41
47
print (f"An unexpected error occurred while running `goreleaser build`: { e } " )
@@ -62,10 +68,17 @@ def upload_artifacts_to_s3():
62
68
local_path = os .path .join (root , filename )
63
69
s3_key = s3_path (local_path )
64
70
65
- print (f"Uploading artifact { local_path } to s3://{ S3_BUCKET_NAME } /{ s3_key } " )
71
+ print (f"Uploading artifact { local_path } to s3://{ DEV_S3_BUCKET_NAME } /{ s3_key } " )
72
+
73
+ stat = os .stat (local_path )
74
+ permissions = str (oct (stat .st_mode )[- 3 :])
66
75
67
76
try :
68
- s3_client .upload_file (local_path , S3_BUCKET_NAME , s3_key )
77
+ s3_client .upload_file (local_path , DEV_S3_BUCKET_NAME , s3_key , ExtraArgs = {
78
+ "Metadata" :{
79
+ "posix-permissions" : permissions
80
+ },
81
+ })
69
82
print (f"Successfully uploaded the artifact { filename } " )
70
83
uploaded_files += 1
71
84
except Exception as e :
@@ -75,6 +88,9 @@ def upload_artifacts_to_s3():
75
88
print (f"Successfully uploaded { uploaded_files } kubectl-mongodb plugin artifacts to S3." )
76
89
77
90
91
+ # s3_path returns the path where the artifacts should be uploaded to in S3 obect store.
92
+ # For dev workflows it's going to be `kubectl-mongodb/{evg-patch-id}/{goreleaser-artifact}`,
93
+ # for staging workflows it would be `kubectl-mongodb/{commit-sha}/{goreleaser-artifact}`.
78
94
def s3_path (local_path : str ):
79
95
commit_sha = os .environ .get (COMMIT_SHA_ENV_VAR , "" ).strip ()
80
96
if commit_sha == "" :
@@ -97,17 +113,18 @@ def download_plugin_for_tests_image():
97
113
print ("Error: The commit sha environment variable is not set. It's required to form the S3 Path." )
98
114
sys .exit (1 )
99
115
100
- local_file_path = "docker/mongodb-kubernetes-tests/multi-cluster-kube-config-creator_linux"
101
-
102
- bucket_path = f"{ S3_BUCKET_KUBECTL_PLUGIN_SUBPATH } /{ commit_sha } /dist/kubectl-mongodb_linux_amd64_v1/kubectl-mongodb"
103
- print (f"Downloading s3://{ S3_BUCKET_NAME } /{ bucket_path } to { local_file_path } " )
116
+ plugin_path = f"{ S3_BUCKET_KUBECTL_PLUGIN_SUBPATH } /{ commit_sha } /dist/kubectl-mongodb_linux_amd64_v1/kubectl-mongodb"
104
117
118
+ print (f"Downloading s3://{ DEV_S3_BUCKET_NAME } /{ plugin_path } to { LOCAL_FILE_PATH } " )
105
119
try :
106
- s3_client .download_file (S3_BUCKET_NAME , bucket_path , local_file_path )
107
- print (f"Successfully downloaded artifact to { local_file_path } " )
120
+ s3_client .download_file (DEV_S3_BUCKET_NAME , plugin_path , LOCAL_FILE_PATH )
121
+ # change the file's permissions so that it can be executed
122
+ os .chmod (LOCAL_FILE_PATH , 0o755 )
123
+
124
+ print (f"Successfully downloaded artifact to { LOCAL_FILE_PATH } " )
108
125
except ClientError as e :
109
126
if e .response ['Error' ]['Code' ] == '404' :
110
- print (f"ERROR: Artifact not found at s3://{ S3_BUCKET_NAME } /{ bucket_path } " )
127
+ print (f"ERROR: Artifact not found at s3://{ DEV_S3_BUCKET_NAME } /{ plugin_path } " )
111
128
else :
112
129
print (f"ERROR: Failed to download artifact. S3 Client Error: { e } " )
113
130
except Exception as e :
0 commit comments