configure cloudshell to run walkthrough

This commit is contained in:
Robert Wilkins III 2023-04-20 01:21:21 +00:00 committed by Gabriel Luiz Freitas Almeida
commit 50b24f9443
5 changed files with 266 additions and 10 deletions

View file

@ -1,7 +1,7 @@
# Running Langflow from a new Google Cloud project
This guide will help you set up a Langflow Dev VM in a Google Cloud Platform project using Google Cloud Shell.
[![Open in Cloud Shell](https://gstatic.com/cloudssh/images/open-btn.svg)](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/genome21/langflow&working_dir=scripts&shellonly=true&tutorial=gcp_setup_tutorial.yaml)
[![Open in Cloud Shell](https://gstatic.com/cloudssh/images/open-btn.svg)](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/genome21/langflow&working_dir=scripts&shellonly=true&tutorial=walkthroughtutorial.md)
## Run the following in your GCP cloudshell:

View file

@ -19,7 +19,7 @@
LangFlow is a GUI for [LangChain](https://github.com/hwchase17/langchain), designed with [react-flow](https://github.com/wbkd/react-flow) to provide an effortless way to experiment and prototype flows with drag-and-drop components and a chat box.
## 📦 Installation
### <b>Locally</b>
You can install LangFlow from pip:
`pip install langflow`
@ -28,6 +28,14 @@ Next, run:
`langflow`
### Deploy Langflow on Google Cloud Platform
Follow our step-by-step guide to deploy Langflow on Google Cloud Platform (GCP) using Google Cloud Shell. The guide is available in the [Langflow in Google Cloud Platform](GCP_DEPLOYMENT.md) document.
Alternatively, click the "Open in Cloud Shell" button below to launch Google Cloud Shell, clone the Langflow repository, and start an interactive tutorial that will guide you through the process of setting up the necessary resources and deploying Langflow on your GCP project.
[![Open in Cloud Shell](https://gstatic.com/cloudssh/images/open-btn.svg)](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/genome21/langflow&working_dir=scripts&shellonly=true&tutorial=GCP_SETUP_TUTORIAL.md)
## 🎨 Creating Flows
Creating flows with LangFlow is easy. Simply drag sidebar components onto the canvas and connect them together to create your pipeline. LangFlow provides a range of [LangChain components](https://langchain.readthedocs.io/en/latest/reference.html) to choose from, including LLMs, prompt serializers, agents, and chains.

View file

@ -0,0 +1,100 @@
# Set the VM, image, and networking configuration
VM_NAME="langflow-dev"
IMAGE_FAMILY="debian-11"
IMAGE_PROJECT="debian-cloud"
BOOT_DISK_SIZE="100GB"
ZONE="us-central1-a"
REGION="us-central1"
VPC_NAME="default"
SUBNET_NAME="default"
SUBNET_RANGE="10.128.0.0/20"
NAT_GATEWAY_NAME="nat-gateway"
CLOUD_ROUTER_NAME="nat-client"
# Set the GCP project's compute region
gcloud config set compute/region $REGION
# Check if the VPC exists, and create it if not
vpc_exists=$(gcloud compute networks list --filter="name=$VPC_NAME" --format="value(name)")
if [[ -z "$vpc_exists" ]]; then
gcloud compute networks create $VPC_NAME --subnet-mode=custom
fi
# Check if the subnet exists, and create it if not
subnet_exists=$(gcloud compute networks subnets list --filter="name=$SUBNET_NAME AND region=$REGION" --format="value(name)")
if [[ -z "$subnet_exists" ]]; then
gcloud compute networks subnets create $SUBNET_NAME --network=$VPC_NAME --region=$REGION --range=$SUBNET_RANGE
fi
# Create a firewall rule to allow TCP port 8080 for all instances in the VPC
firewall_8080_exists=$(gcloud compute firewall-rules list --filter="name=allow-tcp-8080" --format="value(name)")
if [[ -z "$firewall_8080_exists" ]]; then
gcloud compute firewall-rules create allow-tcp-8080 --network $VPC_NAME --allow tcp:8080 --source-ranges 0.0.0.0/0 --direction INGRESS
fi
# Create a firewall rule to allow IAP traffic
firewall_iap_exists=$(gcloud compute firewall-rules list --filter="name=allow-iap" --format="value(name)")
if [[ -z "$firewall_iap_exists" ]]; then
gcloud compute firewall-rules create allow-iap --network $VPC_NAME --allow tcp:80,tcp:443 --source-ranges 35.235.240.0/20 --direction INGRESS
fi
# Create the Cloud Router and NAT Gateway
cloud_router_exists=$(gcloud compute routers list --filter="name=$CLOUD_ROUTER_NAME" --format="value(name)")
if [[ -z "$cloud_router_exists" ]]; then
gcloud compute routers create $CLOUD_ROUTER_NAME --network $VPC_NAME --region $REGION
fi
nat_exists=$(gcloud compute routers list --filter="name=$CLOUD_ROUTER_NAME" --format="value(nats.name)")
if [[ -z "$nat_exists" ]]; then
gcloud compute routers nats create $NAT_GATEWAY_NAME --router $CLOUD_ROUTER_NAME --auto-allocate-nat-external-ips --nat-all-subnet-ip-ranges --enable-logging --region $REGION
fi
# Define the startup script as a multiline Bash here-doc
STARTUP_SCRIPT=$(cat <<'EOF'
#!/bin/bash
# Update and upgrade the system
apt -y update
apt -y upgrade
# Install Python 3 pip, Langflow, and Nginx
apt -y install python3-pip
pip install langflow
apt-get -y install nginx
# Configure Nginx for Langflow
touch /etc/nginx/sites-available/langflow-app
echo "server {
listen 0.0.0.0:8080;
location / {
proxy_pass http://127.0.0.1:7860;
proxy_set_header Host "\$host";
proxy_set_header X-Real-IP "\$remote_addr";
proxy_set_header X-Forwarded-For "\$proxy_add_x_forwarded_for";
}
}" >> /etc/nginx/sites-available/langflow-app
ln -s /etc/nginx/sites-available/langflow-app /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx
langflow
EOF
)
# Create a temporary file to store the startup script
tempfile=$(mktemp)
echo "$STARTUP_SCRIPT" > $tempfile
# Create the VM instance with the specified configuration and startup script
gcloud compute instances create $VM_NAME \
--image-family $IMAGE_FAMILY \
--image-project $IMAGE_PROJECT \
--boot-disk-size $BOOT_DISK_SIZE \
--machine-type=n1-standard-4 \
--metadata-from-file startup-script=$tempfile \
--zone $ZONE \
--network $VPC_NAME \
--subnet $SUBNET_NAME
# Remove the temporary file after the VM is created
rm $tempfile

View file

@ -1,10 +1,80 @@
title: Setting up Langflow on GCP
description: This tutorial guides you through setting up Langflow on GCP
steps:
- title: Running setup script
content: |
Running the setup script to create resources and deploy Langflow on GCP.
title: Deploy Langflow on Google Cloud Platform
duration: 45m
author: Your Name
environment:
cwd: working_dir
repo:
url: https://github.com/genome21/langflow
working_dir: scripts
steps:
- title: Introduction
content: |
In this tutorial, you will learn how to deploy Langflow on Google Cloud Platform (GCP) using Google Cloud Shell.
This tutorial assumes you have a GCP account and basic knowledge of Google Cloud Shell. If you're not familiar with Cloud Shell, you can review the [Cloud Shell documentation](https://cloud.google.com/shell/docs).
- title: Set up your environment
content: |
Before you start, make sure you have the following prerequisites:
- A GCP account with the necessary permissions to create resources
- A project on GCP where you want to deploy Langflow
<walkthrough-project-setup></walkthrough-project-setup>
In the next step, you'll clone the Langflow repository and navigate to the `scripts` directory.
- title: Clone the repository and navigate to the scripts directory
content: |
Run the following commands to clone the Langflow repository and navigate to the `scripts` directory:
```bash
source gcp_setup.sh
```
git clone https://github.com/genome21/langflow
cd langflow/scripts
```
In the next step, you'll configure the GCP environment and deploy Langflow.
- title: Configure the GCP environment and deploy Langflow
content: |
Run the `deploy_langflow_gcp.sh` script to configure the GCP environment and deploy Langflow:
```
./deploy_langflow_gcp.sh
```
The script will:
1. Check if the required resources (VPC, subnet, firewall rules, and Cloud Router) exist and create them if needed
2. Create a startup script to install Python, Langflow, and Nginx
3. Create a Compute Engine VM instance with the specified configuration and startup script
4. Configure Nginx to serve Langflow on TCP port 8080
In the next step, you'll learn how to connect to the Langflow VM.
- title: Connect to the Langflow VM
content: |
To connect to your new Langflow VM, follow these steps:
1. Navigate to the [VM instances](https://console.cloud.google.com/compute/instances) page
2. Click on the external IP for your VM
3. Add port 8080 (assuming your VM external IP is 192.168.0.1):
http://192.168.0.1:8080
4. You will be greeted by the Langflow Dev environment
Congratulations! You have successfully deployed Langflow on Google Cloud Platform.
- title: Cleanup
content: |
If you want to remove the resources created during this tutorial, you can use the following commands:
```
gcloud compute instances delete langflow-dev --zone us-central1-a --quiet
gcloud compute routers nats delete nat-gateway --router nat-client --region us-central1 --quiet
gcloud compute routers delete nat-client --region us-central1 --quiet
gcloud compute firewall-rules delete allow-tcp-8080 --quiet
gcloud compute firewall-rules delete allow-iap --quiet
gcloud compute networks subnets delete default --region us-central1 --quiet
gcloud compute networks delete default --quiet
``

View file

@ -0,0 +1,78 @@
# Deploy Langflow on Google Cloud Platform
**Duration**: 45 minutes
**Author**: [Robert Wilkins III](https://www.linkedin.com/in/robertwilkinsiii)
## Introduction
In this tutorial, you will learn how to deploy Langflow on [Google Cloud Platform](https://cloud.google.com/) (GCP) using Google Cloud Shell.
This tutorial assumes you have a GCP account and basic knowledge of Google Cloud Shell. If you're not familiar with Cloud Shell, you can review the [Cloud Shell documentation](https://cloud.google.com/shell/docs).
## Set up your environment
Before you start, make sure you have the following prerequisites:
- A GCP account with the necessary permissions to create resources
- A project on GCP where you want to deploy Langflow
[**Select your GCP project**]<walkthrough-project-setup></walkthrough-project-setup>
In the next step, you'll clone the Langflow repository and navigate to the `scripts` directory.
## Clone the repository and navigate to the scripts directory
Run the following commands to clone the Langflow repository and navigate to the `scripts` directory:
```bash
git clone https://github.com/genome21/langflow
cd langflow/scripts
```
In the next step, you'll configure the GCP environment and deploy Langflow.
## Configure the GCP environment and deploy Langflow
Run the deploy_langflow_gcp.sh script to configure the GCP environment and deploy Langflow:
```bash
./deploy_langflow_gcp.sh
```
The script will:
1. Check if the required resources (VPC, subnet, firewall rules, and Cloud Router) exist and create them if needed
2. Create a startup script to install Python, Langflow, and Nginx
3. Create a Compute Engine VM instance with the specified configuration and startup script
4. Configure Nginx to serve Langflow on TCP port 8080
In the next step, you'll learn how to connect to the Langflow VM.
## Connect to the Langflow VM
To connect to your new Langflow VM, follow these steps:
1. Navigate to the [VM instances](https://console.cloud.google.com/compute/instances) page
2. Click on the external IP for your VM
3. Add port 8080 (assuming your VM external IP is 192.168.0.1):
http://192.168.0.1:8080
4. You will be greeted by the Langflow Dev environment
Congratulations! You have successfully deployed Langflow on Google Cloud Platform.
## Cleanup
If you want to remove the resources created during this tutorial, you can use the following commands:
```sql
gcloud compute instances delete langflow-dev --zone us-central1-a --quiet
gcloud compute routers nats delete nat-gateway --router nat-client --region us-central1 --quiet
gcloud compute routers delete nat-client --region us-central1 --quiet
gcloud compute firewall-rules delete allow-tcp-8080 --quiet
gcloud compute firewall-rules delete allow-iap --quiet
gcloud compute networks subnets delete default --region us-central1 --quiet
gcloud compute networks delete default --quiet
```