edgaregonzalez / cloud-run-sample-flask

A sample Flask app for a Google Cloud Run demo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cloud-run-sample-flask

1. Introduction

This project is a simple Flask app developed for helping to illustrate how to set up a deployment pipeline on GCP with Cloud Builder, Container Registry and Cloud Run.

Check the complete tutorial here.

2. Environment setup

2.1. Get the code

git clone git@github.com:ivamluz/cloud-run-sample-flask.git
cd cloud-run-sample-flask

2.2. Virtualenv

  • Install Python 3.7+

  • Create and activate an isolated Python environment

    virtualenv venv
    source ./venv/bin/activate
  • Install the dependencies

    pip install --upgrade -r requirements.txt

3. Run the app locally

cd app

HASHED_API_KEY=`../scripts/hash_value.py --value "1234"` \
  gunicorn --bind :8080 --workers 1 --threads 8 app:app --reload

Here, HASHED_API_KEY is a variable used by the application to set up a basic auth mechanism. The intent of this is to show how to configure and use environment variables on Google Cloud Run.

4. Testing the app

From a different terminal instance, run the following command (notice the value for the x-api-key is the unhashed value passed to the HASHED_API_KEY variable in the previous command):

curl \
  -H'x-api-key: 1234' \
  'http://localhost:8080/hello'

Expected Output

{"hello":"world"}

If you see the output above, it means everything is working as expected.

After everything is running, please make sure to keep reading the tutorial.

About

A sample Flask app for a Google Cloud Run demo

License:Apache License 2.0


Languages

Language:Python 70.4%Language:Dockerfile 19.2%Language:Shell 10.4%