Skip to content
This repository has been archived by the owner on Nov 29, 2024. It is now read-only.

Commit

Permalink
Merge pull request #357 from communitiesuk/FS-4560-dependencies-upgrade
Browse files Browse the repository at this point in the history
FS-4560: Application store dependencies upgrade
  • Loading branch information
hamzabinkhalid authored Aug 5, 2024
2 parents 257ad90 + 8af35e4 commit 4dd4907
Show file tree
Hide file tree
Showing 18 changed files with 772 additions and 560 deletions.
2 changes: 1 addition & 1 deletion .env.development
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FLASK_APP=app.py
FLASK_APP=app:application
FLASK_ENV=development
FLASK_RUN_PORT=5000
FLASK_RUN_HOST=localhost
Expand Down
2 changes: 1 addition & 1 deletion .flaskenv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FLASK_APP=app.py
FLASK_APP=app:application
FLASK_ENV=development
FLASK_RUN_PORT=5000
FLASK_RUN_HOST=localhost
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ COPY . .
EXPOSE 8080
ENV FLASK_ENV=development

CMD ["flask", "run", "--host", "0.0.0.0", "--port", "8080"]
CMD ["gunicorn", "--worker-class", "uvicorn.workers.UvicornWorker", "wsgi:app", "-b", "0.0.0.0:8080"]
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
web: flask run --host 0.0.0.0 --port 8080
web: gunicorn --worker-class uvicorn.workers.UvicornWorker -c run/gunicorn/devtest.py wsgi:app
5 changes: 4 additions & 1 deletion api/routes/application/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from external_services.exceptions import SubmitError
from external_services.models.notification import Notification
from flask import current_app
from flask import jsonify
from flask import request
from flask import send_file
from flask.views import MethodView
Expand Down Expand Up @@ -116,7 +117,9 @@ def get_applications_statuses_report(
return {"code": 404, "message": str(e)}, 404

if format.lower() == "json":
return {"metrics": report_data}
response = jsonify({"metrics": report_data})
response.headers["Content-Type"] = "application/json"
return response
else:
return send_file(
export_application_statuses_to_csv(report_data),
Expand Down
31 changes: 22 additions & 9 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from os import getenv

import connexion
from api.routes.application.routes import ApplicationsView # noqa
from config import Config
from connexion.resolver import MethodViewResolver
from flask import Flask
from connexion import FlaskApp
from connexion.resolver import MethodResolver
from db.exceptions.application import ApplicationError
from flask import jsonify
from fsd_utils import init_sentry
from fsd_utils.healthchecks.checkers import DbChecker
from fsd_utils.healthchecks.checkers import FlaskRunningChecker
Expand All @@ -13,19 +16,21 @@
from openapi.utils import get_bundled_specs


def create_app() -> Flask:
def create_app() -> FlaskApp:
init_sentry()

connexion_options = {
"swagger_url": "/",
}
connexion_app = connexion.FlaskApp(__name__, specification_dir="openapi/", options=connexion_options)
connexion_app = connexion.App(
__name__,
)

connexion_app.add_api(
get_bundled_specs("/openapi/api.yml"),
validate_responses=True,
resolver=MethodViewResolver("api"),
resolver_error=501,
resolver=MethodResolver("api"),
)

# Configure Flask App
flask_app = connexion_app.app
flask_app.config.from_object("config.Config")

Expand All @@ -42,11 +47,18 @@ def create_app() -> Flask:
# Bind Flask-Migrate db utilities to Flask app
migrate.init_app(flask_app, db, directory="db/migrations", render_as_batch=True)

# Add healthchecks to flask_app
health = Healthcheck(flask_app)
health.add_check(FlaskRunningChecker())
health.add_check(DbChecker(db))

return flask_app
@flask_app.errorhandler(ApplicationError)
def handle_application_error(error):
response = jsonify({"detail": str(error)})
response.status_code = 500
return response

return connexion_app


def create_sqs_extended_client(flask_app):
Expand Down Expand Up @@ -76,3 +88,4 @@ def create_sqs_extended_client(flask_app):


app = create_app()
application = app.app
Loading

0 comments on commit 4dd4907

Please sign in to comment.