Skip to content

Commit e669527

Browse files
Make file executable after downloading it from s3
1 parent 54615f9 commit e669527

File tree

2 files changed

+28
-17
lines changed

2 files changed

+28
-17
lines changed

.goreleaser.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,3 @@ release:
5151

5252
git:
5353
tag_sort: -version:creatordate
54-
55-
blobs:
56-
- provider: s3
57-
region: eu-north-1
58-
bucket: mongodb-kubernetes-dev
59-
directory: test-dir

scripts/release/kubectl-mongodb/python/build_kubectl_plugin.py

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,23 @@
44

55
import boto3
66
from botocore.exceptions import ClientError, NoCredentialsError, PartialCredentialsError
7+
from mypy.types import ExtraAttrs
78

89
# from lib.base_logger import logger
910

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+
1115
AWS_REGION = "eu-north-1"
1216
S3_BUCKET_KUBECTL_PLUGIN_SUBPATH = "kubectl-mongodb"
1317

1418
COMMIT_SHA_ENV_VAR = "github_commit"
1519

1620
GORELEASER_DIST_DIR = "dist"
1721

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"
1824

1925
def run_goreleaser():
2026
try:
@@ -35,7 +41,7 @@ def run_goreleaser():
3541
print("GoReleaser build completed successfully!")
3642

3743
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.")
3945
sys.exit(1)
4046
except Exception as e:
4147
print(f"An unexpected error occurred while running `goreleaser build`: {e}")
@@ -62,10 +68,17 @@ def upload_artifacts_to_s3():
6268
local_path = os.path.join(root, filename)
6369
s3_key = s3_path(local_path)
6470

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:])
6675

6776
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+
})
6982
print(f"Successfully uploaded the artifact {filename}")
7083
uploaded_files += 1
7184
except Exception as e:
@@ -75,6 +88,9 @@ def upload_artifacts_to_s3():
7588
print(f"Successfully uploaded {uploaded_files} kubectl-mongodb plugin artifacts to S3.")
7689

7790

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}`.
7894
def s3_path(local_path: str):
7995
commit_sha = os.environ.get(COMMIT_SHA_ENV_VAR, "").strip()
8096
if commit_sha == "":
@@ -97,17 +113,18 @@ def download_plugin_for_tests_image():
97113
print("Error: The commit sha environment variable is not set. It's required to form the S3 Path.")
98114
sys.exit(1)
99115

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"
104117

118+
print(f"Downloading s3://{DEV_S3_BUCKET_NAME}/{plugin_path} to {LOCAL_FILE_PATH}")
105119
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}")
108125
except ClientError as e:
109126
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} ")
111128
else:
112129
print(f"ERROR: Failed to download artifact. S3 Client Error: {e}")
113130
except Exception as e:

0 commit comments

Comments
 (0)