Using Gcp Cloudbuild With Notebooks
Introduction
In this guide, we will demonstrate how to use Google Cloud Build to build and deploy Jupyter Notebooks. Google Cloud Build is a service that executes your builds on Google Cloud infrastructure. It can import source code from various repositories or cloud storage spaces, execute a build to your specifications, and produce artifacts such as Docker containers or JavaScript bundles.
Step-by-Step Explanation
Step 1: Set Up Google Cloud Project
- Go to the Google Cloud Console.
- Create a new project or select an existing project.
- Enable the Cloud Build API for your project.
Step 2: Create a Cloud Build Configuration File
- Create a
cloudbuild.yaml
file in your project directory. - Define the build steps in the
cloudbuild.yaml
file. For example, you can define steps to build a Docker image for your Jupyter Notebook.
Step 3: Create a Dockerfile for Jupyter Notebook
- Create a
Dockerfile
in your project directory. - Define the Docker image for your Jupyter Notebook. For example, you can use the
jupyter/base-notebook
image as a base image.
Step 4: Trigger the Build
- Use the
gcloud
command-line tool to trigger the build. - Run the following command to start the build:
gcloud builds submit --config cloudbuild.yaml .
Summary
In this guide, we have shown how to use Google Cloud Build to build and deploy Jupyter Notebooks. We covered setting up a Google Cloud project, creating a Cloud Build configuration file, creating a Dockerfile for Jupyter Notebook, and triggering the build using the gcloud
command-line tool. By following these steps, you can automate the build and deployment of your Jupyter Notebooks using Google Cloud Build.
Full Code Example
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
// Create a Google Cloud Build Trigger
const buildTrigger = new gcp.cloudbuild.Trigger("jupyter-notebook-build-trigger", {
filename: "cloudbuild.yaml",
includedFiles: ["**/*"],
substitutions: {
"_NOTEBOOK_IMAGE": "gcr.io/my-project/jupyter-notebook:latest",
},
triggerTemplate: {
projectId: pulumi.getProject(),
repoName: "my-repo",
branchName: "^main$",
},
});
// Create a Google Cloud Notebooks Instance
const notebookInstance = new gcp.notebooks.Instance("jupyter-notebook-instance", {
machineType: "n1-standard-4",
installGpuDriver: false,
customGpuDriverPath: "",
bootDiskType: "PD_STANDARD",
bootDiskSizeGb: 100,
dataDiskType: "PD_STANDARD",
dataDiskSizeGb: 100,
noRemoveDataDisk: false,
location: "us-central1-a",
vmImage: {
project: "deeplearning-platform-release",
imageFamily: "tf-latest-cpu",
},
});
// Export the URLs of the build trigger and the notebook instance
export const buildTriggerUrl = pulumi.interpolate\`https://console.cloud.google.com/cloud-build/triggers/edit/\${buildTrigger.id}?project=\${pulumi.getProject()}\`;
export const notebookInstanceUrl = pulumi.interpolate\`https://console.cloud.google.com/ai/notebooks/instances/details/\${notebookInstance.id}?project=\${pulumi.getProject()}\`;
Deploy this code
Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.
Sign upNew to Pulumi?
Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.
Sign upThank you for your feedback!
If you have a question about how to use Pulumi, reach out in Community Slack.
Open an issue on GitHub to report a problem or suggest an improvement.