Build a detonation velocity website with Cloud Run and Python (Flask)

Build a detonation velocity website with Cloud Run and Python (Flask)

I created a website for #Weekend Hackathon, so I decided to publish it. There are many options such as AWS and rental server, but this time I decided to use Cloud Run, which is serverless and can be operated almost free of charge.

Install Google Cloud SDK

Download from Google Cloud SDK

Move to the download directory, execute sh, proceed with basic y Reboot the terminal after installation

$ sh install.sh

Version confirmation

$ gcloud version
Google Cloud SDK 321.0.0
bq 2.0.64
core 2020.12.11
gsutil 4.57

SDK settings

Since the browser opens, log in with the operation account Then select the operation project

$ gcloud init

If you want to change the project

$ gcloud config set project [Project name]

Build

Build a Docker image using Cloud Build Create Dockerfile

FROM python:3.7.4

WORKDIR /app
ADD . /app

RUN apt-get update && apt-get clean;

RUN pip install -r requirements.txt

ENV TZ = "Asia/Tokyo"
ENV FLASK_APP /app/app.py
ENV PYTHONPATH $PYTHONPATH:/app

ENV PORT 8080
EXPOSE 8080

CMD ["python", "app.py"]

Build execution

$ gcloud builds submit --tag gcr.io/weekend-hackathon/weekend-hackathon

screencapture-console-cloud-google-cloud-build-builds-2021-01-19-10_01_43.png

Deploy

Deploy a container built using Cloud Run

$ gcloud run deploy weekend-hackathon --project=weekend-hackathon --image=gcr.io/weekend-hackathon/weekend-hackathon --region=us-central1 --platform=managed --no-allow-unauthenticated

Deploying container to Cloud Run service [weekend-hackathon] in project [weekend-hackathon] region [us-central1]
✓ Deploying new service... Done.
  ✓ Creating Revision...
  ✓ Routing traffic...
Done.
Service [weekend-hackathon] revision [weekend-hackathon-00001-teq] has been deployed and is serving 100 percent of traffic.
Service URL: https://weekend-hackathon-leopsotyca-uc.a.run.app

Add permissions

$ gcloud run services add-iam-policy-binding weekend-hackathon --region=us-central1 --member="allUsers" --role="roles/run.invoker" --platform=managed
Updated IAM policy for service [weekend-hackathon].
bindings:
- members:
  - allUsers
  role: roles/run.invoker
etag: BwW5NtPWfrM=
version: 1

If you access the URL and the site is displayed, you are done https://weekend-hackathon-leopsotyca-uc.a.run.app

screencapture-localhost-8080-2021-01-15-2021-01-18-2021-01-19-10_36_10.png

Supplement

In operation, create deploy_run.sh so that it can be deployed all at once. Since the local Docker environment can be published as it is, it can be published at explosive speed Also, Cloud Run is a charge per access, so it is ideal for the initial release. Please try it.

Recommended Posts

Build a detonation velocity website with Cloud Run and Python (Flask)
Launch a web server with Python and Flask
Run a machine learning pipeline with Cloud Dataflow (Python)
Build a python virtual environment with virtualenv and virtualenvwrapper
Build a python virtual environment with virtualenv and virtualenvwrapper
Until you install Python with pythonbrew and run Flask on a WSGI server
Run XGBoost with Cloud Dataflow (Python)
Build a 64-bit Python 2.7 environment with TDM-GCC and MinGW-w64 on Windows 7
Build a Python environment on your Mac with Anaconda and PyCharm
I made a Nyanko tweet form with Python, Flask and Heroku
POST variously with Python and receive with Flask
A memo with Python2.7 and Python3 on CentOS
Run a Python web application with Docker
Build a python virtual environment with pyenv
Build a Python + OpenCV environment on Cloud9
Build a modern Python environment with Neovim
[GCP] Procedure for creating a web application with Cloud Functions (Python + Flask)
Build a development environment using Jupyter and Flask with Python in Docker (supports both VS Code / code-server)
Building a python environment with virtualenv and direnv
Build a python environment with ansible on centos6
[Python] Build a Django development environment with Docker
Create a python3 build environment with Sublime Text3
Easily realize microservices with Cloud Run x Flask
Build a virtual environment with pyenv and venv
Compile and run Rust with a single command
Let's write a Python program and run it
Run Flask on CentOS with python3.4, Gunicorn + Nginx.
Build a Python environment with OSX El capitan
Quickly build a Python Django environment with IntelliJ
Build PyPy and Python execution environment with Docker
Build a Python machine learning environment with a container
Build a python execution environment with VS Code
I made a Mattermost bot with Python (+ Flask)
Put Docker in Windows Home and run a simple web server with Python
Build a Python + bottle + MySQL environment with Docker on RaspberryPi3! [Trial and error]
[ES Lab] I tried to develop a WEB application with Python and Flask ②
Build a flask app made with tensorflow and dlib to work on centos7
WEB scraping with python and try to make a word cloud from reviews
Try making a simple website with responder and sqlite3
Run Python with VBA
Run prepDE.py with python3
Build API server for checking the operation of front implementation with python3 and Flask
Build a python environment for each directory with pyenv-virtualenv
Let's make a simple game with Python 3 and iPhone
Parse and visualize JSON (Web application ⑤ with Python + Flask)
Run Blender with python
I made a LINE BOT with Python and Heroku
Build a machine learning application development environment with Python
A server that echoes data POSTed with flask / python
Run Google Cloud Functions locally with Cloud Native Build packs
Run a Python file with relative import in PyCharm
Until you create a machine learning environment with Python on Windows 7 and run it
Cloud Run tutorial (python)
Programming with Python Flask
I want to run a quantum computer with Python
Build a numerical calculation environment with pyenv and miniconda3
Run iperf with python
Easy to use Nifty Cloud API with botocore and python
Build a machine learning scikit-learn environment with VirtualBox and Ubuntu
Recommendations for django, wagtail ~ Why develop a website with python ~
Associate Python Enum with a function and make it Callable