You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Always place app files under /app dir inside container.
A file /app/version.json should be generated within the CI workflow and baked into the built image:
{
"source" : "https://github.com/hotosm/fmtm",
"version": "release tag or string for humans. can be blank for non-release",
"commit" : "<git hash>",
"build" : "uri to CI build job"
}
Respond to /__version__ with the contents of /app/version.json.
Respond to /__heartbeat__ with a HTTP 200 or 5xx on error. This should check backing services like a database for connectivity and may respond with the status of backing services and application components as a JSON payload.
Respond to /__lbheartbeat__ with an HTTP 200. This is for load balancer checks and should not check backing services.
Always log to terminal (STDOUT), never to a file.
Backend serves its own static, frontend serves it's own static. I.e. do not rely on public/static directory of frontend from backend.
Describe alternatives you've considered
I don't know any other good specs for this.
The text was updated successfully, but these errors were encountered:
frompathlibimportPathfromfastapiimportDependsfromfastapi.responsesimportJSONResponse, Responsefromloguruimportloggeraslogfromsqlalchemyimporttextfromsqlalchemy.ormimportSessionfromapp.__version__import__version__fromapp.db.databaseimportget_dbfromapp.models.enumsimportHTTPStatus@api.get("/__version__")asyncdefdeployment_details():
"""Mozilla Dockerflow Spec: source, version, commit, and link to CI build."""details= {}
version_path=Path("/opt/version.json")
ifversion_path.exists():
withopen(version_path, "r") asversion_file:
details=json.load(version_file)
commit=details.get("commit", "commit key was not found in file!")
build=details.get("build", "build key was not found in file!")
returnJSONResponse(status_code=HTTPStatus.OK, content={
"source" : "https://github.com/hotosm/fmtm",
"version": __version__,
"commit" : commitor"/app/version.json not found",
"build" : buildor"/app/version.json not found"
})
@api.get("/__heartbeat__")asyncdefheartbeat_plus_db(db: Session=Depends(get_db)):
"""Heartbeat that checks that API and DB are both up and running."""try:
db.execute(text("SELECT 1"))
returnResponse(status_code=HTTPStatus.OK)
exceptExceptionase:
log.warning(e)
log.warning("Server failed __heartbeat__ database connection check")
returnJSONResponse(
status_code=HTTPStatus.INTERNAL_SERVER_ERROR, content={"error": str(e)}
)
@api.get("/__lbheartbeat__")asyncdefsimple_heartbeat():
"""Simple ping/pong API response."""returnResponse(status_code=HTTPStatus.OK)
Is your feature request related to a problem? Please describe.
Describe the solution you'd like
/app
dir inside container./app/version.json
should be generated within the CI workflow and baked into the built image:/__version__
with the contents of /app/version.json./__heartbeat__
with a HTTP 200 or 5xx on error. This should check backing services like a database for connectivity and may respond with the status of backing services and application components as a JSON payload./__lbheartbeat__
with an HTTP 200. This is for load balancer checks and should not check backing services.Describe alternatives you've considered
I don't know any other good specs for this.
The text was updated successfully, but these errors were encountered: