<p>What are the options to download .py files into the execution environment?</p>
<p>In this example:</p>
<pre><code>class Preprocess(dsl.ContainerOp):

  def __init__(self, name, bucket, cutoff_year):
    super(Preprocess, self).__init__(
      name=name,
      # image needs to be a compile-time string
      image='gcr.io/&lt;project&gt;/&lt;image-name&gt;/cpu:v1',
      command=['python3', 'run_preprocess.py'],
      arguments=[
        '--bucket', bucket,
        '--cutoff_year', cutoff_year,
        '--kfp'
      ],
      file_outputs={'blob-path': '/blob_path.txt'}
    )
</code></pre>
<p>run_preprocess.py file is being called from CLI.</p>
<p>The question is: how to get that file <em><strong>in there</strong></em>?</p>
<p>I have seen this interesting example: <a href="https://github.com/benjamintanweihao/kubeflow-mnist/blob/master/pipeline.py" rel="nofollow noreferrer">https://github.com/benjamintanweihao/kubeflow-mnist/blob/master/pipeline.py</a> , and it clones the code before running the pipeline.</p>
<p>The other way would be git cloning with Dockerfile (although the image would take forever to build).</p>
<p>What are other options?</p>

<p>To kickstart KFP development using python, try the following tutorial: <a href="https://github.com/kubeflow/pipelines/blob/master/samples/tutorials/Data%20passing%20in%20python%20components.ipynb" rel="nofollow noreferrer">Data passing in python components</a></p>
<blockquote>
<p>it clones the code before running the pipeline
The other way would be git cloning with Dockerfile (although the image would take forever to build)</p>
</blockquote>
<p>Ideally, the files should be inside the container image (the Dockerfile method). This ensures maximum reproducibility.</p>
<p>For not very complex python scripts, the Lightweight python component feature allows you to create component from a python function. In this case the script code is store in the component command-line, so you do not need to upload the code anywhere.</p>
<p>Putting scripts somewhere remote (e.g. cloud storage or website) is possible, but can reduce reliability and reproducibility.</p>
<p>P.S.</p>
<blockquote>
<p>although the image would take forever to build</p>
</blockquote>
<p>It shouldn't. The first time it might be slow due to having to pull the base image, but after that it should be fast since only the new layers are being pushed. (This requires choosing a good base image that has all dependencies installed, so your Dockerfile only adds your scripts).</p>
