Skip to content

Commit

Permalink
publish_release.py: verify ssh (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
sdarwin authored Jul 25, 2024
1 parent a180ecc commit 0952273
Showing 1 changed file with 67 additions and 36 deletions.
103 changes: 67 additions & 36 deletions publish_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@
s3_archives_bucket = "boost-archives"
aws_profile = "production"

# a default, used later, when "publishing" windows staging/ files
# defaults, used later
stagingPath2 = ""
checksum_succeeded = True


def fileHash(fileName):
Expand All @@ -62,6 +63,7 @@ def fileHash(fileName):


def genJSON(snapshotJSON, fileName, incomingSHA):
global checksum_succeeded
with open(snapshotJSON, "r") as f:
snap = json.load(f)
newJSON = {}
Expand All @@ -74,6 +76,7 @@ def genJSON(snapshotJSON, fileName, incomingSHA):
print("ERROR: Checksum failure for '%s'" % fileName)
print("Recorded: %s" % snap["sha256"])
print("Calculated: %s" % incomingSHA)
checksum_succeeded = False

return newJSON

Expand Down Expand Up @@ -168,6 +171,28 @@ def copyStagingS3():
print(result)


def preflight():
load_dotenv()
SSH_USER = os.getenv("SSH_USER", "mclow")
for origin in ["brorigin1.cpp.al", "brorigin2.cpp.al"]:
result = subprocess.run(
f'ssh {SSH_USER}@{origin} "echo test > test10.txt"',
shell=True,
capture_output=True,
text=True,
)
if result.returncode != 0:
print("SSH FAILED")
print(
"Preflight verification of SSH to the CDN origin servers failed. Check your SSH keys, and set SSH_USER=_username_ in an .env file in the same directory as publish_release.py. The best way to debug is manually SSHing to brorigin1.cpp.al and brorigin2.cpp.al"
)
print(result)
answer = input("Do you want to continue anyway: [y/n]")
if not answer or answer[0].lower() != "y":
print("Exiting.")
exit(1)


#####
usage = "usage: %prog [options] boost_version # Example: %prog 1_85_0"
parser = OptionParser(usage=usage)
Expand Down Expand Up @@ -240,6 +265,8 @@ def copyStagingS3():
parser.print_help()
exit(1)

preflight()

boostVersion = args[0]
dottedVersion = boostVersion.replace("_", ".")
sourceRepo = "main/master/"
Expand Down Expand Up @@ -285,23 +312,27 @@ def copyStagingS3():
with open(jsonFileName, "w", encoding="utf-8") as f:
json.dump(jsonData, f, ensure_ascii=False, indent=0)

if not checksum_succeeded:
exit(1)

# Unzip an archive locally in ~/archives/tmp/ and move it to ~/archives/
archiveDir = str(Path.home()) + "/archives"
archiveDirTmp = str(Path.home()) + "/archives/tmp"
archiveName = actualName + ".tar.gz"
Path(archiveDir).mkdir(parents=True, exist_ok=True)
if os.path.isdir(archiveDirTmp):
shutil.rmtree(archiveDirTmp)
Path(archiveDirTmp).mkdir(parents=True, exist_ok=True)
shutil.copyfile(archiveName, archiveDirTmp + "/" + archiveName)
origDir = os.getcwd()
os.chdir(archiveDirTmp)
os.system("tar -xvf %s" % (archiveName))
os.chdir(archiveDir)
if os.path.isdir(hostedArchiveName):
shutil.rmtree(hostedArchiveName)
shutil.move(archiveDirTmp + "/" + unzippedArchiveName, hostedArchiveName)
os.chdir(origDir)
if not options.dryrun:
archiveDir = str(Path.home()) + "/archives"
archiveDirTmp = str(Path.home()) + "/archives/tmp"
archiveName = actualName + ".tar.gz"
Path(archiveDir).mkdir(parents=True, exist_ok=True)
if os.path.isdir(archiveDirTmp):
shutil.rmtree(archiveDirTmp)
Path(archiveDirTmp).mkdir(parents=True, exist_ok=True)
shutil.copyfile(archiveName, archiveDirTmp + "/" + archiveName)
origDir = os.getcwd()
os.chdir(archiveDirTmp)
os.system("tar -xvf %s" % (archiveName))
os.chdir(archiveDir)
if os.path.isdir(hostedArchiveName):
shutil.rmtree(hostedArchiveName)
shutil.move(archiveDirTmp + "/" + unzippedArchiveName, hostedArchiveName)
os.chdir(origDir)

# Upload the files to JFROG
if options.progress:
Expand Down Expand Up @@ -405,22 +436,22 @@ def copyStagingS3():
f.write("\n")

for origin in ["brorigin1.cpp.al", "brorigin2.cpp.al"]:
try:
result = subprocess.run(
f'ssh {SSH_USER}@{origin} "mkdir -p {source_file_list_dir}; chmod 777 {source_file_list_dir}"',
shell=True,
check=True,
capture_output=True,
text=True,
)
result = subprocess.run(
f"scp -p {source_file_list} {SSH_USER}@{origin}:{source_file_list}",
shell=True,
check=True,
capture_output=True,
text=True,
)
except:
print(
"SSH to the CDN origin servers failed. Check your SSH keys, and set SSH_USER=_username_ in an .env file in the same directory as publish_release.py."
)
result = subprocess.run(
f'ssh {SSH_USER}@{origin} "mkdir -p {source_file_list_dir}; chmod 777 {source_file_list_dir}"',
shell=True,
capture_output=True,
text=True,
)
if result.returncode != 0:
print("SSH FAILED")
print(result)

result = subprocess.run(
f"scp -p {source_file_list} {SSH_USER}@{origin}:{source_file_list}",
shell=True,
capture_output=True,
text=True,
)
if result.returncode != 0:
print("SSH FAILED")
print(result)

0 comments on commit 0952273

Please sign in to comment.