Skip to content

Commit 59c7877

Browse files
committed
fix docker
1 parent d5f618c commit 59c7877

File tree

3 files changed

+69
-3
lines changed

3 files changed

+69
-3
lines changed

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ EXPOSE 5005
2020

2121
ENV FLASK_APP=server.py
2222

23+
WORKDIR /app
24+
2325
# Define the command to run when the container starts
2426
# CMD ["flask", "run", "--host=0.0.0.0", "--port=5001"]
2527
# gunicorn is a production ready web server for flask, with ability to handle multiple requests
26-
CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:5001", "app:server"]
28+
CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:5001", "server:app"]

app/requirements.txt

-30 Bytes
Binary file not shown.

app/server.py

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,79 @@
11
from flask import Flask, request, jsonify
22
import os
33
# Import your script
4-
from .langchain_orcid2 import run as run_langchain
5-
from .auth import validate_api_key
4+
from langchain_orcid2 import run as run_langchain
5+
from auth import validate_api_key
6+
import logging
7+
import json
8+
from logging.config import dictConfig
69

710
# Read environment variables
811
cr_mailto = os.getenv('CR_MAILTO')
912
pyalex_email = os.getenv('PYALEX_EMAIL')
1013

14+
# Configure logging
15+
class JsonFormatter(logging.Formatter):
16+
def format(self, record):
17+
log_record = {
18+
'level': record.levelname,
19+
'time': self.formatTime(record, self.datefmt),
20+
'message': record.getMessage(),
21+
'name': record.name,
22+
'pathname': record.pathname,
23+
'lineno': record.lineno,
24+
}
25+
if record.exc_info:
26+
log_record['exc_info'] = self.formatException(record.exc_info)
27+
return json.dumps(log_record)
28+
29+
dictConfig({
30+
'version': 1,
31+
'formatters': {
32+
'json': {
33+
'()': JsonFormatter,
34+
}
35+
},
36+
'handlers': {
37+
'stdout': {
38+
'class': 'logging.StreamHandler',
39+
'formatter': 'json',
40+
'stream': 'ext://sys.stdout',
41+
}
42+
},
43+
'root': {
44+
'level': 'INFO',
45+
'handlers': ['stdout']
46+
}
47+
})
48+
1149
app = Flask(__name__)
1250

51+
# @app.before_request
52+
# def log_request_info():
53+
# app.logger.info('Request received', extra={
54+
# 'method': request.method,
55+
# 'url': request.url,
56+
# 'headers': dict(request.headers),
57+
# 'body': request.get_data(as_text=True)
58+
# })
59+
60+
@app.before_request
61+
def log_request_info():
62+
try:
63+
body = request.get_data(as_text=True)
64+
if len(body) > 1000: # Limit body size for logging
65+
body = body[:1000] + '... [truncated]'
66+
67+
app.logger.info('Request received', extra={
68+
'method': request.method,
69+
'url': request.url,
70+
'headers': dict(request.headers),
71+
'body': body
72+
})
73+
except Exception as e:
74+
app.logger.error('Error logging request info', exc_info=e)
75+
76+
1377
@app.route('/invoke-script', methods=['POST'])
1478
@validate_api_key
1579

0 commit comments

Comments
 (0)