Skip to content

fsmosca/rflask

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Deploy reactpy app with flask backend to GCP.

Guide

Visit https://console.cloud.google.com/getting-started

1. Create project

Be sure to setup billing too.

2. Access Settings

Navigation Menu -> IAM & Admin -> Settings

3. Activate Cloud Shell

Press that button at top right.

4. Clone this repo

You may use this repo just for testing. A quick way to copy files and folders into the google cloud.

git clone https://github.com/fsmosca/rflask.git

5. Change directory to rflask

cd rflask

6. Create virtual environment.

This is only local with respect to the machine in GCP that we are using. This is different when we actually deploy our app.

python -m venv venv

7. Activate the venv

source venv/bin/activate

8. Install the modules in the requirements.txt

To test if the contents of our requirements.txt file is right.

pip install -r requirements.txt

9. Test it

We are not deploying for production yet. Just testing the virtual environment.

gunicorn main:app

You should see the following from the given url.

"Hello, world!"

Send control+c in the shell to exit.

10. Create app

Now let us create an app for production. This is the real deal that we are up to.

gcloud app create

11. Deploy the app

The app.yaml is using flexible environment, you can open the app.yaml file. Flexible uses a container. There are comments in app.yaml file. Read the items in the reference section too.

gcloud app deploy --appyaml=app.yaml

This is our app.yaml.

runtime: python

# F1 = 2 workers (default), F2 = 4 workers
instance_class: F1

env: flex

# -w 2 sets gunicorn number of workers
# The number of workers you specify should match the instance class of your App Engine app:
entrypoint: gunicorn -b :$PORT -w 2 main:app

runtime_config:
    operating_system: "ubuntu22"
    runtime_version: "3.11"

12. Shutdown

Be sure to shutdown your project if you are just testing it.

Even better is to delete the project so that it is disconnected from the billing.

Note

  • The app.yaml is using flexible environment. Attempts to use standard environment did not work so far.
  • We use gunicorn in entry point at app.yaml, so we need gunicorn in requirements.txt

Reference

Releases

No releases published

Packages

No packages published

Languages