Exemplo n.º 1
0
    def __init__(self,
                 build_job,
                 repo_path,
                 from_image,
                 copy_code=True,
                 build_steps=None,
                 env_vars=None,
                 dockerfile_name='Dockerfile'):
        self.build_job = build_job
        self.job_uuid = build_job.uuid.hex
        self.job_name = build_job.unique_name
        self.from_image = from_image
        self.image_name = get_image_name(self.build_job)
        self.image_tag = self.job_uuid
        self.folder_name = repo_path.split('/')[-1]
        self.repo_path = repo_path
        self.copy_code = copy_code

        self.build_path = '/'.join(self.repo_path.split('/')[:-1])
        self.build_steps = get_list(build_steps)
        self.env_vars = get_list(env_vars)
        self.dockerfile_path = os.path.join(self.build_path, dockerfile_name)
        self.polyaxon_requirements_path = self._get_requirements_path()
        self.polyaxon_setup_path = self._get_setup_path()
        self.docker = APIClient(version='auto')
        self.registry_host = None
        self.docker_url = None
Exemplo n.º 2
0
    def __init__(self,
                 build_job,
                 repo_path,
                 from_image,
                 copy_code=True,
                 build_steps=None,
                 env_vars=None,
                 dockerfile_name='Dockerfile'):
        self.build_job = build_job
        self.job_uuid = build_job.uuid.hex
        self.job_name = build_job.unique_name
        self.from_image = from_image
        self.image_name = get_image_name(self.build_job)
        self.image_tag = self.job_uuid
        self.folder_name = repo_path.split('/')[-1]
        self.repo_path = repo_path
        self.copy_code = copy_code

        self.build_path = '/'.join(self.repo_path.split('/')[:-1])
        self.build_steps = get_list(build_steps)
        self.env_vars = get_list(env_vars)
        self.dockerfile_path = os.path.join(self.build_path, dockerfile_name)
        self.polyaxon_requirements_path = self._get_requirements_path()
        self.polyaxon_setup_path = self._get_setup_path()
        self.docker = APIClient(version='auto')
        self.registry_host = None
        self.docker_url = None
Exemplo n.º 3
0
    def __init__(self,
                 build_job: 'BuildJob',
                 repo_path: str,
                 from_image: str,
                 copy_code: bool = True,
                 build_steps: Optional[List[str]] = None,
                 env_vars: Optional[List[Tuple[str, str]]] = None,
                 dockerfile_name: str = 'Dockerfile') -> None:
        self.build_job = build_job
        self.job_uuid = build_job.uuid.hex
        self.job_name = build_job.unique_name
        self.from_image = from_image
        self.image_name = get_image_name(self.build_job)
        self.image_tag = self.job_uuid
        self.folder_name = repo_path.split('/')[-1]
        self.repo_path = repo_path
        self.copy_code = copy_code

        self.build_path = '/'.join(self.repo_path.split('/')[:-1])
        self.build_steps = to_list(build_steps, check_none=True)
        self.env_vars = to_list(env_vars, check_none=True)
        self.dockerfile_path = os.path.join(self.build_path, dockerfile_name)
        self.polyaxon_requirements_path = self._get_requirements_path()
        self.polyaxon_setup_path = self._get_setup_path()
        self.docker = APIClient(version='auto')
        self.registry_host = None
        self.docker_url = None
        self.is_pushing = False
Exemplo n.º 4
0
def start_dockerizer(build_job):
    # Update job status to show that its started
    build_job.set_status(JobLifeCycle.SCHEDULED)
    spawner_class = get_spawner_class(build_job.backend)

    local_build = build_job.backend in {BuildBackend.NATIVE, None}

    spawner = spawner_class(
        project_name=build_job.project.unique_name,
        project_uuid=build_job.project.uuid.hex,
        job_name=build_job.unique_name,
        job_uuid=build_job.uuid.hex,
        commit=build_job.commit,
        from_image=build_job.build_image,
        dockerfile_path=build_job.build_dockerfile,
        context_path=build_job.build_context,
        image_tag=build_job.uuid.hex,
        image_name=get_image_name(build_job, local=local_build),
        build_steps=build_job.build_steps,
        env_vars=build_job.build_env_vars,
        nocache=build_job.build_nocache,
        in_cluster_registry=conf.get('REGISTRY_IN_CLUSTER'),
        spec=build_job.specification,
        k8s_config=conf.get('K8S_CONFIG'),
        namespace=conf.get('K8S_NAMESPACE'),
        in_cluster=True,
        use_sidecar=True)

    error = {}
    try:
        results = spawner.start_dockerizer(
            resources=build_job.resources,
            node_selector=build_job.node_selector,
            affinity=build_job.affinity,
            tolerations=build_job.tolerations)
        auditor.record(event_type=BUILD_JOB_STARTED, instance=build_job)
        build_job.definition = get_job_definition(results)
        build_job.save(update_fields=['definition'])
        return True
    except ApiException:
        _logger.error(
            'Could not start build job, please check your polyaxon spec',
            exc_info=True)
        error = {
            'raised':
            True,
            'traceback':
            traceback.format_exc(),
            'message':
            'Could not start build job, encountered a Kubernetes ApiException.'
        }
    except VolumeNotFoundError as e:
        _logger.error(
            'Could not start build job, please check your volume definitions.',
            exc_info=True)
        error = {
            'raised':
            True,
            'traceback':
            traceback.format_exc(),
            'message':
            'Could not start build job, encountered a volume definition problem. %s'
            % e
        }
    except Exception as e:
        _logger.error(
            'Could not start build job, please check your polyaxon spec.',
            exc_info=True)
        error = {
            'raised':
            True,
            'traceback':
            traceback.format_exc(),
            'message':
            'Could not start build job encountered an {} exception.'.format(
                e.__class__.__name__)
        }
    finally:
        if error.get('raised'):
            build_job.set_status(JobLifeCycle.FAILED,
                                 message=error.get('message'),
                                 traceback=error.get('traceback'))
Exemplo n.º 5
0
 def test_get_image_image_info(self):
     image_info = get_image_info(self.build_job)
     assert image_info[0] == get_image_name(self.build_job)
     assert image_info[1] == self.build_job.uuid.hex
Exemplo n.º 6
0
 def test_get_image_name(self):
     image_name = get_image_name(self.build_job)
     expected_name = '{}/{}'.format(settings.REGISTRY_HOST,
                                    self.build_job.project.name)
     assert image_name == expected_name
Exemplo n.º 7
0
 def test_get_image_name(self):
     image_name = get_image_name(self.build_job)
     expected_name = '{}/{}_{}'.format(conf.get('REGISTRY_URI'),
                                       self.build_job.project.name,
                                       self.build_job.project.id)
     assert image_name == expected_name
Exemplo n.º 8
0
 def test_get_image_image_info(self):
     image_info = get_image_info(self.build_job)
     assert image_info[0] == get_image_name(self.build_job)
     assert image_info[1] == self.build_job.uuid.hex
Exemplo n.º 9
0
 def test_get_image_name(self):
     image_name = get_image_name(self.build_job)
     expected_name = '{}/{}'.format(settings.REGISTRY_HOST, self.build_job.project.name)
     assert image_name == expected_name