in google_cloud_automlops/orchestration/kfp.py [0:0]
def build(self):
"""Constructs files for running and managing Kubeflow pipelines.
"""
defaults = read_yaml_file(GENERATED_DEFAULTS_FILE)
self.artifact_repo_location = defaults['gcp']['artifact_repo_location']
self.artifact_repo_name = defaults['gcp']['artifact_repo_name']
self.project_id = defaults['gcp']['project_id']
self.naming_prefix = defaults['gcp']['naming_prefix']
# Set and create directory for components if it does not already exist
component_dir = BASE_DIR + 'components/' + self.name
comp_yaml_path = component_dir + '/component.yaml'
# Build necessary folders
# TODO: make this only happen for the first component or pull into automlops.py
make_dirs([
component_dir,
BASE_DIR + 'components/component_base/src/'])
compspec_image = (
f'''{self.artifact_repo_location}-docker.pkg.dev/'''
f'''{self.project_id}/'''
f'''{self.artifact_repo_name}/'''
f'''{self.naming_prefix}/'''
f'''components/component_base:latest''')
# Write component spec
custom_component = component(func=self.func, base_image=compspec_image)
compiler.Compiler().compile(custom_component, comp_yaml_path)
# Write task script to component base
write_file(
filepath=BASE_DIR + 'components/component_base/src/' + self.name + '.py',
text=render_jinja(
template_path=import_files(KFP_TEMPLATES_PATH + '.components.component_base.src') / 'task.py.j2',
generated_license=GENERATED_LICENSE,
custom_code_contents=self.src_code),
mode='w')
component_spec = read_yaml_file(comp_yaml_path)
# Update component_spec to include correct startup command
component_spec['deploymentSpec']['executors'][f'''exec-{self.name.replace('_', '-')}''']['container']['command'] = [
'python3',
f'''/pipelines/component/src/{self.name + '.py'}''']
# Write license and overwrite component spec to the appropriate component.yaml file
write_file(
filepath=comp_yaml_path,
text=GENERATED_LICENSE,
mode='w')
write_yaml_file(
filepath=comp_yaml_path,
contents=component_spec,
mode='a')