Code Monkey home page Code Monkey logo

cicd-notebooks-aiplatform's Introduction

Fully Configured Example of CI/CD for Notebooks on Top of Google Cloud Platform

This repository includes a fully functional continuous integration and continuous deployment system for Jupyter Notebooks.

The goal of this repository is to showcase what can be built using notebook-centric development practices, and we aim for it to be a reference implementation for those who want to develop similar systems on Google Cloud. For the purposes of this example, we have created the sample notebook demo.ipynb, which takes in a bigquery dataset to generate a usage dashboard, and have set up automated testing and deployment for this notebook.

Each individual file has been documented with an explanation of its use in the CI+CD system, and we will cover the architecture below.

GCP Services

In our setup, we have leveraged the following services/products of Google Cloud Platform:

Core services:

Extra glue (may vary depending on your setup):

Continuous Integration (CI)

Overview of CI component:

ci schema

In this flow, a user is developing on an AI Platform Notebook instance. He pushes his notebook with changes to the Github repository, which triggers a git hook and in turn a Cloud Build job (cloudbuild.yaml). This Cloud Build job creates a testing instance on which the notebook will be executed, and results of the execution will be reported to Cloud Storage for the user to examine.

Let's follow what happens when a user submits broken code in the notebook.

Life of a Broken Commit

  • User pushes commit that breaks notebook.
  • GitHub (or Cloud Source Repository) has a special pre-configured hook that triggers Cloud Build each time when a new commit is pushed to master. Cloud Build has provided a guide to set up this git hook here.
  • Cloud Build looks for the file cloudbuild.yaml that describes the testing steps. In our example, this file:
    • clones the repository
    • checkout required commit under test
    • executes testing logic in run_notebook_instance.sh which does the following steps:
      • upload notebook (you can upload other files if needed) to GCS
      • use gcp-notebook-executer to start executing the notebook
      • wait until notebook execution is finished
      • check output directory in cloud storage
    • upload tested execution code to GCS and Cloud Functions (used later for CD)
  • mark build as green or red

What do I need to do to create CI for my repository?

  1. Make sure that your notebook self-contained and can be executed on top of one of available Cloud Deep Learning VMs image families
  2. Add Cloud Build hook to your repository
  3. Create testing script run_notebook_instance.sh based on our script. In the script you need to customize:
    • image family that need to be used
    • VM configuration (GPU type, VM shape, etc)
    • name of the notebook
    • you might need update logic that uploads dependencies to cloud storage
  4. Create cloudbuild.yaml similar to the one from this repository.

Continuous Deployment (CD)

Overview of CI component (updated):

ci updated schema

Overview of CD component:

cd schema

Now that we have a tested, reproducible notebook, let's automate the execution of the notebook on a set schedule. As the last step of the CI workflow, let's deploy a Cloud Function which runs the same notebook execution code with modifiable parameters (function code). For orchestration we'll use Cloud Scheduler, but this could be any code/utility/trigger that can publish a message to Pub/Sub (for example, new data arrives in GCS, or a manual request to execute the notebook). Once the schedule is set up, new notebook results will automatically appear in the configured output directory.

CD Setup

  • Execute an iteration of the CI workflow, if successful this will deploy the Cloud Function and create a Pub/Sub topic demo-notebook which the function subscribes to.
  • Create a Cloud Scheduler job: frequency can be any cron style schedule (e.g. 0 0 * * 0 = every sunday midnight), target should be Pub/Sub with the topic demo-notebook, and the payload should be {}, which will use the current date (behavior defined in the function).

How to get help

If you have further questions, or encounter issues using AI Platform Notebooks or Deep Learning VMs, reach out at our team's forum: https://groups.google.com/forum/#!forum/google-dl-platform

cicd-notebooks-aiplatform's People

Contributors

lukmanr avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.