changeset 131:221d6ea7c6c8

cs: add cs_flask_app files
author paulo
date Thu, 20 Jan 2022 00:44:05 -0800
parents 06f97e38e1b2
children 99e4022eae52
files cs/Dockerfile cs/cs_flask_app.py cs/flask_run_dev.sh cs/requirements.pip
diffstat 4 files changed, 80 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/cs/Dockerfile	Thu Jan 20 00:44:05 2022 -0800
     1.3 @@ -0,0 +1,17 @@
     1.4 +# Use the official lightweight Python image.
     1.5 +# https://hub.docker.com/_/python
     1.6 +FROM python:3.6-slim 
     1.7 +
     1.8 +# Copy local code to the container image.
     1.9 +ENV APP_HOME /app
    1.10 +WORKDIR $APP_HOME
    1.11 +COPY . ./
    1.12 +
    1.13 +# Install production dependencies.
    1.14 +RUN pip install -r requirements.pip
    1.15 +
    1.16 +# Run the web service on container startup. Here we use the gunicorn
    1.17 +# webserver, with one worker process and 8 threads.
    1.18 +# For environments with multiple CPU cores, increase the number of workers
    1.19 +# to be equal to the cores available.
    1.20 +CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 --timeout 0 cs_flask_app:app
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/cs/cs_flask_app.py	Thu Jan 20 00:44:05 2022 -0800
     2.3 @@ -0,0 +1,23 @@
     2.4 +import os
     2.5 +
     2.6 +import flask
     2.7 +import google.cloud.storage
     2.8 +from html3.html3 import HTML
     2.9 +
    2.10 +app = flask.Flask(__name__)
    2.11 +
    2.12 +GCS_CLIENT = google.cloud.storage.Client()
    2.13 +GCS_BUCKET = GCS_CLIENT.get_bucket(os.environ.get("GCS_BUCKET"))
    2.14 +
    2.15 +@app.route("/")
    2.16 +def index():
    2.17 +  return flask.redirect(flask.url_for("file_serve", filename="index.html"))
    2.18 +
    2.19 +
    2.20 +@app.route("/<filename>")
    2.21 +def file_serve(filename):
    2.22 +  file_blob = GCS_BUCKET.get_blob(f"cs/{filename}")
    2.23 +  if not file_blob:
    2.24 +    flask.abort(404)
    2.25 +
    2.26 +  return flask.send_file(file_blob.open("rb"), download_name=filename)
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/cs/flask_run_dev.sh	Thu Jan 20 00:44:05 2022 -0800
     3.3 @@ -0,0 +1,8 @@
     3.4 +#!/bin/sh
     3.5 +
     3.6 +export GOOGLE_APPLICATION_CREDENTIALS=dev.key.json
     3.7 +export GCS_BUCKET=dev.pauloang.com
     3.8 +export FLASK_APP=cs_flask_app.py
     3.9 +export FLASK_ENV=development
    3.10 +
    3.11 +./bin/flask run
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/cs/requirements.pip	Thu Jan 20 00:44:05 2022 -0800
     4.3 @@ -0,0 +1,32 @@
     4.4 +cachetools==4.2.2
     4.5 +certifi==2021.5.30
     4.6 +cffi==1.14.6
     4.7 +charset-normalizer==2.0.6
     4.8 +click==8.0.1
     4.9 +dataclasses==0.8
    4.10 +Flask==2.0.1
    4.11 +google-api-core==2.0.1
    4.12 +google-auth==2.1.0
    4.13 +google-cloud-core==2.0.0
    4.14 +google-cloud-storage==1.42.2
    4.15 +google-crc32c==1.1.2
    4.16 +google-resumable-media==2.0.2
    4.17 +googleapis-common-protos==1.53.0
    4.18 +gunicorn==20.1.0
    4.19 +html3==1.18
    4.20 +idna==3.2
    4.21 +importlib-metadata==4.8.1
    4.22 +itsdangerous==2.0.1
    4.23 +Jinja2==3.0.1
    4.24 +MarkupSafe==2.0.1
    4.25 +protobuf==3.18.0
    4.26 +pyasn1==0.4.8
    4.27 +pyasn1-modules==0.2.8
    4.28 +pycparser==2.20
    4.29 +requests==2.26.0
    4.30 +rsa==4.7.2
    4.31 +six==1.16.0
    4.32 +typing-extensions==3.10.0.2
    4.33 +urllib3==1.26.6
    4.34 +Werkzeug==2.0.1
    4.35 +zipp==3.5.0