From b6d6e7ed47f5d4bf10bb75627568942490df9654 Mon Sep 17 00:00:00 2001 From: elric97 Date: Tue, 23 Nov 2021 13:16:36 -0500 Subject: [PATCH 1/7] Changes for heroku deployment --- backend/Procfile | 1 + backend/app.py | 9 +++++++-- backend/ping.py | 6 ++++++ backend/products.py | 4 ++-- backend/requirements.txt | 3 ++- 5 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 backend/Procfile create mode 100644 backend/ping.py diff --git a/backend/Procfile b/backend/Procfile new file mode 100644 index 0000000..8001d1a --- /dev/null +++ b/backend/Procfile @@ -0,0 +1 @@ +web: gunicorn app:app \ No newline at end of file diff --git a/backend/app.py b/backend/app.py index 92d54e4..64a02b1 100644 --- a/backend/app.py +++ b/backend/app.py @@ -4,14 +4,19 @@ from flask import Flask from os import environ from flask_cors import CORS +import waitress app = Flask(__name__) from auth_controller import * from products import * from product_controller import * from db_init import db +from ping import * + app.secret_key = "testing" CORS(app) -#if __name__ == "__main__": -# app.run(debug=True, port=environ.get("PORT", 5000) , host='0.0.0.0') +if __name__ == "__main__": + app.run(debug=True, port=environ.get("PORT", 5000), host='0.0.0.0') + # app.debug = True + # waitress.serve(app, port=environ.get("PORT", 5000)) diff --git a/backend/ping.py b/backend/ping.py new file mode 100644 index 0000000..4036807 --- /dev/null +++ b/backend/ping.py @@ -0,0 +1,6 @@ +from app import app + + +@app.route('/ping', methods=['GET']) +def ping(): + return "Ping Pong" diff --git a/backend/products.py b/backend/products.py index c3008f9..d663d7c 100644 --- a/backend/products.py +++ b/backend/products.py @@ -9,7 +9,7 @@ import os from sys import stderr -from flask import request, jsonify +from flask import request, jsonify, Response from flask import json from app import app @@ -102,7 +102,7 @@ def features(product_name): return Response(response=json.dumps({"Error": "Please provide connection information"}), status=400, mimetype='application/json') - result = product_records.find_one_and_update({"name": productname}, {"$set": {"features": data}}) + result = product_records.find_one_and_update({"name": product_name}, {"$set": {"features": data}}) elif request.method == 'GET': result = product_records.find({"name": product_name}, {"features": 1}) diff --git a/backend/requirements.txt b/backend/requirements.txt index 472f71a..b433a2d 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -29,4 +29,5 @@ toml==0.10.2 urllib3==1.21.1 Werkzeug==2.0.1 bcrypt==3.2.0 - +waitress==2.0.0 +gunicorn From be358e6fc14da134c189b9b0c8d3f0f73e813af5 Mon Sep 17 00:00:00 2001 From: elric97 Date: Tue, 23 Nov 2021 13:19:46 -0500 Subject: [PATCH 2/7] removed host --- backend/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/app.py b/backend/app.py index 64a02b1..acbd4d8 100644 --- a/backend/app.py +++ b/backend/app.py @@ -17,6 +17,6 @@ CORS(app) if __name__ == "__main__": - app.run(debug=True, port=environ.get("PORT", 5000), host='0.0.0.0') + app.run(debug=True, port=environ.get("PORT", 5000)) # app.debug = True # waitress.serve(app, port=environ.get("PORT", 5000)) From 03e75f9c2618d007525ee65e40d3514438fabb3d Mon Sep 17 00:00:00 2001 From: elric97 Date: Tue, 23 Nov 2021 13:25:25 -0500 Subject: [PATCH 3/7] Removed waitress import --- backend/app.py | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/app.py b/backend/app.py index acbd4d8..4e199ac 100644 --- a/backend/app.py +++ b/backend/app.py @@ -4,7 +4,6 @@ from flask import Flask from os import environ from flask_cors import CORS -import waitress app = Flask(__name__) from auth_controller import * From 387cfdb3df937787a54f6fc0820b381ea27aa18b Mon Sep 17 00:00:00 2001 From: elric97 Date: Tue, 23 Nov 2021 13:36:18 -0500 Subject: [PATCH 4/7] Removed app.run parameters --- backend/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/app.py b/backend/app.py index 4e199ac..09af7e3 100644 --- a/backend/app.py +++ b/backend/app.py @@ -16,6 +16,6 @@ CORS(app) if __name__ == "__main__": - app.run(debug=True, port=environ.get("PORT", 5000)) + app.run() # app.debug = True # waitress.serve(app, port=environ.get("PORT", 5000)) From 697aaaa6a9b1524d8324aa9d32c5fe0f7570115e Mon Sep 17 00:00:00 2001 From: elric97 Date: Tue, 23 Nov 2021 13:58:13 -0500 Subject: [PATCH 5/7] Updated procfile --- backend/Procfile | 2 +- backend/app.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/backend/Procfile b/backend/Procfile index 8001d1a..e9aece8 100644 --- a/backend/Procfile +++ b/backend/Procfile @@ -1 +1 @@ -web: gunicorn app:app \ No newline at end of file +web: gunicorn -b :$PORT app:app \ No newline at end of file diff --git a/backend/app.py b/backend/app.py index 09af7e3..efe4c2d 100644 --- a/backend/app.py +++ b/backend/app.py @@ -16,6 +16,7 @@ CORS(app) if __name__ == "__main__": - app.run() + port = int(os.environ.get('PORT', 5000)) + app.run(host='0.0.0.0', port=port, debug=True) # app.debug = True # waitress.serve(app, port=environ.get("PORT", 5000)) From 34a3f178ee13bff14a5778b39ec5871e11f8ea62 Mon Sep 17 00:00:00 2001 From: elric97 Date: Tue, 23 Nov 2021 14:27:28 -0500 Subject: [PATCH 6/7] Testing automation --- .github/workflows/deploy.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..9d6c881 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,19 @@ +name: Deploy + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: akhileshns/heroku-deploy@v3.12.12 # This is the action + with: + heroku_api_key: ${{secrets.HEROKU_API_KEY}} + heroku_app_name: "feature-hunt-github" #Must be unique in Heroku + heroku_email: "sharma.rachit882@gmail.com" + appdir: "backend" \ No newline at end of file From cd8fee638665f33ac63eb24df3263358afe6790f Mon Sep 17 00:00:00 2001 From: elric97 Date: Tue, 23 Nov 2021 14:34:45 -0500 Subject: [PATCH 7/7] Testing for a new heroku app --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 9d6c881..09fe774 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -14,6 +14,6 @@ jobs: - uses: akhileshns/heroku-deploy@v3.12.12 # This is the action with: heroku_api_key: ${{secrets.HEROKU_API_KEY}} - heroku_app_name: "feature-hunt-github" #Must be unique in Heroku + heroku_app_name: "feature-hunt-automated" #Must be unique in Heroku heroku_email: "sharma.rachit882@gmail.com" appdir: "backend" \ No newline at end of file