Reflex app deployment on GCP Compute Engine #1604
Replies: 4 comments
-
Nice thanks for the tutorial! |
Beta Was this translation helpful? Give feedback.
-
If you don't want to fill your external_ip manually, you can even find it through python subprocess cmd : import subprocess
ip_address = subprocess.Popen(
[
'gcloud compute instances list --format json | jq -r ".[].networkInterfaces[0].accessConfigs[0].natIP"'
]
) |
Beta Was this translation helpful? Give feedback.
-
Hi, Thank you for the tutorial. I followed the provided instruction and i am able to run my app on GCE. However, I am unable to access the reflex-app on my computer. However on my computer on firefox: The connection was reset The connection to the server was reset while the page was loading. Please let me know if i missed some something. Thank you |
Beta Was this translation helpful? Give feedback.
-
Thanks, I managed to make it work. I needed to click on |
Beta Was this translation helpful? Give feedback.
-
First, you need to create a Compute Engine instance. I recommend Ubuntu 22 because it has python 3.10 by default and saves us a lot of problems. If you don't know how to create it, read this.
Once you create it, make sure that ports 8000 and 3000 are allowed in the firewall. By default, they are not, so we have to create a firewall rules. My rule looks like this:
Now, I will assume you used Ubuntu 22 as the OS of the instance.
You have to use ssh to connect to the instance. To do that there are a lot of methods but I'll keep it simple and I will use GCP ssh:
Once we are connected, we execute the following commands:
sudo apt-get update
sudo apt-get install python3-pip nodejs zip
python3 -m pip install reflex
PATH=$PATH:/home/<your_username>/.local/bin
Now clone your repo where your Reflex app is:
git clone https://github.com/<your_repo>
After cloning the app, we go into the folder and init the app:
cd your_reflex_app/
reflex init
Make sure that your app config looks something like this:
where external_ip is the external ip of your Compute Engine instance.
To finish, run the app in production environment (you can use just reflex run to develop):
reflex run --env prod
If something is unclear or missing, please tell me and I will update it.
I hope it helps!
Credits to @picklelo for his Digital Ocean guide. It was a great start to be able to deploy on GCP.
Beta Was this translation helpful? Give feedback.
All reactions