From c315abcde23d7b7ea875fdc457d44fbd51928f47 Mon Sep 17 00:00:00 2001 From: Robert Wilkins III <1147229+genome21@users.noreply.github.com> Date: Tue, 18 Apr 2023 03:07:05 +0000 Subject: [PATCH 01/39] Add steps to provision GCP VM serving langflow --- GCP-SETUP.md | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 GCP-SETUP.md diff --git a/GCP-SETUP.md b/GCP-SETUP.md new file mode 100644 index 000000000..ba6d61404 --- /dev/null +++ b/GCP-SETUP.md @@ -0,0 +1,90 @@ +# Running Langflow from a new GCP project +## Run the following in your GCP cloudshell: + +```bash + +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" +NAT_GATEWAY_NAME="nat-gateway" +CLOUD_ROUTER_NAME="nat-client" + +gcloud config set compute/region $REGION + +# Verify the VPC and subnet exist +vpc_exists=$(gcloud compute networks list --filter="name=$VPC_NAME" --format="value(name)") +subnet_exists=$(gcloud compute networks subnets list --filter="name=$SUBNET_NAME AND region=$REGION" --format="value(name)") + +if [[ -z "$vpc_exists" || -z "$subnet_exists" ]]; then + echo "Error: VPC '$VPC_NAME' and/or subnet '$SUBNET_NAME' do not exist in region '$REGION'." + exit 1 +fi + +# Create the Cloud Router and NAT Gateway +gcloud compute routers create $CLOUD_ROUTER_NAME \ + --network $VPC_NAME \ + --region $REGION + +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 + +# Define the startup script as a multiline Bash here-doc +STARTUP_SCRIPT=$(cat <<'EOF' +#!/bin/bash + +apt update +apt upgrade +apt install python3-pip +pip install langflow +apt-get install nginx +touch /etc/nginx/sites-available/langflow-app +echo "server { + listen 0.0.0.0:7860; + + 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/my-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 + +gcloud compute instances create $VM_NAME \ + --image-family $IMAGE_FAMILY \ + --image-project $IMAGE_PROJECT \ + --boot-disk-size $BOOT_DISK_SIZE \ + --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 + +``` + +## Connecting to your new Langflow VM +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 \ No newline at end of file From c7bf4f80dfc1a1d118e8440c301da8641896c09b Mon Sep 17 00:00:00 2001 From: Robert Wilkins III <1147229+genome21@users.noreply.github.com> Date: Tue, 18 Apr 2023 03:14:45 +0000 Subject: [PATCH 02/39] Adjust firewall to allow port 8080 --- GCP-SETUP.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/GCP-SETUP.md b/GCP-SETUP.md index ba6d61404..53646d4b0 100644 --- a/GCP-SETUP.md +++ b/GCP-SETUP.md @@ -25,6 +25,13 @@ if [[ -z "$vpc_exists" || -z "$subnet_exists" ]]; then exit 1 fi +gcloud compute firewall-rules create allow-tcp-8080 \ + --network $VPC_NAME \ + --allow tcp:8080 \ + --source-ranges 0.0.0.0/0 \ + --direction INGRESS + + # Create the Cloud Router and NAT Gateway gcloud compute routers create $CLOUD_ROUTER_NAME \ --network $VPC_NAME \ From f2a587191b86d27528852eae81b92381df2aa500 Mon Sep 17 00:00:00 2001 From: Robert Wilkins III <1147229+genome21@users.noreply.github.com> Date: Tue, 18 Apr 2023 03:42:01 +0000 Subject: [PATCH 03/39] Add comments to clarify code --- GCP-SETUP.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/GCP-SETUP.md b/GCP-SETUP.md index 53646d4b0..1f4eb6b4e 100644 --- a/GCP-SETUP.md +++ b/GCP-SETUP.md @@ -1,8 +1,11 @@ # Running Langflow from a new GCP project +This guide will help you set up a Langflow Dev VM in a Google Cloud Platform project using Google Cloud Shell. + + ## Run the following in your GCP cloudshell: ```bash - +# Set the VM, image, and networking configuration VM_NAME="langflow-dev" IMAGE_FAMILY="debian-11" IMAGE_PROJECT="debian-cloud" @@ -14,17 +17,20 @@ SUBNET_NAME="default" NAT_GATEWAY_NAME="nat-gateway" CLOUD_ROUTER_NAME="nat-client" +# Set the GCP project's compute region gcloud config set compute/region $REGION # Verify the VPC and subnet exist vpc_exists=$(gcloud compute networks list --filter="name=$VPC_NAME" --format="value(name)") subnet_exists=$(gcloud compute networks subnets list --filter="name=$SUBNET_NAME AND region=$REGION" --format="value(name)") +# Exit with an error message if the VPC or subnet does not exist if [[ -z "$vpc_exists" || -z "$subnet_exists" ]]; then echo "Error: VPC '$VPC_NAME' and/or subnet '$SUBNET_NAME' do not exist in region '$REGION'." exit 1 fi +# Create a firewall rule to allow TCP port 8080 for all instances in the VPC gcloud compute firewall-rules create allow-tcp-8080 \ --network $VPC_NAME \ --allow tcp:8080 \ @@ -48,11 +54,16 @@ gcloud compute routers nats create $NAT_GATEWAY_NAME \ STARTUP_SCRIPT=$(cat <<'EOF' #!/bin/bash +# Update and upgrade the system apt update apt upgrade + +# Install Python 3 pip, Langflow, and Nginx apt install python3-pip pip install langflow apt-get install nginx + +# Configure Nginx for Langflow touch /etc/nginx/sites-available/langflow-app echo "server { listen 0.0.0.0:7860; @@ -75,6 +86,7 @@ EOF 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 \ @@ -88,6 +100,9 @@ gcloud compute instances create $VM_NAME \ rm $tempfile ``` +> This script sets up a Debian-based VM with the Langflow package, Nginx, and the necessary configurations to run the Langflow Dev environment. The VM will be accessible on TCP port 8080 from any IP address. + +
## Connecting to your new Langflow VM 1. Navigate to the [VM instances](https://console.cloud.google.com/compute/instances) page From 7195278f2c7c2ce39412db7b677a584237b5b403 Mon Sep 17 00:00:00 2001 From: Robert Wilkins III <1147229+genome21@users.noreply.github.com> Date: Tue, 18 Apr 2023 04:29:42 +0000 Subject: [PATCH 04/39] check and create VPC and subnet --- GCP-SETUP.md | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/GCP-SETUP.md b/GCP-SETUP.md index 1f4eb6b4e..de0ec836d 100644 --- a/GCP-SETUP.md +++ b/GCP-SETUP.md @@ -14,20 +14,23 @@ 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 -# Verify the VPC and subnet exist +# Check if the VPC exists, and create it if not vpc_exists=$(gcloud compute networks list --filter="name=$VPC_NAME" --format="value(name)") -subnet_exists=$(gcloud compute networks subnets list --filter="name=$SUBNET_NAME AND region=$REGION" --format="value(name)") +if [[ -z "$vpc_exists" ]]; then + gcloud compute networks create $VPC_NAME --subnet-mode=custom +fi -# Exit with an error message if the VPC or subnet does not exist -if [[ -z "$vpc_exists" || -z "$subnet_exists" ]]; then - echo "Error: VPC '$VPC_NAME' and/or subnet '$SUBNET_NAME' do not exist in region '$REGION'." - exit 1 +# 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 From d19d3f4de03e68e003df984084a4742b9d60ba64 Mon Sep 17 00:00:00 2001 From: Robert Wilkins III <1147229+genome21@users.noreply.github.com> Date: Tue, 18 Apr 2023 04:32:41 +0000 Subject: [PATCH 05/39] Allow IAP --- GCP-SETUP.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/GCP-SETUP.md b/GCP-SETUP.md index de0ec836d..9261b8219 100644 --- a/GCP-SETUP.md +++ b/GCP-SETUP.md @@ -40,6 +40,12 @@ gcloud compute firewall-rules create allow-tcp-8080 \ --source-ranges 0.0.0.0/0 \ --direction INGRESS +# Create a firewall rule to allow IAP traffic +gcloud compute firewall-rules create allow-iap \ + --network $VPC_NAME \ + --allow tcp:80,tcp:443 \ + --source-ranges 35.235.240.0/20 \ + --direction INGRESS # Create the Cloud Router and NAT Gateway gcloud compute routers create $CLOUD_ROUTER_NAME \ From 5c4743db36f1b7d0c58797fcef26d5f2cd117931 Mon Sep 17 00:00:00 2001 From: Robert Wilkins III <1147229+genome21@users.noreply.github.com> Date: Tue, 18 Apr 2023 17:31:50 +0000 Subject: [PATCH 06/39] adding machine type to VM create --- GCP-SETUP.md | 1 + 1 file changed, 1 insertion(+) diff --git a/GCP-SETUP.md b/GCP-SETUP.md index 9261b8219..3a4750bc5 100644 --- a/GCP-SETUP.md +++ b/GCP-SETUP.md @@ -100,6 +100,7 @@ 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 \ From 1e6a40adee2cb6784d9c22a199fd9348c024e895 Mon Sep 17 00:00:00 2001 From: Robert Wilkins III <1147229+genome21@users.noreply.github.com> Date: Wed, 19 Apr 2023 16:44:55 +0000 Subject: [PATCH 07/39] fix apt confirms, heredoc vars, add if statements --- GCP-SETUP.md | 53 +++++++++++++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/GCP-SETUP.md b/GCP-SETUP.md index 3a4750bc5..3a0908ff2 100644 --- a/GCP-SETUP.md +++ b/GCP-SETUP.md @@ -34,57 +34,54 @@ if [[ -z "$subnet_exists" ]]; then fi # Create a firewall rule to allow TCP port 8080 for all instances in the VPC -gcloud compute firewall-rules create allow-tcp-8080 \ - --network $VPC_NAME \ - --allow tcp:8080 \ - --source-ranges 0.0.0.0/0 \ - --direction INGRESS +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 -gcloud compute firewall-rules create allow-iap \ - --network $VPC_NAME \ - --allow tcp:80,tcp:443 \ - --source-ranges 35.235.240.0/20 \ - --direction INGRESS +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 -gcloud compute routers create $CLOUD_ROUTER_NAME \ - --network $VPC_NAME \ - --region $REGION +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 -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 +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 update -apt upgrade +apt -y update +apt -y upgrade # Install Python 3 pip, Langflow, and Nginx -apt install python3-pip +apt -y install python3-pip pip install langflow -apt-get install nginx +apt-get -y install nginx # Configure Nginx for Langflow touch /etc/nginx/sites-available/langflow-app echo "server { - listen 0.0.0.0:7860; + 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; + 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/my-app /etc/nginx/sites-enabled/ +ln -s /etc/nginx/sites-available/langflow-app /etc/nginx/sites-enabled/ sudo nginx -t sudo systemctl restart nginx langflow From a200ddc4fdf309bb214970f0bc2e75b0cf205311 Mon Sep 17 00:00:00 2001 From: Robert Wilkins III <1147229+genome21@users.noreply.github.com> Date: Wed, 19 Apr 2023 22:59:56 +0000 Subject: [PATCH 08/39] create setup files and GCP tutorial --- GCP-SETUP.md => GCP_DEPLOYMENT.md | 4 +++- scripts/gcp_setup.sh | 0 scripts/gcp_setup_tutorial.yaml | 10 ++++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) rename GCP-SETUP.md => GCP_DEPLOYMENT.md (93%) create mode 100644 scripts/gcp_setup.sh create mode 100644 scripts/gcp_setup_tutorial.yaml diff --git a/GCP-SETUP.md b/GCP_DEPLOYMENT.md similarity index 93% rename from GCP-SETUP.md rename to GCP_DEPLOYMENT.md index 3a0908ff2..015d02d6f 100644 --- a/GCP-SETUP.md +++ b/GCP_DEPLOYMENT.md @@ -1,6 +1,8 @@ -# Running Langflow from a new GCP project +# 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) + ## Run the following in your GCP cloudshell: diff --git a/scripts/gcp_setup.sh b/scripts/gcp_setup.sh new file mode 100644 index 000000000..e69de29bb diff --git a/scripts/gcp_setup_tutorial.yaml b/scripts/gcp_setup_tutorial.yaml new file mode 100644 index 000000000..b45c56c30 --- /dev/null +++ b/scripts/gcp_setup_tutorial.yaml @@ -0,0 +1,10 @@ +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. + + ```bash + source gcp_setup.sh + ``` From 5c57701e38c43817d6224c7e643460c43c458578 Mon Sep 17 00:00:00 2001 From: Robert Wilkins III <1147229+genome21@users.noreply.github.com> Date: Thu, 20 Apr 2023 01:21:21 +0000 Subject: [PATCH 09/39] configure cloudshell to run walkthrough --- GCP_DEPLOYMENT.md | 2 +- README.md | 10 +++- scripts/gcp_setup.sh | 100 ++++++++++++++++++++++++++++++++ scripts/gcp_setup_tutorial.yaml | 86 ++++++++++++++++++++++++--- scripts/walkthroughtutorial.md | 78 +++++++++++++++++++++++++ 5 files changed, 266 insertions(+), 10 deletions(-) create mode 100644 scripts/walkthroughtutorial.md diff --git a/GCP_DEPLOYMENT.md b/GCP_DEPLOYMENT.md index 015d02d6f..3cf10df27 100644 --- a/GCP_DEPLOYMENT.md +++ b/GCP_DEPLOYMENT.md @@ -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: diff --git a/README.md b/README.md index 970496349..eaaf84331 100644 --- a/README.md +++ b/README.md @@ -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 - +### Locally 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. diff --git a/scripts/gcp_setup.sh b/scripts/gcp_setup.sh index e69de29bb..3e20e9589 100644 --- a/scripts/gcp_setup.sh +++ b/scripts/gcp_setup.sh @@ -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 diff --git a/scripts/gcp_setup_tutorial.yaml b/scripts/gcp_setup_tutorial.yaml index b45c56c30..f8c5b401c 100644 --- a/scripts/gcp_setup_tutorial.yaml +++ b/scripts/gcp_setup_tutorial.yaml @@ -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 + + + + 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 + `` diff --git a/scripts/walkthroughtutorial.md b/scripts/walkthroughtutorial.md new file mode 100644 index 000000000..ebc9a4b95 --- /dev/null +++ b/scripts/walkthroughtutorial.md @@ -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**] + +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 +``` From 12a1f3ac7a71dad43e4035af64271d443dc40669 Mon Sep 17 00:00:00 2001 From: Robert Wilkins III <1147229+genome21@users.noreply.github.com> Date: Thu, 20 Apr 2023 01:30:44 +0000 Subject: [PATCH 10/39] remove scripted steps from walkthrough --- scripts/walkthroughtutorial.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/walkthroughtutorial.md b/scripts/walkthroughtutorial.md index ebc9a4b95..641cce1e8 100644 --- a/scripts/walkthroughtutorial.md +++ b/scripts/walkthroughtutorial.md @@ -18,16 +18,16 @@ Before you start, make sure you have the following prerequisites: [**Select your GCP project**] -In the next step, you'll clone the Langflow repository and navigate to the `scripts` directory. +[comment]: <> (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 +[comment]: <> (## Clone the repository and navigate to the scripts directory) -Run the following commands to clone the Langflow repository and navigate to the `scripts` directory: +[comment]: <> (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 -``` +[comment]: <> (```bash) +[comment]: <> (git clone https://github.com/genome21/langflow) +[comment]: <> (cd langflow/scripts) +[comment]: <> (```) In the next step, you'll configure the GCP environment and deploy Langflow. From c458f0f222071c4249468a5384c1e1eaaaaa2c13 Mon Sep 17 00:00:00 2001 From: Robert Wilkins III <1147229+genome21@users.noreply.github.com> Date: Thu, 20 Apr 2023 01:32:45 +0000 Subject: [PATCH 11/39] remove comments that show up in walkthrough --- scripts/walkthroughtutorial.md | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/scripts/walkthroughtutorial.md b/scripts/walkthroughtutorial.md index 641cce1e8..d21dbd31a 100644 --- a/scripts/walkthroughtutorial.md +++ b/scripts/walkthroughtutorial.md @@ -18,17 +18,6 @@ Before you start, make sure you have the following prerequisites: [**Select your GCP project**] -[comment]: <> (In the next step, you'll clone the Langflow repository and navigate to the `scripts` directory.) - -[comment]: <> (## Clone the repository and navigate to the scripts directory) - -[comment]: <> (Run the following commands to clone the Langflow repository and navigate to the `scripts` directory:) - -[comment]: <> (```bash) -[comment]: <> (git clone https://github.com/genome21/langflow) -[comment]: <> (cd langflow/scripts) -[comment]: <> (```) - In the next step, you'll configure the GCP environment and deploy Langflow. ## Configure the GCP environment and deploy Langflow From 98fc23dfe8b5bc993fcc58f3512630437a71a2d2 Mon Sep 17 00:00:00 2001 From: Robert Wilkins III <1147229+genome21@users.noreply.github.com> Date: Thu, 20 Apr 2023 01:35:20 +0000 Subject: [PATCH 12/39] fix bash command launch --- scripts/walkthroughtutorial.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/walkthroughtutorial.md b/scripts/walkthroughtutorial.md index d21dbd31a..153a5a0c2 100644 --- a/scripts/walkthroughtutorial.md +++ b/scripts/walkthroughtutorial.md @@ -24,7 +24,7 @@ In the next step, you'll 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 +bash ./deploy_langflow_gcp.sh ``` The script will: From a13be7f1dd237b0002ec14b5f7ef0000e9911d02 Mon Sep 17 00:00:00 2001 From: Robert Wilkins III <1147229+genome21@users.noreply.github.com> Date: Thu, 20 Apr 2023 01:37:52 +0000 Subject: [PATCH 13/39] match bash script to walkthrough --- scripts/{gcp_setup.sh => deploy_langflow_gcp.sh} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename scripts/{gcp_setup.sh => deploy_langflow_gcp.sh} (100%) diff --git a/scripts/gcp_setup.sh b/scripts/deploy_langflow_gcp.sh similarity index 100% rename from scripts/gcp_setup.sh rename to scripts/deploy_langflow_gcp.sh From 413285f7eccc251bca83c557ec144021d600aa4f Mon Sep 17 00:00:00 2001 From: Robert Wilkins III <1147229+genome21@users.noreply.github.com> Date: Thu, 20 Apr 2023 01:55:34 +0000 Subject: [PATCH 14/39] force gcp login in ephemeral cloudshell --- scripts/walkthroughtutorial.md | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/walkthroughtutorial.md b/scripts/walkthroughtutorial.md index 153a5a0c2..99599010f 100644 --- a/scripts/walkthroughtutorial.md +++ b/scripts/walkthroughtutorial.md @@ -24,6 +24,7 @@ In the next step, you'll configure the GCP environment and deploy Langflow. Run the deploy_langflow_gcp.sh script to configure the GCP environment and deploy Langflow: ```bash +gcloud auth login --brief --quiet bash ./deploy_langflow_gcp.sh ``` From 7314a3fc81026a06b3d5dda9b42a36dc439f5543 Mon Sep 17 00:00:00 2001 From: Robert Wilkins III <1147229+genome21@users.noreply.github.com> Date: Thu, 20 Apr 2023 02:05:34 +0000 Subject: [PATCH 15/39] add cloudshell repo trust advisory --- GCP_DEPLOYMENT.md | 1 + 1 file changed, 1 insertion(+) diff --git a/GCP_DEPLOYMENT.md b/GCP_DEPLOYMENT.md index 3cf10df27..6bbd54097 100644 --- a/GCP_DEPLOYMENT.md +++ b/GCP_DEPLOYMENT.md @@ -1,5 +1,6 @@ # 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. +> When cloudshell opens, select **Trust this repo**. Some gcloud commands do not run in ephemeral cloudshell. [![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) From a8b2460b91dfc3410323b88367796bcc04336cc4 Mon Sep 17 00:00:00 2001 From: Robert Wilkins III <1147229+genome21@users.noreply.github.com> Date: Thu, 20 Apr 2023 02:07:10 +0000 Subject: [PATCH 16/39] remove login prompt for ephemeral cloudshell --- scripts/walkthroughtutorial.md | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/walkthroughtutorial.md b/scripts/walkthroughtutorial.md index 99599010f..153a5a0c2 100644 --- a/scripts/walkthroughtutorial.md +++ b/scripts/walkthroughtutorial.md @@ -24,7 +24,6 @@ In the next step, you'll configure the GCP environment and deploy Langflow. Run the deploy_langflow_gcp.sh script to configure the GCP environment and deploy Langflow: ```bash -gcloud auth login --brief --quiet bash ./deploy_langflow_gcp.sh ``` From 060a0cfbeb9f980dba8d6443a43a5de081040d76 Mon Sep 17 00:00:00 2001 From: Robert Wilkins III <1147229+genome21@users.noreply.github.com> Date: Thu, 20 Apr 2023 02:10:45 +0000 Subject: [PATCH 17/39] set project config --- scripts/walkthroughtutorial.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/walkthroughtutorial.md b/scripts/walkthroughtutorial.md index 153a5a0c2..f908bce3b 100644 --- a/scripts/walkthroughtutorial.md +++ b/scripts/walkthroughtutorial.md @@ -23,7 +23,8 @@ 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 +```sh +gcloud config set project {{project-id}} bash ./deploy_langflow_gcp.sh ``` From 11fea7a7a86f37a0bbccf3c8111f3e9bd20ee3f1 Mon Sep 17 00:00:00 2001 From: Robert Wilkins III <1147229+genome21@users.noreply.github.com> Date: Thu, 20 Apr 2023 02:18:27 +0000 Subject: [PATCH 18/39] testing var expansion --- scripts/walkthroughtutorial.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/walkthroughtutorial.md b/scripts/walkthroughtutorial.md index f908bce3b..d30c3b702 100644 --- a/scripts/walkthroughtutorial.md +++ b/scripts/walkthroughtutorial.md @@ -16,7 +16,7 @@ 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**] +[**Select your GCP project**] In the next step, you'll configure the GCP environment and deploy Langflow. @@ -24,7 +24,7 @@ In the next step, you'll configure the GCP environment and deploy Langflow. Run the deploy_langflow_gcp.sh script to configure the GCP environment and deploy Langflow: ```sh -gcloud config set project {{project-id}} +gcloud config set project {{project_id}} bash ./deploy_langflow_gcp.sh ``` From e0aba3223fd7017b71fa9262c30d1b6948b05851 Mon Sep 17 00:00:00 2001 From: Robert Wilkins III <1147229+genome21@users.noreply.github.com> Date: Thu, 20 Apr 2023 02:19:36 +0000 Subject: [PATCH 19/39] revert var expansion test --- scripts/walkthroughtutorial.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/walkthroughtutorial.md b/scripts/walkthroughtutorial.md index d30c3b702..3b7e3a76e 100644 --- a/scripts/walkthroughtutorial.md +++ b/scripts/walkthroughtutorial.md @@ -24,7 +24,7 @@ In the next step, you'll configure the GCP environment and deploy Langflow. Run the deploy_langflow_gcp.sh script to configure the GCP environment and deploy Langflow: ```sh -gcloud config set project {{project_id}} +gcloud config set project {{project-id}} bash ./deploy_langflow_gcp.sh ``` From 72d6cb060ae5604ad5c4bde7d5adfff35d8606fc Mon Sep 17 00:00:00 2001 From: Robert Wilkins III <1147229+genome21@users.noreply.github.com> Date: Thu, 20 Apr 2023 02:23:34 +0000 Subject: [PATCH 20/39] var expansion again --- scripts/walkthroughtutorial.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/walkthroughtutorial.md b/scripts/walkthroughtutorial.md index 3b7e3a76e..d30c3b702 100644 --- a/scripts/walkthroughtutorial.md +++ b/scripts/walkthroughtutorial.md @@ -24,7 +24,7 @@ In the next step, you'll configure the GCP environment and deploy Langflow. Run the deploy_langflow_gcp.sh script to configure the GCP environment and deploy Langflow: ```sh -gcloud config set project {{project-id}} +gcloud config set project {{project_id}} bash ./deploy_langflow_gcp.sh ``` From 0527bf3291c2137bdaecbcb80bf77ab4221a984d Mon Sep 17 00:00:00 2001 From: Robert Wilkins III <1147229+genome21@users.noreply.github.com> Date: Thu, 20 Apr 2023 02:33:47 +0000 Subject: [PATCH 21/39] var expansion alt test --- scripts/walkthroughtutorial.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/walkthroughtutorial.md b/scripts/walkthroughtutorial.md index d30c3b702..66efe5e74 100644 --- a/scripts/walkthroughtutorial.md +++ b/scripts/walkthroughtutorial.md @@ -16,7 +16,11 @@ 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**] +[**Select your GCP project**] + + In the next step, you'll configure the GCP environment and deploy Langflow. @@ -24,7 +28,7 @@ In the next step, you'll configure the GCP environment and deploy Langflow. Run the deploy_langflow_gcp.sh script to configure the GCP environment and deploy Langflow: ```sh -gcloud config set project {{project_id}} +gcloud config set project bash ./deploy_langflow_gcp.sh ``` From e38d7b6f24e6830203cb04bbe8e02fa0bbf8ece4 Mon Sep 17 00:00:00 2001 From: Robert Wilkins III <1147229+genome21@users.noreply.github.com> Date: Thu, 20 Apr 2023 02:57:37 +0000 Subject: [PATCH 22/39] provide user with link to langflow server --- scripts/walkthroughtutorial.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/scripts/walkthroughtutorial.md b/scripts/walkthroughtutorial.md index 66efe5e74..0f65dbadf 100644 --- a/scripts/walkthroughtutorial.md +++ b/scripts/walkthroughtutorial.md @@ -46,8 +46,16 @@ 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 +
or +3. Run the following command to store the VM's IP in a variable called `LANGFLOW-IP`: +```bash +export LANGFLOW-IP=$(gcloud compute instances list --filter="NAME=langflow-dev" --format="value(EXTERNAL_IP)") + +echo http://$LANGFLOW-IP:8080 +``` + + + 4. You will be greeted by the Langflow Dev environment Congratulations! You have successfully deployed Langflow on Google Cloud Platform. From df062edd9127576c87b317056336f3af3a6a74ba Mon Sep 17 00:00:00 2001 From: Robert Wilkins III <1147229+genome21@users.noreply.github.com> Date: Thu, 20 Apr 2023 03:08:50 +0000 Subject: [PATCH 23/39] vars and trophies --- scripts/walkthroughtutorial.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/walkthroughtutorial.md b/scripts/walkthroughtutorial.md index 0f65dbadf..5398617c3 100644 --- a/scripts/walkthroughtutorial.md +++ b/scripts/walkthroughtutorial.md @@ -42,6 +42,7 @@ The script will: 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 @@ -54,7 +55,7 @@ export LANGFLOW-IP=$(gcloud compute instances list --filter="NAME=langflow-dev" echo http://$LANGFLOW-IP:8080 ``` - + 4. You will be greeted by the Langflow Dev environment From c4f41a7da9f88917a4ee2fa86c79987fc8a16f8b Mon Sep 17 00:00:00 2001 From: Robert Wilkins III <1147229+genome21@users.noreply.github.com> Date: Thu, 20 Apr 2023 03:11:30 +0000 Subject: [PATCH 24/39] remove input tag --- scripts/walkthroughtutorial.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/scripts/walkthroughtutorial.md b/scripts/walkthroughtutorial.md index 5398617c3..2711ccd93 100644 --- a/scripts/walkthroughtutorial.md +++ b/scripts/walkthroughtutorial.md @@ -50,13 +50,11 @@ To connect to your new Langflow VM, follow these steps:
or 3. Run the following command to store the VM's IP in a variable called `LANGFLOW-IP`: ```bash -export LANGFLOW-IP=$(gcloud compute instances list --filter="NAME=langflow-dev" --format="value(EXTERNAL_IP)") +export LANGFLOW_IP=$(gcloud compute instances list --filter="NAME=langflow-dev" --format="value(EXTERNAL_IP)") -echo http://$LANGFLOW-IP:8080 +echo http://$LANGFLOW_IP:8080 ``` - - 4. You will be greeted by the Langflow Dev environment Congratulations! You have successfully deployed Langflow on Google Cloud Platform. From d46c1e5a81ebc7918578094175633e4d4ae8b64c Mon Sep 17 00:00:00 2001 From: Robert Wilkins III <1147229+genome21@users.noreply.github.com> Date: Thu, 20 Apr 2023 03:17:40 +0000 Subject: [PATCH 25/39] clarify notes to connect to vm --- scripts/walkthroughtutorial.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/scripts/walkthroughtutorial.md b/scripts/walkthroughtutorial.md index 2711ccd93..dd107a770 100644 --- a/scripts/walkthroughtutorial.md +++ b/scripts/walkthroughtutorial.md @@ -45,17 +45,16 @@ In the next step, you'll learn how to 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 -
or -3. Run the following command to store the VM's IP in a variable called `LANGFLOW-IP`: +1. Navigate to the [VM instances](https://console.cloud.google.com/compute/instances) page and click on the external IP for your VM. Make sure to use HTTP and set the port to 8080 +
**or** +3. Run the following command to display the URL for your Langflow environment: ```bash export LANGFLOW_IP=$(gcloud compute instances list --filter="NAME=langflow-dev" --format="value(EXTERNAL_IP)") echo http://$LANGFLOW_IP:8080 ``` -4. You will be greeted by the Langflow Dev environment +4. Click on the Langflow URL in cloudshell to be greeted by the Langflow Dev environment Congratulations! You have successfully deployed Langflow on Google Cloud Platform. From 6c61926261ac6168d1dd2c8525b359f01dcc1c2c Mon Sep 17 00:00:00 2001 From: Robert Wilkins III <1147229+genome21@users.noreply.github.com> Date: Thu, 20 Apr 2023 03:20:09 +0000 Subject: [PATCH 26/39] move trophy toward end of walkthrough --- scripts/walkthroughtutorial.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/walkthroughtutorial.md b/scripts/walkthroughtutorial.md index dd107a770..7742f3453 100644 --- a/scripts/walkthroughtutorial.md +++ b/scripts/walkthroughtutorial.md @@ -42,7 +42,6 @@ The script will: 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 and click on the external IP for your VM. Make sure to use HTTP and set the port to 8080 @@ -58,6 +57,8 @@ echo http://$LANGFLOW_IP:8080 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: From 1c7776508fbbdc65f7e3ff708a9c15835646fc63 Mon Sep 17 00:00:00 2001 From: Robert Wilkins III <1147229+genome21@users.noreply.github.com> Date: Thu, 20 Apr 2023 03:29:03 +0000 Subject: [PATCH 27/39] improve readability --- scripts/walkthroughtutorial.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/walkthroughtutorial.md b/scripts/walkthroughtutorial.md index 7742f3453..3d9401f2e 100644 --- a/scripts/walkthroughtutorial.md +++ b/scripts/walkthroughtutorial.md @@ -69,6 +69,13 @@ gcloud compute routers nats delete nat-gateway --router nat-client --region us-c gcloud compute routers delete nat-client --region us-central1 --quiet +``` +The following network settings and services are used during this walkthrough. If you plan to continue using the project after the walkthrough, you may keep these configurations in place. + +However, if you decide to remove them after completing the walkthrough, you can use the following gcloud commands: +> These commands will delete the firewall rules and network configurations created during the walkthrough. Make sure to run them only if you no longer need these settings. + +``` gcloud compute firewall-rules delete allow-tcp-8080 --quiet gcloud compute firewall-rules delete allow-iap --quiet From dcf1f0c35ed4eda752161526b83ebf88a8ba1432 Mon Sep 17 00:00:00 2001 From: Robert Wilkins III <1147229+genome21@users.noreply.github.com> Date: Thu, 20 Apr 2023 03:35:10 +0000 Subject: [PATCH 28/39] add styling --- scripts/walkthroughtutorial.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/walkthroughtutorial.md b/scripts/walkthroughtutorial.md index 3d9401f2e..3731533c1 100644 --- a/scripts/walkthroughtutorial.md +++ b/scripts/walkthroughtutorial.md @@ -39,6 +39,8 @@ The script will: 3. Create a Compute Engine VM instance with the specified configuration and startup script 4. Configure Nginx to serve Langflow on TCP port 8080 +> The process may take approximately 30 minutes to complete. Rest assured that progress is being made, and you'll be able to proceed once the process is finished. + In the next step, you'll learn how to connect to the Langflow VM. ## Connect to the Langflow VM From d427fa9972d4642160338e983e1298d5b8434c4b Mon Sep 17 00:00:00 2001 From: Robert Wilkins III <1147229+genome21@users.noreply.github.com> Date: Thu, 20 Apr 2023 03:36:27 +0000 Subject: [PATCH 29/39] more styling --- scripts/walkthroughtutorial.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/walkthroughtutorial.md b/scripts/walkthroughtutorial.md index 3731533c1..b53d3c6d2 100644 --- a/scripts/walkthroughtutorial.md +++ b/scripts/walkthroughtutorial.md @@ -39,7 +39,7 @@ The script will: 3. Create a Compute Engine VM instance with the specified configuration and startup script 4. Configure Nginx to serve Langflow on TCP port 8080 -> The process may take approximately 30 minutes to complete. Rest assured that progress is being made, and you'll be able to proceed once the process is finished. +> The process may take approximately 30 minutes to complete. Rest assured that progress is being made, and you'll be able to proceed once the process is finished. In the next step, you'll learn how to connect to the Langflow VM. @@ -75,7 +75,7 @@ gcloud compute routers delete nat-client --region us-central1 --quiet The following network settings and services are used during this walkthrough. If you plan to continue using the project after the walkthrough, you may keep these configurations in place. However, if you decide to remove them after completing the walkthrough, you can use the following gcloud commands: -> These commands will delete the firewall rules and network configurations created during the walkthrough. Make sure to run them only if you no longer need these settings. +> These commands will delete the firewall rules and network configurations created during the walkthrough. Make sure to run them only if you no longer need these settings. ``` gcloud compute firewall-rules delete allow-tcp-8080 --quiet From 573f0d6ee796910a051030a73e857b3610db270b Mon Sep 17 00:00:00 2001 From: Robert Wilkins III <1147229+genome21@users.noreply.github.com> Date: Thu, 20 Apr 2023 03:54:58 +0000 Subject: [PATCH 30/39] remove redundant wording --- GCP_DEPLOYMENT.md | 119 +------------------------------- scripts/gcp_setup_tutorial.yaml | 80 --------------------- 2 files changed, 2 insertions(+), 197 deletions(-) delete mode 100644 scripts/gcp_setup_tutorial.yaml diff --git a/GCP_DEPLOYMENT.md b/GCP_DEPLOYMENT.md index 6bbd54097..01686e4ed 100644 --- a/GCP_DEPLOYMENT.md +++ b/GCP_DEPLOYMENT.md @@ -1,122 +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. -> When cloudshell opens, select **Trust this repo**. Some gcloud commands do not run in ephemeral cloudshell. +> When cloudshell opens, select **Trust repo**. Some gcloud commands do not run in ephemeral cloudshell. [![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: - -```bash -# 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 - -``` -> This script sets up a Debian-based VM with the Langflow package, Nginx, and the necessary configurations to run the Langflow Dev environment. The VM will be accessible on TCP port 8080 from any IP address. - -
- -## Connecting to your new Langflow VM -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 \ No newline at end of file +This script sets up a Debian-based VM with the Langflow package, Nginx, and the necessary configurations to run the Langflow Dev environment. \ No newline at end of file diff --git a/scripts/gcp_setup_tutorial.yaml b/scripts/gcp_setup_tutorial.yaml deleted file mode 100644 index f8c5b401c..000000000 --- a/scripts/gcp_setup_tutorial.yaml +++ /dev/null @@ -1,80 +0,0 @@ -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 - - - - 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: - - ``` - 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 - `` From 207f1b03994bd129068c125228ec27e0b19b5181 Mon Sep 17 00:00:00 2001 From: Robert Wilkins III <1147229+genome21@users.noreply.github.com> Date: Thu, 20 Apr 2023 04:43:26 +0000 Subject: [PATCH 31/39] add spot instance support and pricing --- GCP_DEPLOYMENT.md | 31 +++++++-- scripts/deploy_langflow_gcp_spot.sh | 101 ++++++++++++++++++++++++++++ scripts/walkthroughtutorial.md | 7 +- scripts/walkthroughtutorial_spot.md | 88 ++++++++++++++++++++++++ 4 files changed, 221 insertions(+), 6 deletions(-) create mode 100644 scripts/deploy_langflow_gcp_spot.sh create mode 100644 scripts/walkthroughtutorial_spot.md diff --git a/GCP_DEPLOYMENT.md b/GCP_DEPLOYMENT.md index 01686e4ed..0491dabb0 100644 --- a/GCP_DEPLOYMENT.md +++ b/GCP_DEPLOYMENT.md @@ -1,7 +1,30 @@ -# 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. -> When cloudshell opens, select **Trust repo**. Some gcloud commands do not run in ephemeral cloudshell. +# Run Langflow from a New Google Cloud Project +This guide will help you set up a Langflow development VM in a Google Cloud Platform project using Google Cloud Shell. + +> **Note**: When Cloud Shell opens, be sure to select **Trust repo**. Some `gcloud` commands might not run in an ephemeral Cloud Shell environment. + + +## Standard VM [![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) -This script sets up a Debian-based VM with the Langflow package, Nginx, and the necessary configurations to run the Langflow Dev environment. \ No newline at end of file +This script sets up a Debian-based VM with the Langflow package, Nginx, and the necessary configurations to run the Langflow Dev environment. +
+ +## Spot/Preemptible Instance + +[![Open in Cloud Shell - Spot Instance](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) + +When running as a [spot (preemptible) instance](https://cloud.google.com/compute/docs/instances/preemptible), the code and VM will behave the same way as in a regular instance, executing the startup script to configure the environment, install necessary dependencies, and run the Langflow application. However, **due to the nature of spot instances, the VM may be terminated at any time if Google Cloud needs to reclaim the resources**. This makes spot instances suitable for fault-tolerant, stateless, or interruptible workloads that can handle unexpected terminations and restarts. + +## Pricing +
+ +| Component | Regular Cost (Hourly) | Regular Cost (Monthly) | Spot/Preemptible Cost (Hourly) | Spot/Preemptible Cost (Monthly) | Notes | +| -------------- | --------------------- | ---------------------- | ------------------------------ | ------------------------------- | ----- | +| 100 GB Disk | - | $10/month | - | $10/month | Disk cost remains the same for both regular and Spot/Preemptible VMs | +| VM (n1-standard-4) | $0.15/hr | ~$108/month | ~$0.04/hr | ~$29/month | The VM cost can be significantly reduced using a Spot/Preemptible instance | +| **Total** | **$0.15/hr** | **~$118/month** | **~$0.04/hr** | **~$39/month** | Total costs for running the VM and disk 24/7 for an entire month | + +> For a more accurate breakdown of costs, please use the [**GCP Pricing Calculator**](https://cloud.google.com/products/calculator) + diff --git a/scripts/deploy_langflow_gcp_spot.sh b/scripts/deploy_langflow_gcp_spot.sh new file mode 100644 index 000000000..7ddc93b96 --- /dev/null +++ b/scripts/deploy_langflow_gcp_spot.sh @@ -0,0 +1,101 @@ +# 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 \ + -preemptible + +# Remove the temporary file after the VM is created +rm $tempfile diff --git a/scripts/walkthroughtutorial.md b/scripts/walkthroughtutorial.md index b53d3c6d2..0d619090f 100644 --- a/scripts/walkthroughtutorial.md +++ b/scripts/walkthroughtutorial.md @@ -39,7 +39,8 @@ The script will: 3. Create a Compute Engine VM instance with the specified configuration and startup script 4. Configure Nginx to serve Langflow on TCP port 8080 -> The process may take approximately 30 minutes to complete. Rest assured that progress is being made, and you'll be able to proceed once the process is finished. + +> The process may take approximately 30 minutes to complete. Rest assured that progress is being made, and you'll be able to proceed once the process is finished. In the next step, you'll learn how to connect to the Langflow VM. @@ -75,7 +76,9 @@ gcloud compute routers delete nat-client --region us-central1 --quiet The following network settings and services are used during this walkthrough. If you plan to continue using the project after the walkthrough, you may keep these configurations in place. However, if you decide to remove them after completing the walkthrough, you can use the following gcloud commands: -> These commands will delete the firewall rules and network configurations created during the walkthrough. Make sure to run them only if you no longer need these settings. + + +> These commands will delete the firewall rules and network configurations created during the walkthrough. Make sure to run them only if you no longer need these settings. ``` gcloud compute firewall-rules delete allow-tcp-8080 --quiet diff --git a/scripts/walkthroughtutorial_spot.md b/scripts/walkthroughtutorial_spot.md new file mode 100644 index 000000000..168a67046 --- /dev/null +++ b/scripts/walkthroughtutorial_spot.md @@ -0,0 +1,88 @@ +# 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**] + + + +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_spot.sh script to configure the GCP environment and deploy Langflow: + +```sh +gcloud config set project +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 + +> The process may take approximately 30 minutes to complete. Rest assured that progress is being made, and you'll be able to proceed once the process is finished. + +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 and click on the external IP for your VM. Make sure to use HTTP and set the port to 8080 +
**or** +3. Run the following command to display the URL for your Langflow environment: +```bash +export LANGFLOW_IP=$(gcloud compute instances list --filter="NAME=langflow-dev" --format="value(EXTERNAL_IP)") + +echo http://$LANGFLOW_IP:8080 +``` + +4. Click on the Langflow URL in cloudshell to 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 + +``` +The following network settings and services are used during this walkthrough. If you plan to continue using the project after the walkthrough, you may keep these configurations in place. + +However, if you decide to remove them after completing the walkthrough, you can use the following gcloud commands: +> These commands will delete the firewall rules and network configurations created during the walkthrough. Make sure to run them only if you no longer need these settings. + +``` +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 +``` From de5ed466d71471631ecb60d68b2ba0bc5325b10c Mon Sep 17 00:00:00 2001 From: Robert Wilkins III <1147229+genome21@users.noreply.github.com> Date: Thu, 20 Apr 2023 05:10:38 +0000 Subject: [PATCH 32/39] improve grammer and remove nat --- README.md | 7 ++++--- scripts/deploy_langflow_gcp.sh | 11 ----------- scripts/deploy_langflow_gcp_spot.sh | 11 ----------- scripts/walkthroughtutorial.md | 5 ----- 4 files changed, 4 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index eaaf84331..3be5d99a9 100644 --- a/README.md +++ b/README.md @@ -30,11 +30,12 @@ Next, run: ### 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. +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. +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=walkthroughtutorial_spot.md) -[![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 diff --git a/scripts/deploy_langflow_gcp.sh b/scripts/deploy_langflow_gcp.sh index 3e20e9589..2c3dc0420 100644 --- a/scripts/deploy_langflow_gcp.sh +++ b/scripts/deploy_langflow_gcp.sh @@ -38,17 +38,6 @@ 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 diff --git a/scripts/deploy_langflow_gcp_spot.sh b/scripts/deploy_langflow_gcp_spot.sh index 7ddc93b96..065b6013f 100644 --- a/scripts/deploy_langflow_gcp_spot.sh +++ b/scripts/deploy_langflow_gcp_spot.sh @@ -38,17 +38,6 @@ 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 diff --git a/scripts/walkthroughtutorial.md b/scripts/walkthroughtutorial.md index 0d619090f..fa6e3c11d 100644 --- a/scripts/walkthroughtutorial.md +++ b/scripts/walkthroughtutorial.md @@ -67,11 +67,6 @@ If you want to remove the resources created during this tutorial, you can use th ```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 - ``` The following network settings and services are used during this walkthrough. If you plan to continue using the project after the walkthrough, you may keep these configurations in place. From 7e3ea1071922093ec06a4e8ce99540cac1621e82 Mon Sep 17 00:00:00 2001 From: Robert Wilkins III <1147229+genome21@users.noreply.github.com> Date: Thu, 20 Apr 2023 05:11:28 +0000 Subject: [PATCH 33/39] remove the nats --- scripts/walkthroughtutorial_spot.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/scripts/walkthroughtutorial_spot.md b/scripts/walkthroughtutorial_spot.md index 168a67046..751f03d78 100644 --- a/scripts/walkthroughtutorial_spot.md +++ b/scripts/walkthroughtutorial_spot.md @@ -66,11 +66,6 @@ If you want to remove the resources created during this tutorial, you can use th ```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 - ``` The following network settings and services are used during this walkthrough. If you plan to continue using the project after the walkthrough, you may keep these configurations in place. From 9869c59e6d851ee88efe2d175e8afeca089a902b Mon Sep 17 00:00:00 2001 From: Robert Wilkins III <1147229+genome21@users.noreply.github.com> Date: Thu, 20 Apr 2023 05:14:37 +0000 Subject: [PATCH 34/39] layout changes --- GCP_DEPLOYMENT.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/GCP_DEPLOYMENT.md b/GCP_DEPLOYMENT.md index 0491dabb0..edb7e043c 100644 --- a/GCP_DEPLOYMENT.md +++ b/GCP_DEPLOYMENT.md @@ -17,7 +17,8 @@ This script sets up a Debian-based VM with the Langflow package, Nginx, and the When running as a [spot (preemptible) instance](https://cloud.google.com/compute/docs/instances/preemptible), the code and VM will behave the same way as in a regular instance, executing the startup script to configure the environment, install necessary dependencies, and run the Langflow application. However, **due to the nature of spot instances, the VM may be terminated at any time if Google Cloud needs to reclaim the resources**. This makes spot instances suitable for fault-tolerant, stateless, or interruptible workloads that can handle unexpected terminations and restarts. -## Pricing +## Pricing (approximate) +> For a more accurate breakdown of costs, please use the [**GCP Pricing Calculator**](https://cloud.google.com/products/calculator)
| Component | Regular Cost (Hourly) | Regular Cost (Monthly) | Spot/Preemptible Cost (Hourly) | Spot/Preemptible Cost (Monthly) | Notes | @@ -25,6 +26,3 @@ When running as a [spot (preemptible) instance](https://cloud.google.com/compute | 100 GB Disk | - | $10/month | - | $10/month | Disk cost remains the same for both regular and Spot/Preemptible VMs | | VM (n1-standard-4) | $0.15/hr | ~$108/month | ~$0.04/hr | ~$29/month | The VM cost can be significantly reduced using a Spot/Preemptible instance | | **Total** | **$0.15/hr** | **~$118/month** | **~$0.04/hr** | **~$39/month** | Total costs for running the VM and disk 24/7 for an entire month | - -> For a more accurate breakdown of costs, please use the [**GCP Pricing Calculator**](https://cloud.google.com/products/calculator) - From 5445f509284a0575a1f6a17715f4158f8b2be9a7 Mon Sep 17 00:00:00 2001 From: Robert Wilkins III <1147229+genome21@users.noreply.github.com> Date: Sun, 14 May 2023 21:10:08 +0000 Subject: [PATCH 35/39] fix GCP walkthrough location --- GCP_DEPLOYMENT.md | 4 ++-- README.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/GCP_DEPLOYMENT.md b/GCP_DEPLOYMENT.md index edb7e043c..36c81e19f 100644 --- a/GCP_DEPLOYMENT.md +++ b/GCP_DEPLOYMENT.md @@ -6,14 +6,14 @@ This guide will help you set up a Langflow development VM in a Google Cloud Plat ## Standard VM -[![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) +[![Open in Cloud Shell](https://gstatic.com/cloudssh/images/open-btn.svg)](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/logspace-ai/langflow&working_dir=scripts&shellonly=true&tutorial=walkthroughtutorial.md) This script sets up a Debian-based VM with the Langflow package, Nginx, and the necessary configurations to run the Langflow Dev environment.
## Spot/Preemptible Instance -[![Open in Cloud Shell - Spot Instance](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) +[![Open in Cloud Shell - Spot Instance](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_spot.md) When running as a [spot (preemptible) instance](https://cloud.google.com/compute/docs/instances/preemptible), the code and VM will behave the same way as in a regular instance, executing the startup script to configure the environment, install necessary dependencies, and run the Langflow application. However, **due to the nature of spot instances, the VM may be terminated at any time if Google Cloud needs to reclaim the resources**. This makes spot instances suitable for fault-tolerant, stateless, or interruptible workloads that can handle unexpected terminations and restarts. diff --git a/README.md b/README.md index a4e1c8868..de98f87a1 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ Follow our step-by-step guide to deploy Langflow on Google Cloud Platform (GCP) 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=walkthroughtutorial_spot.md) +[![Open in Cloud Shell](https://gstatic.com/cloudssh/images/open-btn.svg)](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/logspace-ai/langflow&working_dir=scripts&shellonly=true&tutorial=walkthroughtutorial_spot.md) ### Deploy Langflow on Google Cloud Platform From 2fdce4b14653c85e6b8c7bf70a76d843a39a419b Mon Sep 17 00:00:00 2001 From: Robert Wilkins III <1147229+genome21@users.noreply.github.com> Date: Sun, 14 May 2023 21:24:23 +0000 Subject: [PATCH 36/39] update gcp script for spot instance --- scripts/deploy_langflow_gcp_spot.sh | 2 +- scripts/walkthroughtutorial_spot.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/deploy_langflow_gcp_spot.sh b/scripts/deploy_langflow_gcp_spot.sh index 065b6013f..317540a58 100644 --- a/scripts/deploy_langflow_gcp_spot.sh +++ b/scripts/deploy_langflow_gcp_spot.sh @@ -84,7 +84,7 @@ gcloud compute instances create $VM_NAME \ --zone $ZONE \ --network $VPC_NAME \ --subnet $SUBNET_NAME \ - -preemptible + --preemptible # Remove the temporary file after the VM is created rm $tempfile diff --git a/scripts/walkthroughtutorial_spot.md b/scripts/walkthroughtutorial_spot.md index 751f03d78..a08d95770 100644 --- a/scripts/walkthroughtutorial_spot.md +++ b/scripts/walkthroughtutorial_spot.md @@ -29,7 +29,7 @@ Run the deploy_langflow_gcp_spot.sh script to configure the GCP environment and ```sh gcloud config set project -bash ./deploy_langflow_gcp.sh +bash ./deploy_langflow_gcp_spot.sh ``` The script will: From 51ef093628cda3fcaf2e9c6cb9dcc8de6d7e9249 Mon Sep 17 00:00:00 2001 From: Robert Wilkins III <1147229+genome21@users.noreply.github.com> Date: Sun, 14 May 2023 21:48:22 +0000 Subject: [PATCH 37/39] test without nginx --- scripts/deploy_langflow_gcp_spot.sh | 32 ++++++++++++++--------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/scripts/deploy_langflow_gcp_spot.sh b/scripts/deploy_langflow_gcp_spot.sh index 317540a58..1b3e5c92c 100644 --- a/scripts/deploy_langflow_gcp_spot.sh +++ b/scripts/deploy_langflow_gcp_spot.sh @@ -49,24 +49,24 @@ apt -y upgrade # Install Python 3 pip, Langflow, and Nginx apt -y install python3-pip pip install langflow -apt-get -y install nginx +# apt-get -y install nginx -# Configure Nginx for Langflow -touch /etc/nginx/sites-available/langflow-app -echo "server { - listen 0.0.0.0:8080; +# # 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 +# 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 --host 0.0.0.0 --port 7860 EOF ) From 0803416870e9575ea408ca38c67a6bccbe4d0625 Mon Sep 17 00:00:00 2001 From: Robert Wilkins III <1147229+genome21@users.noreply.github.com> Date: Sun, 14 May 2023 21:50:12 +0000 Subject: [PATCH 38/39] adjust firewall rules for native port --- scripts/deploy_langflow_gcp_spot.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/deploy_langflow_gcp_spot.sh b/scripts/deploy_langflow_gcp_spot.sh index 1b3e5c92c..f43b54c21 100644 --- a/scripts/deploy_langflow_gcp_spot.sh +++ b/scripts/deploy_langflow_gcp_spot.sh @@ -27,9 +27,9 @@ if [[ -z "$subnet_exists" ]]; then 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 +firewall_7860_exists=$(gcloud compute firewall-rules list --filter="name=allow-tcp-7860" --format="value(name)") +if [[ -z "$firewall_7860_exists" ]]; then + gcloud compute firewall-rules create allow-tcp-7860 --network $VPC_NAME --allow tcp:7860 --source-ranges 0.0.0.0/0 --direction INGRESS fi # Create a firewall rule to allow IAP traffic From 4aaa2c280dab5b07f5b234b2bb7d052c5c6c88e9 Mon Sep 17 00:00:00 2001 From: Robert Wilkins III <1147229+genome21@users.noreply.github.com> Date: Sun, 14 May 2023 22:08:13 +0000 Subject: [PATCH 39/39] GPC Shell Script - Websocket Connection Failure #300 --- scripts/deploy_langflow_gcp.sh | 29 ++++++----------------------- scripts/deploy_langflow_gcp_spot.sh | 21 ++------------------- scripts/walkthroughtutorial.md | 8 ++++---- scripts/walkthroughtutorial_spot.md | 8 ++++---- 4 files changed, 16 insertions(+), 50 deletions(-) diff --git a/scripts/deploy_langflow_gcp.sh b/scripts/deploy_langflow_gcp.sh index 2c3dc0420..fbf87099a 100644 --- a/scripts/deploy_langflow_gcp.sh +++ b/scripts/deploy_langflow_gcp.sh @@ -26,16 +26,16 @@ 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 +# Create a firewall rule to allow TCP port 7860 for all instances in the VPC +firewall_7860_exists=$(gcloud compute firewall-rules list --filter="name=allow-tcp-7860" --format="value(name)") +if [[ -z "$firewall_7860_exists" ]]; then + gcloud compute firewall-rules create allow-tcp-7860 --network $VPC_NAME --allow tcp:7860 --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 + gcloud compute firewall-rules create allow-iap --network $VPC_NAME --allow tcp:80,tcp:443,tcp:22,:tcp:3389 --source-ranges 35.235.240.0/20 --direction INGRESS fi # Define the startup script as a multiline Bash here-doc @@ -49,24 +49,7 @@ 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 +langflow --host 0.0.0.0 --port 7860 EOF ) diff --git a/scripts/deploy_langflow_gcp_spot.sh b/scripts/deploy_langflow_gcp_spot.sh index f43b54c21..9291ddcc3 100644 --- a/scripts/deploy_langflow_gcp_spot.sh +++ b/scripts/deploy_langflow_gcp_spot.sh @@ -26,7 +26,7 @@ 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 +# Create a firewall rule to allow TCP port 7860 for all instances in the VPC firewall_7860_exists=$(gcloud compute firewall-rules list --filter="name=allow-tcp-7860" --format="value(name)") if [[ -z "$firewall_7860_exists" ]]; then gcloud compute firewall-rules create allow-tcp-7860 --network $VPC_NAME --allow tcp:7860 --source-ranges 0.0.0.0/0 --direction INGRESS @@ -35,7 +35,7 @@ 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 + gcloud compute firewall-rules create allow-iap --network $VPC_NAME --allow tcp:80,tcp:443,tcp:22,:tcp:3389 --source-ranges 35.235.240.0/20 --direction INGRESS fi # Define the startup script as a multiline Bash here-doc @@ -49,23 +49,6 @@ 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 --host 0.0.0.0 --port 7860 EOF ) diff --git a/scripts/walkthroughtutorial.md b/scripts/walkthroughtutorial.md index fa6e3c11d..83ea3086a 100644 --- a/scripts/walkthroughtutorial.md +++ b/scripts/walkthroughtutorial.md @@ -37,7 +37,7 @@ 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 +4. Run Langflow to serve content on TCP port 7860 > The process may take approximately 30 minutes to complete. Rest assured that progress is being made, and you'll be able to proceed once the process is finished. @@ -47,13 +47,13 @@ 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 and click on the external IP for your VM. Make sure to use HTTP and set the port to 8080 +1. Navigate to the [VM instances](https://console.cloud.google.com/compute/instances) page and click on the external IP for your VM. Make sure to use HTTP and set the port to 7860
**or** 3. Run the following command to display the URL for your Langflow environment: ```bash export LANGFLOW_IP=$(gcloud compute instances list --filter="NAME=langflow-dev" --format="value(EXTERNAL_IP)") -echo http://$LANGFLOW_IP:8080 +echo http://$LANGFLOW_IP:7860 ``` 4. Click on the Langflow URL in cloudshell to be greeted by the Langflow Dev environment @@ -76,7 +76,7 @@ However, if you decide to remove them after completing the walkthrough, you can > These commands will delete the firewall rules and network configurations created during the walkthrough. Make sure to run them only if you no longer need these settings. ``` -gcloud compute firewall-rules delete allow-tcp-8080 --quiet +gcloud compute firewall-rules delete allow-tcp-7860 --quiet gcloud compute firewall-rules delete allow-iap --quiet diff --git a/scripts/walkthroughtutorial_spot.md b/scripts/walkthroughtutorial_spot.md index a08d95770..3792bc1ca 100644 --- a/scripts/walkthroughtutorial_spot.md +++ b/scripts/walkthroughtutorial_spot.md @@ -37,7 +37,7 @@ 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 +4. Run Langflow to serve content on TCP port 7860 > The process may take approximately 30 minutes to complete. Rest assured that progress is being made, and you'll be able to proceed once the process is finished. @@ -46,13 +46,13 @@ 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 and click on the external IP for your VM. Make sure to use HTTP and set the port to 8080 +1. Navigate to the [VM instances](https://console.cloud.google.com/compute/instances) page and click on the external IP for your VM. Make sure to use HTTP and set the port to 7860
**or** 3. Run the following command to display the URL for your Langflow environment: ```bash export LANGFLOW_IP=$(gcloud compute instances list --filter="NAME=langflow-dev" --format="value(EXTERNAL_IP)") -echo http://$LANGFLOW_IP:8080 +echo http://$LANGFLOW_IP:7860 ``` 4. Click on the Langflow URL in cloudshell to be greeted by the Langflow Dev environment @@ -73,7 +73,7 @@ However, if you decide to remove them after completing the walkthrough, you can > These commands will delete the firewall rules and network configurations created during the walkthrough. Make sure to run them only if you no longer need these settings. ``` -gcloud compute firewall-rules delete allow-tcp-8080 --quiet +gcloud compute firewall-rules delete allow-tcp-7860 --quiet gcloud compute firewall-rules delete allow-iap --quiet