Giter Club home page Giter Club logo

cloudrun-demo's Introduction

Hands on Cloud Run Tutorial

This tutorial will teach you how to deploy a simple client (Javascript/React) and server (Python/FastAPI) to Google Cloud Run. Check out the Video Tutorial here.

Prerequisites

Verify installs by testing the above tools in the command line

gcloud --version
npm --version

Setup

Login to gcloud project

gcloud auth login // prompts for login
gcloud config set project YOUR_GCLOUD_PROJECT
gcloud config get-value project // verify project id

Clone to tutorial repo

git clone https://github.com/VCG/cloudrun-demo.git
cd cloudrun-demo

Deploy Python Server

Install local dependencies and test locally

cd server
python3.9 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

Run the app locally

python main.py
// check http://127.0.0.1:4244/

Have a look at server/Dockerfile. This file defines the container environment that gcloud will use to host your Python application. Also familiarize yourself with the serverless concept of CloudRun. An app deployed in Cloud Run must fulfill those requirements. Now deploy your code using this command from the cloud CLI:

gcloud run deploy <YOUR_NAME>-demo-server --source . --allow-unauthenticated

Once the command has finished successfully finished, visit the URL that is printed in the terminal. You should see the same output as when you ran the app locally. Also, inspect the options that are available for your deployment from the Cloud Console.

Deploy React Client

Navigate to the client directory and install all local dependencies

cd ../client
npm install

Now, update the client/.env.production to the URL that has been generated by the Cloud Run deployment of the server. By using both the client/.env and client/.env.production React knows which URL to use depending on whether you are developing locally or you are using the deployed version. Next, have a look at client/Dockerfile. What is different from server/Dockerfile?

Deploy react client to Cloud Run

gcloud run deploy <YOUR_NAME>-demo-client --source . --allow-unauthenticated

This should give you a URL to your deployed React app if successful. The frontend website should display something like Hello World! - This was loaded dynamically through an endpoint! if everything worked out.

cloudrun-demo's People

Contributors

jakobtroidl avatar simonwarchol avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.