Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions document-service/doc-api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ USER web
FROM development_build AS production_build
COPY --chown=web:web . /code

RUN chmod +x /code/update_db.sh

# ENV PYTHONPATH=/opt/app-root/src

# CMD gunicorn --bind 0.0.0.0:${PORT} --config /code/gunicorn_config.py wsgi:app
Expand Down
23 changes: 14 additions & 9 deletions document-service/doc-api/src/doc_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ def create_app(service_environment=APP_RUNNING_ENVIRONMENT, **kwargs):

db.init_app(app)
Migrate(app, db)
if app.config.get("DEPLOYMENT_ENV", "") == "testing": # CI only run upgrade for unit testing.

deployment_env = app.config.get("DEPLOYMENT_ENV", "")

if deployment_env == "testing": # CI only run upgrade for unit testing.
logger.info("Running migration upgrade.")
with app.app_context():
upgrade(directory="migrations", revision="head", sql=False, tag=None)
Expand All @@ -54,14 +57,16 @@ def create_app(service_environment=APP_RUNNING_ENVIRONMENT, **kwargs):
logger.info("Finished migration upgrade.")
else:
logger.info("Logging, migrate set up.")
auth_service.init_app(app)
storage_service.init_app(app)
meta_endpoint.init_app(app)
ops_endpoint.init_app(app)
v1_endpoint.init_app(app)
queue_service.init_app(app)

setup_jwt_manager(app, jwt)

# Skip service initialization for migration jobs
if deployment_env != "migration":
auth_service.init_app(app)
storage_service.init_app(app)
meta_endpoint.init_app(app)
ops_endpoint.init_app(app)
v1_endpoint.init_app(app)
queue_service.init_app(app)
setup_jwt_manager(app, jwt)

with app.app_context():
if app.config.get("CLOUDSQL_INSTANCE_CONNECTION_NAME"): # pragma: no cover
Expand Down
2 changes: 2 additions & 0 deletions document-service/doc-api/update_db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ COMMAND=${1:-upgrade}
REVISION=${2:-}
echo starting $COMMAND $REVISION
export DEPLOYMENT_ENV=migration
cd /code
export PYTHONPATH="$(pwd)/src:$PYTHONPATH"
export FLASK_APP=wsgi:app
flask db $COMMAND $REVISION
echo 'upgrade completed'
Loading