Skip to content

Commit a911fa7

Browse files
Add a python script to release the kubectl-mongodb plugin using goreleaser
Apart from running goreleaser to release the plugin we also need to upload the release artifacts to the S3 bucket. That's what this commit does.
1 parent 4220cee commit a911fa7

File tree

3 files changed

+74
-31
lines changed

3 files changed

+74
-31
lines changed

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

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import os
2-
import subprocess
32
import sys
43

54
import boto3
5+
import utils
66
from botocore.exceptions import ClientError, NoCredentialsError, PartialCredentialsError
77

88
from lib.base_logger import logger
@@ -14,41 +14,18 @@
1414
)
1515

1616
AWS_REGION = "eu-north-1"
17-
KUBECTL_PLUGIN_BINARY_NAME = "kubectl-mongodb"
18-
S3_BUCKET_KUBECTL_PLUGIN_SUBPATH = KUBECTL_PLUGIN_BINARY_NAME
17+
S3_BUCKET_KUBECTL_PLUGIN_SUBPATH = utils.KUBECTL_PLUGIN_BINARY_NAME
1918

2019
GORELEASER_DIST_DIR = "dist"
2120

22-
# LOCAL_KUBECTL_PLUGIN_PATH the full filename where tests image expects the kuebctl-mongodb binary to be available
21+
# LOCAL_KUBECTL_PLUGIN_PATH is the full filename where tests image expects the kuebctl-mongodb binary to be available
2322
LOCAL_KUBECTL_PLUGIN_PATH = "docker/mongodb-kubernetes-tests/multi-cluster-kube-config-creator_linux"
2423

2524

26-
def run_goreleaser():
27-
try:
28-
command = ["./goreleaser", "build", "--snapshot", "--clean", "--skip", "post-hooks"]
29-
30-
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, bufsize=1)
31-
32-
for log in iter(process.stdout.readline, ""):
33-
print(log, end="")
34-
35-
process.stdout.close()
36-
exit_code = process.wait()
37-
38-
if exit_code != 0:
39-
logger.debug(f"GoReleaser command failed with exit code {exit_code}.")
40-
sys.exit(1)
25+
def run_goreleaser_build():
4126

42-
logger.info("GoReleaser build completed successfully!")
43-
44-
except FileNotFoundError:
45-
logger.debug(
46-
"ERROR: 'goreleaser' command not found. Please ensure goreleaser is installed and in your system's PATH."
47-
)
48-
sys.exit(1)
49-
except Exception as e:
50-
logger.debug(f"An unexpected error occurred while running `goreleaser build`: {e}")
51-
sys.exit(1)
27+
command = ["./goreleaser", "build", "--snapshot", "--clean", "--skip", "post-hooks"]
28+
utils.run_goreleaser_command(command)
5229

5330

5431
# upload_artifacts_to_s3 uploads the artifacts that are generated by goreleaser to S3 bucket at a specific path.
@@ -123,9 +100,9 @@ def download_plugin_for_tests_image(build_scenario: BuildScenario, s3_bucket: st
123100

124101
def main():
125102
build_scenario = BuildScenario.infer_scenario_from_environment()
126-
kubectl_plugin_build_info = load_build_info(build_scenario).binaries[KUBECTL_PLUGIN_BINARY_NAME]
103+
kubectl_plugin_build_info = load_build_info(build_scenario).binaries[utils.KUBECTL_PLUGIN_BINARY_NAME]
127104

128-
run_goreleaser()
105+
run_goreleaser_build()
129106

130107
upload_artifacts_to_s3(kubectl_plugin_build_info.s3_store, kubectl_plugin_build_info.version)
131108

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import build_kubectl_plugin
2+
import utils
3+
4+
from scripts.release.build.build_info import (
5+
load_build_info,
6+
)
7+
from scripts.release.build.build_scenario import (
8+
BuildScenario,
9+
)
10+
11+
12+
def run_goreleaser_release():
13+
14+
command = ["./goreleaser", "release", "--clean"]
15+
utils.run_goreleaser_command(command)
16+
17+
18+
# upload_artifacts uploads the artifacts that are generated by the `goreleaser release`
19+
# command to the release S3 bucket.
20+
def upload_artifacts(s3_bucket: str, version: str):
21+
build_kubectl_plugin.upload_artifacts_to_s3(s3_bucket, version)
22+
23+
24+
def main():
25+
run_goreleaser_release()
26+
27+
build_scenario = BuildScenario.infer_scenario_from_environment()
28+
kubectl_plugin_build_info = load_build_info(build_scenario).binaries[utils.KUBECTL_PLUGIN_BINARY_NAME]
29+
30+
upload_artifacts(kubectl_plugin_build_info.s3_store, kubectl_plugin_build_info.version)
31+
32+
33+
if __name__ == "__main__":
34+
main()
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import subprocess
2+
import sys
3+
4+
from lib.base_logger import logger
5+
6+
KUBECTL_PLUGIN_BINARY_NAME = "kubectl-mongodb"
7+
8+
9+
def run_goreleaser_command(command: list[str]):
10+
try:
11+
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, bufsize=1)
12+
13+
for log in iter(process.stdout.readline, ""):
14+
print(log, end="")
15+
16+
process.stdout.close()
17+
exit_code = process.wait()
18+
19+
if exit_code != 0:
20+
logger.debug(f"GoReleaser command failed with exit code {exit_code}.")
21+
sys.exit(1)
22+
23+
logger.info("GoReleaser build completed successfully!")
24+
25+
except FileNotFoundError:
26+
logger.debug(
27+
"ERROR: 'goreleaser' command not found. Please ensure goreleaser is installed and in your system's PATH."
28+
)
29+
sys.exit(1)
30+
except Exception as e:
31+
logger.debug(f"An unexpected error occurred while running `goreleaser build`: {e}")
32+
sys.exit(1)

0 commit comments

Comments
 (0)