Skip to content
Snippets Groups Projects
Commit de38c9f0 authored by Jonas Höppner's avatar Jonas Höppner
Browse files

CI: Adapt package_release to also deploy artifacts locally

To upload the sdk the local deployment on build host is needed as it is
too big for the uploads.

Move copy functionality to extra function. It also generates md5sum.txt
from the source file's md5sums.
Copy locally (host system) and as gitlab artifact.

Add option to copy doc files ( all .md in given folder).

BCS 746-000262
parent 09eb4bcf
No related branches found
No related tags found
1 merge request!57CI: test local deployment on build host
Pipeline #8418 passed with stages
in 25 seconds
...@@ -5,7 +5,69 @@ import json ...@@ -5,7 +5,69 @@ import json
import os import os
import sys import sys
import shutil import shutil
import subprocess import hashlib
import tempfile
def md5(fname):
hash_md5 = hashlib.md5()
with open(fname, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
hash_md5.update(chunk)
return hash_md5.hexdigest()
def copy_files(files, input_dir, subdir, output_dir, outlocal_dir):
md5sums = {}
if output_dir is not None:
os.makedirs(os.path.join(output_dir, subdir), exist_ok=True)
if outlocal_dir is not None:
os.makedirs(os.path.join(outlocal_dir, subdir), exist_ok=True)
for f in files:
source_file = os.path.join(input_dir, f)
if os.path.exists(source_file):
if output_dir is not None:
target_file = os.path.join(
output_dir, subdir, os.path.basename(source_file)
)
print("Copy: %s -> %s" % (source_file, target_file))
shutil.copyfile(source_file, target_file, follow_symlinks=True)
if outlocal_dir is not None:
target_file = os.path.join(
outlocal_dir, subdir, os.path.basename(source_file)
)
print("Copy: %s -> %s" % (source_file, target_file))
shutil.copyfile(source_file, target_file, follow_symlinks=True)
md5sums[os.path.basename(source_file)] = md5(source_file)
else:
print("Missing: " + source_file)
# Write md5sums file:
with tempfile.TemporaryDirectory() as tmp:
source_file = os.path.join(tmp, subdir, "md5sums.txt")
os.makedirs(os.path.dirname(source_file), exist_ok=True)
with open(source_file, "w") as f_md5:
for f, h in md5sums.items():
f_md5.write("{} {}\n".format(h, f))
if output_dir is not None:
target_file = os.path.join(
output_dir, subdir, os.path.basename(source_file)
)
print("Copy: %s -> %s" % (source_file, target_file))
shutil.copyfile(source_file, target_file, follow_symlinks=True)
if outlocal_dir is not None:
target_file = os.path.join(
outlocal_dir, subdir, os.path.basename(source_file)
)
print("Copy: %s -> %s" % (source_file, target_file))
shutil.copyfile(source_file, target_file, follow_symlinks=True)
def main(): def main():
...@@ -14,7 +76,6 @@ def main(): ...@@ -14,7 +76,6 @@ def main():
"--images-dir", "--images-dir",
help="""Yocto images directory""", help="""Yocto images directory""",
dest="images_dir", dest="images_dir",
required=True,
) )
parser.add_argument( parser.add_argument(
"--release-dir", "--release-dir",
...@@ -27,13 +88,30 @@ def main(): ...@@ -27,13 +88,30 @@ def main():
help="""Yocto sdk directory""", help="""Yocto sdk directory""",
dest="sdk_dir", dest="sdk_dir",
) )
parser.add_argument(
"--doc-dir",
help="""Documentation directory""",
dest="doc_dir",
)
args, _ = parser.parse_known_args() args, _ = parser.parse_known_args()
# Get bitbake variables from testdata.json file # Get bitbake variables from testdata.json file
testdata_files = glob.glob(args.images_dir + "/*.testdata.json") testdata_files = []
if args.images_dir is not None:
testdata_files += glob.glob(args.images_dir + "/*.testdata.json")
if args.sdk_dir is not None:
testdata_files += glob.glob(args.sdk_dir + "/*.testdata.json")
# Debug stuff
if not testdata_files: if not testdata_files:
sys.exit("ERROR: no *.testdata.json file found in images directory") print(args.images_dir)
for f in glob.glob(args.images_dir + "/*"):
print("-- ", f)
print(args.sdk_dir)
for f in glob.glob(args.sdk_dir + "/*"):
print("-- ", f)
sys.exit("ERROR: no *.testdata.json file found in image or sdk dir.")
with open(testdata_files[0], "r") as f: with open(testdata_files[0], "r") as f:
buildvars = json.load(f) buildvars = json.load(f)
...@@ -43,45 +121,41 @@ def main(): ...@@ -43,45 +121,41 @@ def main():
sdkname = buildvars["TOOLCHAIN_OUTPUTNAME"] sdkname = buildvars["TOOLCHAIN_OUTPUTNAME"]
artifacts_image = buildvars["DISTRO_IMAGES"].split() artifacts_image = buildvars["DISTRO_IMAGES"].split()
artifacts_all = buildvars["DISTRO_RELEASE_ARTEFACTS"].split() artifacts_all = buildvars["DISTRO_RELEASE_ARTEFACTS"].split()
artifacts_all.append("BUILD_SRCREVS.log")
# Set directories (use relative path) # Set directories (use relative path)
release_name = "GUF-Yocto-%s" % version release_name = "GUF-Yocto-%s" % version
output_dir = "%s/%s/%s" % (args.release_dir, release_name, machine) # output_dir = "%s/%s/%s" % (args.release_dir, release_name, machine)
images_dir_relative = os.path.relpath(args.images_dir, output_dir) output_dir = os.path.join(args.release_dir, release_name)
# Create output directory # Create output directory
os.makedirs(output_dir, exist_ok=True) os.makedirs(output_dir, exist_ok=True)
# Create symlinks for all images (to reduce size and network load) # local output ( mount on host machine)
for artifact in artifacts_image: release_name_local = "Yocto-%s" % version
source_file = "%s/%s" % (images_dir_relative, artifact) if version.startswith("fngsystem"):
target_file = "%s/%s" % (output_dir, artifact) outlocal_base = "/artifacts-fngsystem"
print("Create link: %s -> %s" % (target_file, source_file)) else:
os.symlink(source_file, target_file) outlocal_base = "/artifacts-yocto"
# outlocal_dir = "%s/%s/%s" % (outlocal_base, release_name_local, machine)
# Copy all other artifacts outlocal_dir = os.path.join(outlocal_base, release_name_local)
for artifact in artifacts_all: os.makedirs(outlocal_dir, exist_ok=True)
if artifact in artifacts_image:
continue if args.doc_dir is not None:
source_file = "%s/%s" % (args.images_dir, artifact) doc_files = glob.glob(args.doc_dir + "/*.md")
target_file = "%s/%s" % (output_dir, artifact) copy_files(doc_files, "", "", output_dir, outlocal_dir)
print("Copy: %s -> %s" % (target_file, source_file))
shutil.copyfile(source_file, target_file, follow_symlinks=True) if args.images_dir is not None:
# Add some additional files to the artifacts
for artifact in artifacts_image:
artifacts_all.append(artifact.split(".")[0] + ".manifest")
artifacts_all.append(artifact.split(".")[0] + ".testdata.json")
copy_files(artifacts_all, args.images_dir, machine, output_dir, outlocal_dir)
# Handle SDK if available # Handle SDK if available
if args.sdk_dir != "": if args.sdk_dir is not None:
sdkfile = "{}.sh".format(sdkname) sdkfiles = glob.glob(args.sdk_dir + sdkname + "*")
sdkfilepath = "{}/{}".format(args.sdk_dir, sdkfile) copy_files(sdkfiles, "", os.path.join(machine, "sdk"), None, outlocal_dir)
sdkoutput_dir = "{}/sdk".format(output_dir)
sdkfile_parts = "{}/{}.part".format(sdkoutput_dir, sdkfile)
if os.path.exists(sdkfilepath):
print("Copy and split SDK from ", sdkfilepath)
os.makedirs(sdkoutput_dir, exist_ok=True)
subprocess.run(
["split", "-b", "512M", sdkfilepath, sdkfile_parts], check=True
)
else:
print("Skipping SDK, not found at ", sdkfilepath)
if __name__ == "__main__": if __name__ == "__main__":
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment