From 1faa68b8d7da9cbb525f2f73fd820b7947dd3f1f Mon Sep 17 00:00:00 2001 From: James Liu <37026441+zijianjoy@users.noreply.github.com> Date: Thu, 9 Dec 2021 10:44:55 -0800 Subject: [PATCH] chore: Remove Container Build sample (#7027) --- .../container_build/container_build.ipynb | 232 ------------------ samples/core/container_build/requirements.txt | 1 - .../configs/container_build.config.yaml | 17 -- 3 files changed, 250 deletions(-) delete mode 100644 samples/core/container_build/container_build.ipynb delete mode 100644 samples/core/container_build/requirements.txt delete mode 100644 test/sample-test/configs/container_build.config.yaml diff --git a/samples/core/container_build/container_build.ipynb b/samples/core/container_build/container_build.ipynb deleted file mode 100644 index c2dc8ddc935c..000000000000 --- a/samples/core/container_build/container_build.ipynb +++ /dev/null @@ -1,232 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Copyright 2019 The Kubeflow Authors. All Rights Reserved.\n", - "#\n", - "# Licensed under the Apache License, Version 2.0 (the \"License\");\n", - "# you may not use this file except in compliance with the License.\n", - "# You may obtain a copy of the License at\n", - "#\n", - "# http://www.apache.org/licenses/LICENSE-2.0\n", - "#\n", - "# Unless required by applicable law or agreed to in writing, software\n", - "# distributed under the License is distributed on an \"AS IS\" BASIS,\n", - "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n", - "# See the License for the specific language governing permissions and\n", - "# limitations under the License." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "scrolled": false - }, - "outputs": [], - "source": [ - "# Install Pipeline SDK - This only needs to be ran once in the enviroment. \n", - "!python3 -m pip install 'kfp>=0.1.31' --quiet\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# KubeFlow Pipelines - Container building\n", - "\n", - "In this notebook, we will demo: \n", - "\n", - "* Buiding a container image to use as base image for component\n", - "\n", - "Reference documentation: \n", - "* https://www.kubeflow.org/docs/pipelines/sdk/build-component/\n", - "* https://www.kubeflow.org/docs/pipelines/sdk/sdk-overview/" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Setup" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "tags": [ - "parameters" - ] - }, - "outputs": [], - "source": [ - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Create a python function" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "def add(a: float, b: float) -> float:\n", - " '''Calculates sum of two arguments'''\n", - " \n", - " print(\"Adding two values %s and %s\" %(a, b))\n", - " \n", - " return a + b" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - " ## Build a new container for and use is as the base image for components.\n", - " Build and push a new container image that includes some required packages. The packages are specified in the requirements.txt file in the working directory.\n", - " Use the new container image as the base image for components.\n", - " Create a new component from the above function.\n", - " The return value \"add_op\" represents a step that can be used directly in a pipeline function." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from pathlib import Path\n", - "print(Path('requirements.txt').read_text())" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import kfp\n", - "from kfp.containers import build_image_from_working_dir\n", - "from kfp.components import func_to_container_op" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "scrolled": true - }, - "outputs": [], - "source": [ - "# Building and pushing new container image\n", - "image_with_packages = build_image_from_working_dir(\n", - " #working_dir='.', # Optional. Default is the current directory\n", - " #base_image='google/cloud-sdk:latest', # Optional\n", - " #image_name='gcr.io/my-org/my-image:latest', # Optional. Default is gcr.io///kfp_container\n", - ")\n", - "\n", - "# Creating component while explicitly specifying the newly-built base image\n", - "add_op = func_to_container_op(add, base_image=image_with_packages)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# You can also set up the image builder as default image so that it is always used by default\n", - "kfp.components.default_base_image_or_builder = build_image_from_working_dir\n", - "\n", - "# Or is you want to customize the builder, you can use lambda:\n", - "kfp.components.default_base_image_or_builder = lambda: build_image_from_working_dir(base_image='google/cloud-sdk:latest')\n", - "\n", - "# Now all python components will start using that container builder by default:\n", - "add_op2 = func_to_container_op(add)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Build a pipeline using this component" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import kfp.dsl as dsl\n", - "@dsl.pipeline(\n", - " name='calculation-pipeline',\n", - " description='A sample pipeline that performs arithmetic calculations.'\n", - ")\n", - "def calc_pipeline(\n", - " a='1',\n", - " b='7',\n", - " c='17',\n", - "):\n", - " #Passing pipeline parameter and a constant value as operation arguments\n", - " add_task = add_op(a, b) #Returns a dsl.ContainerOp class instance. \n", - " \n", - " #You can create explicit dependancy between the tasks using xyz_task.after(abc_task)\n", - " add_2_task = add_op(b, c)\n", - " \n", - " add_3_task = add_op(add_task.output, add_2_task.output)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Submit the pipeline for execution" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "arguments = {'a': '7', 'b': '8'}\n", - "kfp.Client().create_run_from_pipeline_func(pipeline_func=calc_pipeline, arguments=arguments)\n", - "\n", - "# This should output link that leads to the run information page. \n", - "# Note: There is a bug in JupyterLab that modifies the URL and makes the link stop working" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.6.8" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/samples/core/container_build/requirements.txt b/samples/core/container_build/requirements.txt deleted file mode 100644 index 18f4bcfb6519..000000000000 --- a/samples/core/container_build/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -google-api-python-client == 1.7.0 diff --git a/test/sample-test/configs/container_build.config.yaml b/test/sample-test/configs/container_build.config.yaml deleted file mode 100644 index be5b63eb4c4a..000000000000 --- a/test/sample-test/configs/container_build.config.yaml +++ /dev/null @@ -1,17 +0,0 @@ -# Copyright 2019 The Kubeflow Authors -# -# 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. - -test_name: container_build -notebook_params: - PROJECT_NAME: ml-pipeline-test