Prima implementazione controllo build remota e caricamento con rsync + ssh.

This commit is contained in:
Emiliano Vavassori 2023-01-05 01:07:12 +01:00
parent 2c19eefa05
commit df5012eedd
2 changed files with 69 additions and 20 deletions

View File

@ -32,6 +32,9 @@ class Build(loaih.RemoteBuild):
self.portable = False self.portable = False
self.updatable = True self.updatable = True
self.sign = True self.sign = True
self.remoterepo = False
self.remote_host = ''
self.remote_path = ''
self.storage_path = '/mnt/appimage' self.storage_path = '/mnt/appimage'
self.download_path = '/var/tmp/downloads' self.download_path = '/var/tmp/downloads'
@ -105,10 +108,29 @@ class Build(loaih.RemoteBuild):
def check(self): def check(self):
"""Checking if the requested AppImage has been already built.""" """Checking if the requested AppImage has been already built."""
if not len(self.appimagefilename) == 2: if len(self.appimagefilename) != 2:
self.calculate() self.calculate()
for arch in self.arch: for arch in self.arch:
# First, check if by metadata the repo is remote or not.
if self.remoterepo or 'http' in self.storage_path:
self.remoterepo = True
# Remote storage. I have to query a remote site to know if it
# was already built.
name = self.appimagefilename[arch]
matching = etree.HTML(urllib.request.urlopen(str.join('/',
self.relative_path.insert(0, self.storage_path)
)).read()).xpath(
f"//a[contains(@href, '{name}')/@href"
)
if len(matching) > 0:
# Already built.
self.built[arch] = True
else:
# Repo is local
print(f"Searching for {self.appimagefilename[arch]}") print(f"Searching for {self.appimagefilename[arch]}")
res = subprocess.run(shlex.split(f"find {self.full_path} -name {self.appimagefilename[arch]}"), capture_output=True, env={ "LC_ALL": "C" }, text=True, encoding='utf-8') res = subprocess.run(shlex.split(f"find {self.full_path} -name {self.appimagefilename[arch]}"), capture_output=True, env={ "LC_ALL": "C" }, text=True, encoding='utf-8')
@ -309,13 +331,33 @@ class Build(loaih.RemoteBuild):
return return
os.chdir(self.appnamedir) os.chdir(self.appnamedir)
# Two cases here: local and remote storage_path.
if self.remoterepo:
# Remote first.
# Build destination directory
if len(self.relative_path) > 0:
remotepath = str.join('/', self.relative_path.insert(0, self.remote_path))
else:
remotepath = str.join('/', [ self.remote_path, '' ])
try:
subprocess.run(
shlex.split(
f"rsync -avz -e ssh *.AppImage* {self.remote_host}:{remotepath}"
)
)
finally:
pass
else:
# Local
# Forcing creation of subfolders, in case there is a new build # Forcing creation of subfolders, in case there is a new build
os.makedirs(self.full_path, exist_ok = True) os.makedirs(self.full_path, exist_ok = True)
for file in glob.glob("*.AppImage*"): for file in glob.glob("*.AppImage*"):
subprocess.run(shlex.split(f"cp -f {file} {self.full_path}")) subprocess.run(shlex.split(f"cp -f {file} {self.full_path}"))
def generalize_and_link(self): def generalize_and_link(self, chdir = self.full_path):
"""Creates the needed generalized files if needed.""" """Creates the needed generalized files if needed."""
# If called with a pointed version, no generalize and link necessary. # If called with a pointed version, no generalize and link necessary.
if not self.branch_version: if not self.branch_version:
@ -335,7 +377,7 @@ class Build(loaih.RemoteBuild):
if self.built[arch]: if self.built[arch]:
continue continue
os.chdir(self.full_path) os.chdir(chdir)
# if the appimage for the reported arch is not found, skip to next # if the appimage for the reported arch is not found, skip to next
# arch # arch
if not os.path.exists(self.appimagefilename[arch]): if not os.path.exists(self.appimagefilename[arch]):

View File

@ -71,6 +71,10 @@ def build(arch, language, offline, portable, updatable, download_path, repo_path
obj.updatable = True obj.updatable = True
obj.storage_path = config['data']['repo'] if 'repo' in config['data'] and config['data']['repo'] else '/srv/http/appimage.sys42.eu' obj.storage_path = config['data']['repo'] if 'repo' in config['data'] and config['data']['repo'] else '/srv/http/appimage.sys42.eu'
obj.download_path = config['data']['download'] if 'download' in config['data'] and config['data']['download'] else '/var/tmp/downloads' obj.download_path = config['data']['download'] if 'download' in config['data'] and config['data']['download'] else '/var/tmp/downloads'
if 'http' in obj.storage_path:
obj.remoterepo = True
obj.remote_host = config['data']['remote_host'] if 'remote_host' in config['data'] and config['data']['remote_host'] else 'ciccio.libreitalia.org'
obj.remote_path = config['data']['remote_path'] if 'remote_path' in config['data'] and config['data']['remote_path'] else '/var/lib/nethserver/vhost/appimages'
if 'sign' in config['data'] and config['data']['sign']: if 'sign' in config['data'] and config['data']['sign']:
obj.sign = True obj.sign = True
@ -83,7 +87,10 @@ def build(arch, language, offline, portable, updatable, download_path, repo_path
obj.download() obj.download()
obj.build() obj.build()
obj.checksums() obj.checksums()
if obj.remoterepo:
obj.generalize_and_link(obj.appnamedir)
obj.publish() obj.publish()
if not obj.remoterepo:
obj.generalize_and_link() obj.generalize_and_link()
del obj del obj