summaryrefslogtreecommitdiff
path: root/morphlib/plugins
diff options
context:
space:
mode:
authorAdam Coldrick <adam.coldrick@codethink.co.uk>2015-03-24 14:16:54 +0000
committerMorph (on behalf of Adam Coldrick) <adam.coldrick@codethink.co.uk>2015-03-24 14:16:54 +0000
commitaa047d1b4ea195c1a5a70568a2b75f958f47fa99 (patch)
tree92ad20301b38f56b0e27506e87d7f5a1dcc6bd0f /morphlib/plugins
parentd1e4fa3639540a51dbb71612bf41a45018f164ea (diff)
downloadmorph-aa047d1b4ea195c1a5a70568a2b75f958f47fa99.tar.gz
Morph build 271da1e1d62c40748b586dc0345d0f7d
System branch: master
Diffstat (limited to 'morphlib/plugins')
-rw-r--r--morphlib/plugins/deploy_plugin.py76
-rw-r--r--morphlib/plugins/gc_plugin.py8
2 files changed, 13 insertions, 71 deletions
diff --git a/morphlib/plugins/deploy_plugin.py b/morphlib/plugins/deploy_plugin.py
index c9890b13..7635a7b4 100644
--- a/morphlib/plugins/deploy_plugin.py
+++ b/morphlib/plugins/deploy_plugin.py
@@ -24,7 +24,6 @@ import uuid
import cliapp
import morphlib
-from morphlib.artifactcachereference import ArtifactCacheReference
class DeployPlugin(cliapp.Plugin):
@@ -440,8 +439,6 @@ class DeployPlugin(cliapp.Plugin):
system_status_prefix = '%s[%s]' % (old_status_prefix, system['morph'])
self.app.status_prefix = system_status_prefix
try:
- system_tree = None
-
# Find the artifact to build
morph = morphlib.util.sanitise_morphology_path(system['morph'])
srcpool = build_command.create_source_pool(build_repo, ref, morph)
@@ -505,9 +502,6 @@ class DeployPlugin(cliapp.Plugin):
system_tree, deploy_location)
finally:
self.app.status_prefix = system_status_prefix
- if system_tree and os.path.exists(system_tree):
- morphlib.fsutils.unmount(self.app.runcmd, system_tree)
- shutil.rmtree(system_tree)
finally:
self.app.status_prefix = old_status_prefix
@@ -541,94 +535,46 @@ class DeployPlugin(cliapp.Plugin):
except morphlib.extensions.ExtensionNotFoundError:
pass
- def checkout_stratum(self, path, artifact, lac, rac):
- with open(lac.get(artifact), 'r') as stratum:
- chunks = [ArtifactCacheReference(c) for c in json.load(stratum)]
- morphlib.builder.download_depends(chunks, lac, rac)
- for chunk in chunks:
- self.app.status(msg='Checkout chunk %(name)s.',
- name=chunk.basename(), chatty=True)
- lac.get(chunk, path)
-
- metadata = os.path.join(path, 'baserock', '%s.meta' % artifact.name)
- with lac.get_artifact_metadata(artifact, 'meta') as meta_src:
- with morphlib.savefile.SaveFile(metadata, 'w') as meta_dst:
- shutil.copyfileobj(meta_src, meta_dst)
-
- def checkout_strata(self, path, artifact, lac, rac):
- deps = artifact.source.dependencies
- morphlib.builder.download_depends(deps, lac, rac)
- for stratum in deps:
- self.checkout_stratum(path, stratum, lac, rac)
- morphlib.builder.ldconfig(self.app.runcmd, path)
-
def setup_deploy(self, build_command, deploy_tempdir, root_repo_dir, ref,
artifact, deployment_type, location, env):
# deployment_type, location and env are only used for saving metadata
- deployment_dir = tempfile.mkdtemp(dir=deploy_tempdir)
-
# Create a tempdir to extract the rootfs in
- system_tree = tempfile.mkdtemp(dir=deployment_dir)
-
- # Create temporary directory for overlayfs
- overlay_dir = os.path.join(deployment_dir,
- '%s-upperdir' % artifact.name)
- if not os.path.exists(overlay_dir):
- os.makedirs(overlay_dir)
- work_dir = os.path.join(deployment_dir, '%s-workdir' % artifact.name)
- if not os.path.exists(work_dir):
- os.makedirs(work_dir)
-
- deploy_tree = os.path.join(deployment_dir,
- 'overlay-deploy-%s' % artifact.name)
+ system_tree = tempfile.mkdtemp(dir=deploy_tempdir)
+
try:
- # Checkout the strata involved in the artifact into a tempdir
- self.app.status(msg='Checking out strata in system')
- self.checkout_strata(system_tree, artifact,
- build_command.lac, build_command.rac)
+ # Unpack the artifact (tarball) to a temporary directory.
+ self.app.status(msg='Unpacking system for configuration')
- self.app.status(msg='Checking out system for configuration')
if build_command.lac.has(artifact):
- build_command.lac.get(artifact, system_tree)
+ f = build_command.lac.get(artifact)
elif build_command.rac.has(artifact):
build_command.cache_artifacts_locally([artifact])
- build_command.lac.get(artifact, system_tree)
+ f = build_command.lac.get(artifact)
else:
raise cliapp.AppException('Deployment failed as system is'
' not yet built.\nPlease ensure'
' the system is built before'
' deployment.')
+ tf = tarfile.open(fileobj=f)
+ tf.extractall(path=system_tree)
self.app.status(
- msg='System checked out at %(system_tree)s',
+ msg='System unpacked at %(system_tree)s',
system_tree=system_tree)
- union_filesystem = self.app.settings['union-filesystem']
- morphlib.fsutils.overlay_mount(self.app.runcmd,
- 'overlay-deploy-%s' %
- artifact.name,
- deploy_tree, system_tree,
- overlay_dir, work_dir,
- union_filesystem)
-
self.app.status(
msg='Writing deployment metadata file')
metadata = self.create_metadata(
artifact, root_repo_dir, deployment_type, location, env)
metadata_path = os.path.join(
- deploy_tree, 'baserock', 'deployment.meta')
+ system_tree, 'baserock', 'deployment.meta')
with morphlib.savefile.SaveFile(metadata_path, 'w') as f:
json.dump(metadata, f, indent=4,
sort_keys=True, encoding='unicode-escape')
- return deploy_tree
+ return system_tree
except Exception:
- if deploy_tree and os.path.exists(deploy_tree):
- morphlib.fsutils.unmount(self.app.runcmd, deploy_tree)
- shutil.rmtree(deploy_tree)
shutil.rmtree(system_tree)
- shutil.rmtree(overlay_dir)
- shutil.rmtree(work_dir)
raise
def run_deploy_commands(self, deploy_tempdir, env, artifact, root_repo_dir,
diff --git a/morphlib/plugins/gc_plugin.py b/morphlib/plugins/gc_plugin.py
index 8b5dc4c2..71522b04 100644
--- a/morphlib/plugins/gc_plugin.py
+++ b/morphlib/plugins/gc_plugin.py
@@ -125,8 +125,8 @@ class GCPlugin(cliapp.Plugin):
'sufficient space already cleared',
chatty=True)
return
- lac = morphlib.ostreeartifactcache.OSTreeArtifactCache(
- os.path.join(cache_path, 'artifacts'))
+ lac = morphlib.localartifactcache.LocalArtifactCache(
+ fs.osfs.OSFS(os.path.join(cache_path, 'artifacts')))
max_age, min_age = self.calculate_delete_range()
logging.debug('Must remove artifacts older than timestamp %d'
% max_age)
@@ -144,8 +144,6 @@ class GCPlugin(cliapp.Plugin):
lac.remove(cachekey)
removed += 1
- lac.prune()
-
# Maybe remove remaining middle-aged artifacts
for cachekey in may_delete:
if sufficient_free():
@@ -159,8 +157,6 @@ class GCPlugin(cliapp.Plugin):
lac.remove(cachekey)
removed += 1
- lac.prune()
-
if sufficient_free():
self.app.status(msg='Made sufficient space in %(cache_path)s '
'after removing %(removed)d sources',