69 lines
1.9 KiB
Python
69 lines
1.9 KiB
Python
# Copyright 2021 kubeflow.org
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
from kfp import dsl
|
|
from kfp.components import load_component_from_text
|
|
from kfp_tekton.tekton import Loop, AnySequencer
|
|
from kfp_tekton.compiler import TektonCompiler
|
|
|
|
|
|
class Coder:
|
|
def empty(self):
|
|
return ""
|
|
|
|
|
|
TektonCompiler._get_unique_id_code = Coder.empty
|
|
|
|
|
|
def PrintOp(name: str, msg: str = None):
|
|
if msg is None:
|
|
msg = name
|
|
print_op = load_component_from_text(
|
|
"""
|
|
name: %s
|
|
inputs:
|
|
- {name: input_text, type: String, description: 'Represents an input parameter.'}
|
|
outputs:
|
|
- {name: output_value, type: String, description: 'Represents an output paramter.'}
|
|
implementation:
|
|
container:
|
|
image: alpine:3.6
|
|
command:
|
|
- sh
|
|
- -c
|
|
- |
|
|
set -e
|
|
echo $0 > $1
|
|
- {inputValue: input_text}
|
|
- {outputPath: output_value}
|
|
""" % (name)
|
|
)
|
|
return print_op(msg)
|
|
|
|
|
|
@dsl.pipeline("any-sequencer-looped")
|
|
def any_sequencer_pipeline(param: list = ["a", "b", "c"]):
|
|
op00 = PrintOp("print-00")
|
|
op01 = PrintOp("print-01")
|
|
AnySequencer([op00, op01], "any-seq-0", statusPath="status")
|
|
|
|
with Loop(param):
|
|
op10 = PrintOp("print-10")
|
|
op11 = PrintOp("print-11")
|
|
AnySequencer([op10, op11], "any-seq-1", statusPath="status")
|
|
|
|
|
|
if __name__ == '__main__':
|
|
TektonCompiler().compile(any_sequencer_pipeline, __file__.replace('.py', '.yaml'))
|