push script: Fix buildx mangled symlinks

This commit is contained in:
Jack O'Sullivan 2021-06-10 20:08:29 +01:00
parent e62d1b19e3
commit 743aa65fbb

View File

@ -90,10 +90,19 @@ class DXF(dxf.DXF):
self.set_manifest(ref, mf, mime=mime)
return size, digest
def fix_slash(info: tarfile.TarInfo):
if info.name == '':
info.name = '.'
return info
def tar_filter(p: Platform):
def f(info: tarfile.TarInfo):
# Ensure there's no directory called '/'
if info.name == '':
info.name = '.'
# buildx messes up symlink targets...
platform_prefix = f'/{p.dirname}'
if info.issym() and info.linkname.startswith(platform_prefix):
info.linkname = info.linkname[len(platform_prefix):]
return info
return f
def main():
parser = argparse.ArgumentParser(description='Construct and push a multiarch Docker plugin')
@ -127,7 +136,7 @@ def main():
with tarfile.open(name=tar_name, mode='w', fileobj=gz) as tar:
path = os.path.join(args.rootfs, p.dirname)
print(f"tar'ing and gzip'ing {path}")
tar.add(path, arcname='', filter=fix_slash)
tar.add(path, arcname='', filter=tar_filter(p))
f.seek(0, os.SEEK_SET)
sha256 = hashlib.sha256()