Exemplo n.º 1
0
    def setUp(self):
        self._repo_dir_tmp = tempfile.TemporaryDirectory('repo')
        self._repo_dir = self._repo_dir_tmp.name
        self._factory = 'test_factory'
        self._branch = 'master'
        self._arch = 'amd64'

        self._ostree_repo = OSTreeRepo(self._repo_dir, create=True)
Exemplo n.º 2
0
    def __init__(self, factory, token, creds, targets, arch_ostree_store,
                 fetch_root_dir, treehub_repo_dir):

        self._creds = creds
        self._arch_ostree_store = arch_ostree_store
        self._fetcher = TargetAppsFetcher(token,
                                          fetch_root_dir,
                                          factory=factory)
        self._treehub_repo = OSTreeRepo(treehub_repo_dir, create=True)
        self._targets = targets
        self._fetched_targets = []
Exemplo n.º 3
0
 def setUp(self):
     self._repo_dir_tmp = tempfile.TemporaryDirectory('repo')
     self._repo_dir = self._repo_dir_tmp.name
     self._app_tree = OSTreeRepo(self._repo_dir, create=True)
     self._app_tree_store = OSTreeTargetAppsStore(self._repo_dir,
                                                  factory='factory-01')
     self._target = FactoryClient.Target(
         'target-01', OSTreeTargetAppsStoreTest.DefaultTarget)
Exemplo n.º 4
0
def copy_container_images_to_wic(target: FactoryClient.Target, factory: str,
                                 ostree_repo_archive_dir: str, app_repo_dir,
                                 app_fetch_dir: str, wic_image: str,
                                 token: str, apps_shortlist: list,
                                 progress: Progress):

    p = Progress(2, progress)
    target_app_store = ArchOSTreeTargetAppsStore(factory,
                                                 ostree_repo_archive_dir,
                                                 app_repo_dir)
    target.shortlist = apps_shortlist
    if not target_app_store.exist(target):
        logger.info('Compose Apps haven\'t been found, fetching them...')
        apps_fetcher = TargetAppsFetcher(token, app_fetch_dir)
        if target_app_store.exist_branch(target):
            target_app_store.checkout(target,
                                      apps_fetcher.target_dir(target.name))
        apps_fetcher.fetch_target(target, force=True)
        target.apps_uri = target_app_store.store(
            target, apps_fetcher.target_dir(target.name))
    p.tick()

    with TemporaryDirectory(dir=os.getenv('HOME', '/root')) as tmp_tree_dir:
        # TODO: make use of the commit size generation functionality to determine a size to extend a wic image for
        logger.info('Building an ostree repo for the given Target...')
        os.makedirs(tmp_tree_dir, exist_ok=True)
        tmp_tree_repo = OSTreeRepo(tmp_tree_dir, 'bare', create=True)
        p.tick()
        target_app_store.copy(target, tmp_tree_repo)
        p.tick()

        with WicImage(wic_image,
                      tmp_tree_repo.size_in_kbs() * 1024) as wic_image:
            logger.info('Removing previously preloaded Apps if any...')

            shutil.rmtree(wic_image.docker_data_root, ignore_errors=True)
            shutil.rmtree(wic_image.compose_apps_root, ignore_errors=True)
            shutil.rmtree(wic_image.compose_apps_tree, ignore_errors=True)
            p.tick()
            target_app_store.copy_and_checkout(target,
                                               wic_image.compose_apps_tree,
                                               wic_image.compose_apps_root,
                                               wic_image.docker_data_root)
            wic_image.update_target(target)
    p.tick()
Exemplo n.º 5
0
class TargetPublisher:
    def __init__(self, factory, token, creds, targets, arch_ostree_store,
                 fetch_root_dir, treehub_repo_dir):

        self._creds = creds
        self._arch_ostree_store = arch_ostree_store
        self._fetcher = TargetAppsFetcher(token,
                                          fetch_root_dir,
                                          factory=factory)
        self._treehub_repo = OSTreeRepo(treehub_repo_dir, create=True)
        self._targets = targets
        self._fetched_targets = []

    def fetch_targets(self):
        logging.info('Fetching Targets\' Apps ...')
        for target in self._targets:
            # make use of the existing apps' images stored in the ostree repo to minimize downloads
            # from docker registries, both the foundries' and hub.docker.io or any other
            if self._arch_ostree_store.exist_branch(target):
                self._arch_ostree_store.checkout(
                    target, self._fetcher.target_dir(target.name))

            self._fetcher.fetch_target(target, force=True)
            target.apps_uri = self._arch_ostree_store.store(
                target, self._fetcher.target_dir(target.name))
            self._fetched_targets.append(target)

    def publish_targets(self):
        logging.info('Publishing Targets\' Apps ...')
        for target in self._fetched_targets:
            self._treehub_repo.pull_local(
                self._arch_ostree_store.dir,
                self._arch_ostree_store.branch(target))
            logger.info(
                'Pushing Compose Apps to Treehub, ref: {}, uri: {} ...'.format(
                    self._arch_ostree_store.branch(target), target.apps_uri))
            subprocess.check_call([
                'garage-push', '--repo', self._treehub_repo.dir,
                '--credentials', self._creds, '--ref', target.apps_commit_hash,
                '--jobs', '60'
            ],
                                  timeout=12000)
Exemplo n.º 6
0
class OSTreeTest(unittest.TestCase):
    def setUp(self):
        self._repo_dir_tmp = tempfile.TemporaryDirectory('repo')
        self._repo_dir = self._repo_dir_tmp.name
        self._factory = 'test_factory'
        self._branch = 'master'
        self._arch = 'amd64'

        self._ostree_repo = OSTreeRepo(self._repo_dir, create=True)

    def tearDown(self) -> None:
        self._repo_dir_tmp.cleanup()

    def test_create_destroy(self):
        self.assertTrue(self._ostree_repo.initialized())

    def test_create_destroy_instance(self):
        self.assertTrue(self._ostree_repo.initialized())
        read_ostree_repo = OSTreeRepo(self._repo_dir)
        self.assertTrue(read_ostree_repo.initialized())

    def test_create_destroy_instance_negative(self):
        with tempfile.TemporaryDirectory() as tree_dir:
            with self.assertRaises(Exception) as ctx:
                OSTreeRepo(tree_dir)
            self.assertNotEqual(
                str(ctx.exception).find('Failed to create OSTree repo'), -1)

    def test_commit(self):
        with tempfile.TemporaryDirectory() as tree_dir:
            test_file_name = 'test_file.txt'
            test_file_content = 'some data'
            with open(os.path.join(tree_dir, test_file_name),
                      'w') as test_file:
                test_file.write(test_file_content)

            branch = 'org.foundries.io/{}/{}/{}'.format(
                self._factory, self._branch, self._arch)
            hash = self._ostree_repo.commit(tree_dir, branch)
            self.assertEqual(branch, self._ostree_repo.refs())
            self.assertEqual(hash, self._ostree_repo.rev_parse(branch))
            self.assertEqual(test_file_content,
                             self._ostree_repo.cat(hash, test_file_name))
            self.assertEqual(self._ostree_repo.size_in_kbs(), 92)
Exemplo n.º 7
0
 def test_create_destroy_instance_negative(self):
     with tempfile.TemporaryDirectory() as tree_dir:
         with self.assertRaises(Exception) as ctx:
             OSTreeRepo(tree_dir)
         self.assertNotEqual(
             str(ctx.exception).find('Failed to create OSTree repo'), -1)
Exemplo n.º 8
0
 def test_create_destroy_instance(self):
     self.assertTrue(self._ostree_repo.initialized())
     read_ostree_repo = OSTreeRepo(self._repo_dir)
     self.assertTrue(read_ostree_repo.initialized())