diff options
Diffstat (limited to 'morphlib/plugins/deploy_plugin.py')
-rw-r--r-- | morphlib/plugins/deploy_plugin.py | 76 |
1 files changed, 11 insertions, 65 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, |