コード例 #1
0
ファイル: commands.py プロジェクト: adamchainz/kozmic-ci
def clean_dependencies_cache(verbose=True):
    images_by_projects = collections.defaultdict(list)
    limit = flask.current_app.config['KOZMIC_CACHED_IMAGES_LIMIT']

    for image_data in docker.images():
        created_at = image_data['Created']

        for repo_tag in image_data['RepoTags']:
            if not repo_tag.startswith('kozmic-cache/'):
                continue

            try:
                repository, tag = repo_tag.split(':')
            except ValueError:
                continue

            try:
                project_id = int(tag)
            except ValueError:
                continue

            images_by_projects[project_id].append((created_at, image_data['Id']))
            break

    for project_id, timestamped_images in images_by_projects.iteritems():
        images_to_remove = [image for _, image in
                            sorted(timestamped_images)[:-limit]]
        for image in images_to_remove:
            docker.remove_image(image)
            logger.info('Removed %s', image)
コード例 #2
0
ファイル: commands.py プロジェクト: pombredanne/kozmic-ci
def clean_dependencies_cache(verbose=True):
    images_by_projects = collections.defaultdict(list)
    limit = flask.current_app.config['KOZMIC_CACHED_IMAGES_LIMIT']

    for image_data in docker.images():
        created_at = image_data['Created']

        for repo_tag in image_data['RepoTags']:
            if not repo_tag.startswith('kozmic-cache/'):
                continue

            try:
                repository, tag = repo_tag.split(':')
            except ValueError:
                continue

            try:
                project_id = int(tag)
            except ValueError:
                continue

            images_by_projects[project_id].append(
                (created_at, image_data['Id']))
            break

    for project_id, timestamped_images in images_by_projects.iteritems():
        images_to_remove = [
            image for _, image in sorted(timestamped_images)[:-limit]
        ]
        for image in images_to_remove:
            docker.remove_image(image)
            logger.info('Removed %s', image)
コード例 #3
0
ファイル: do_job_tests.py プロジェクト: adamchainz/kozmic-ci
    def test_private_project(self):
        cache_id = 'qwerty'
        cached_image = 'kozmic-cache/{}'.format(cache_id)

        try:
            for image_data in docker.images(cached_image):
                for repo_tag in image_data['RepoTags']:
                    if repo_tag.startswith(cached_image):
                        docker.remove_image(image_data['Id'])
                        break
        except:
            pass
        assert not docker.images(cached_image)

        build = factories.BuildFactory.create(
            project=self.project,
            gh_commit_sha=self.prev_head_sha)
        hook_call = factories.HookCallFactory.create(
            hook=self.hook,
            build=build)

        job = self._do_job(hook_call)
        assert job.return_code == 0
        assert job.stdout == (
            'Pulling "{}" Docker image...\n'
             'installed!\nit works\nYEAH\n'.format(self.hook.docker_image))
        assert docker.images(cached_image)

        build = factories.BuildFactory.create(
            project=self.project,
            gh_commit_sha=self.head_sha)
        hook_call = factories.HookCallFactory.create(
            hook=self.hook,
            build=build)

        job = self._do_job(hook_call)
        assert job.return_code == 0
        assert job.stdout == (
            'Pulling "{}" Docker image...\n'
            'Skipping install script as tracked files did not change...\n'
            'it works\n'
            'YEAH\n'.format(self.hook.docker_image))
コード例 #4
0
    def test_private_project(self):
        cache_id = 'qwerty'
        cached_image = 'kozmic-cache/{}'.format(cache_id)

        try:
            for image_data in docker.images(cached_image):
                for repo_tag in image_data['RepoTags']:
                    if repo_tag.startswith(cached_image):
                        docker.remove_image(image_data['Id'])
                        break
        except:
            pass
        assert not docker.images(cached_image)

        build = factories.BuildFactory.create(
            project=self.project,
            gh_commit_sha=self.prev_head_sha)
        hook_call = factories.HookCallFactory.create(
            hook=self.hook,
            build=build)

        job = self._do_job(hook_call)
        assert job.return_code == 0
        assert job.stdout == (
            'Pulling "{}" Docker image...\n'
             'installed!\nit works\nYEAH\n'.format(self.hook.docker_image))
        assert docker.images(cached_image)

        build = factories.BuildFactory.create(
            project=self.project,
            gh_commit_sha=self.head_sha)
        hook_call = factories.HookCallFactory.create(
            hook=self.hook,
            build=build)

        job = self._do_job(hook_call)
        assert job.return_code == 0
        assert job.stdout == (
            'Pulling "{}" Docker image...\n'
            'Skipping install script as tracked files did not change...\n'
            'it works\n'
            'YEAH\n'.format(self.hook.docker_image))