Address issue #300 - GCP Shell Script - Websocket Connection Failure (#301)

This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-05-16 01:20:57 +00:00 committed by GitHub
commit 636b60bab4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 33 additions and 58 deletions

View file

@ -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.
<hr>
## 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.

View file

@ -37,6 +37,15 @@ or
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/logspace-ai/langflow&working_dir=scripts&shellonly=true&tutorial=walkthroughtutorial_spot.md)
### 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.

View file

@ -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
)

View file

@ -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
)
@ -84,7 +67,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

View file

@ -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
<walkthrough-pin-section-icon></walkthrough-pin-section-icon>
> 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
<br>**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

View file

@ -29,7 +29,7 @@ Run the deploy_langflow_gcp_spot.sh script to configure the GCP environment and
```sh
gcloud config set project <walkthrough-project-id/>
bash ./deploy_langflow_gcp.sh
bash ./deploy_langflow_gcp_spot.sh
```
The script will:
@ -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
> <walkthrough-pin-section-icon></walkthrough-pin-section-icon> 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
<br>**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
> <walkthrough-pin-section-icon></walkthrough-pin-section-icon> 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