diff --git a/mrvn_flask/cloudmigrate.yaml b/mrvn_flask/cloudmigrate.yaml new file mode 100644 index 0000000..b1da787 --- /dev/null +++ b/mrvn_flask/cloudmigrate.yaml @@ -0,0 +1,6 @@ +steps: +- name: "gcr.io/cloud-builders/docker" + args: ["build", "-t", "gcr.io/projects-300508/mrvn_flask", "."] + +- name: "gcr.io/cloud-builders/docker" + args: ["push", "gcr.io/projects-300508/mrvn_flask"] \ No newline at end of file diff --git a/mrvn_flask/__init__.py b/mrvn_flask/flaskapp/__init__.py similarity index 89% rename from mrvn_flask/__init__.py rename to mrvn_flask/flaskapp/__init__.py index 73347c8..06e6880 100644 --- a/mrvn_flask/__init__.py +++ b/mrvn_flask/flaskapp/__init__.py @@ -6,12 +6,13 @@ import google.auth from google.cloud import secretmanager_v1beta1 as sm except ImportError: + print("Import Error raised.") pass BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) env_file = os.path.join(BASE_DIR, ".env") -SETTINGS_NAME = "application_settings" +SETTINGS_NAME = "flask_app_settings" def create_app(test_config=None): # create and configure the app @@ -33,6 +34,7 @@ def create_app(test_config=None): env.read_env(env_file) SECRET_KEY= env('SECRET_KEY'), # DATABASE=os.path.join(app.instance_path, 'flaskr.sqlite'), + os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = "env('GOOGLE_APPLICATION_CREDENTIALS')" ) if test_config is None: # load the instance config, if it exists, when not testing diff --git a/mrvn_flask/flaskapp/get_from_firestore.py b/mrvn_flask/flaskapp/get_from_firestore.py new file mode 100644 index 0000000..934e5c2 --- /dev/null +++ b/mrvn_flask/flaskapp/get_from_firestore.py @@ -0,0 +1,14 @@ +from google.cloud import firestore +try: + import google.auth + from google.cloud import secretmanager_v1beta1 as sm +except ImportError: + print("Import Error raised.") + pass + +def my_reddit_comments(): + db = firestore.Client() + coll = db.collection('tagapagtuos_submissions').stream() + db = None + + return [doc.to_dict() for doc in coll] \ No newline at end of file diff --git a/mrvn_flask/home.py b/mrvn_flask/flaskapp/home.py similarity index 54% rename from mrvn_flask/home.py rename to mrvn_flask/flaskapp/home.py index 48fa3cc..3952257 100644 --- a/mrvn_flask/home.py +++ b/mrvn_flask/flaskapp/home.py @@ -2,21 +2,16 @@ from flask import ( Blueprint, flash, g, redirect, render_template, request, session, url_for ) -from google.cloud import firestore + +from .get_from_firestore import my_reddit_comments + bp = Blueprint('home', __name__) -@bp.route('/', methods=['GET']) +@bp.route('/sample', methods=['GET']) def home(): context = my_reddit_comments() return render_template('sample.html', context=context) -def my_reddit_comments(): - db = firestore.Client() - coll = db.collection('tagapagtuos_submissions').stream() - db = None - - return [doc.to_dict() for doc in coll] - -@bp.route('/cv') +@bp.route('/') def baseee(): return render_template('home.html') \ No newline at end of file diff --git a/mrvn_flask/flaskapp2/Dockerfile b/mrvn_flask/flaskapp2/Dockerfile new file mode 100644 index 0000000..1e45a0c --- /dev/null +++ b/mrvn_flask/flaskapp2/Dockerfile @@ -0,0 +1,8 @@ +FROM python:3.8-slim +RUN apt-get update -y +RUN apt-get install -y python-pip python-dev build-essential +COPY . /app +WORKDIR /app +RUN pip install -r requirements.txt +ENTRYPOINT ["python"] +CMD ["app.py"] \ No newline at end of file diff --git a/mrvn_flask/flaskapp2/app.py b/mrvn_flask/flaskapp2/app.py new file mode 100644 index 0000000..dc892f1 --- /dev/null +++ b/mrvn_flask/flaskapp2/app.py @@ -0,0 +1,47 @@ +''' +Adapted from "Build and deploy a Flask CRUD API with Firestore and Cloud Run" +Author: @timtech4u +https://cloud.google.com/community/tutorials/building-flask-api-with-cloud-firestore-and-deploying-to-cloud-run +''' + +# Required imports +import os +from flask import Flask, request, render_template +#from firebase_admin import credentials, firestore, initialize_app + + +# Initialize Flask app +app = Flask(__name__) + +# Initialize Firestore DB +#cred = credentials.Certificate('key.json') +#default_app = initialize_app(cred) +#db = firestore.client() +#todo_ref = db.collection('todos') +''' +from google.cloud import firestore +try: + import google.auth + from google.cloud import secretmanager_v1beta1 as sm +except ImportError: + print("Import Error raised.") + pass + +def my_reddit_comments(): + db = firestore.Client() + coll = db.collection('tagapagtuos_submissions').stream() + db = None + return [doc.to_dict() for doc in coll] + +@app.route('/sample', methods=['GET']) +def sample(): + context = my_reddit_comments() + return render_template('sample.html', context=context) +''' +@app.route('/') +def home(): + return render_template('home.html') + +port = int(os.environ.get('PORT', 8080)) +if __name__ == '__main__': + app.run(threaded=True, host='0.0.0.0', port=port) \ No newline at end of file diff --git a/mrvn_flask/flaskapp2/requirements.txt b/mrvn_flask/flaskapp2/requirements.txt new file mode 100644 index 0000000..17c90e8 --- /dev/null +++ b/mrvn_flask/flaskapp2/requirements.txt @@ -0,0 +1,26 @@ +cachetools==4.2.0 +certifi==2020.12.5 +chardet==4.0.0 +click==7.1.2 +Flask==1.1.2 +google-api-core==1.24.1 +google-auth==1.24.0 +google-cloud-core==1.5.0 +google-cloud-firestore==2.0.2 +googleapis-common-protos==1.52.0 +grpcio==1.34.0 +gunicorn==20.0.4 +idna==2.10 +itsdangerous==1.1.0 +Jinja2==2.11.2 +MarkupSafe==1.1.1 +proto-plus==1.13.0 +protobuf==3.14.0 +pyasn1==0.4.8 +pyasn1-modules==0.2.8 +pytz==2020.5 +requests==2.25.1 +rsa==4.6 +six==1.15.0 +urllib3==1.26.2 +Werkzeug==1.0.1 diff --git a/mrvn_flask/templates/base.html b/mrvn_flask/flaskapp2/templates/base.html similarity index 100% rename from mrvn_flask/templates/base.html rename to mrvn_flask/flaskapp2/templates/base.html diff --git a/mrvn_flask/templates/home.html b/mrvn_flask/flaskapp2/templates/home.html similarity index 100% rename from mrvn_flask/templates/home.html rename to mrvn_flask/flaskapp2/templates/home.html diff --git a/mrvn_flask/flaskapp2/templates/sample.html b/mrvn_flask/flaskapp2/templates/sample.html new file mode 100644 index 0000000..138ce5b --- /dev/null +++ b/mrvn_flask/flaskapp2/templates/sample.html @@ -0,0 +1,161 @@ +{% extends 'base.html' %} +{% block container %} + + +
+ {{ i['subreddit']}}
+ {{ i['date']}}
+ {{ i['body']}}
+ {{ i['url']}}
+ -----------------
+
Marvin D. Tensuan
+Curriculum Vitae
+ +Assist in the creation of a global-scope FX team.
++ The FX Management team is mandated to hedge cost-related foreign currency transactions incurred from major Deutsche Bank branches across US, UK, and APAC. +
Certified Public Accountant
+Philippine Regulatory Board of Accountancy (May 2018 – present)
+Philippine Institute of Certified Public Accountants
+Polytechnic University of the Philippines (June 2013 to October 2017)
+Extra and co-curricular activities:
+(June 2009 to March 2013)
+(June 2003 to March 2009)
+