Fix empty reply: remove gunicorn preload, isolate DB init from workers
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+1
-1
@@ -28,4 +28,4 @@ ENV GIT_CONFIG_VALUE_0=/repo
|
|||||||
EXPOSE 8000
|
EXPOSE 8000
|
||||||
|
|
||||||
ENTRYPOINT ["/app/entrypoint.sh"]
|
ENTRYPOINT ["/app/entrypoint.sh"]
|
||||||
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--workers", "2", "--timeout", "120", "--preload", "wsgi:app"]
|
CMD ["gunicorn", "-c", "gunicorn.conf.py", "wsgi:app"]
|
||||||
|
|||||||
+3
-1
@@ -30,6 +30,7 @@ def create_app(setup_database=True):
|
|||||||
"postgresql://photohost:photohost_secret@localhost:5432/photohost",
|
"postgresql://photohost:photohost_secret@localhost:5432/photohost",
|
||||||
)
|
)
|
||||||
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
|
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
|
||||||
|
app.config["SQLALCHEMY_ENGINE_OPTIONS"] = {"pool_pre_ping": True}
|
||||||
app.config["UPLOAD_FOLDER"] = os.getenv("UPLOAD_FOLDER", "uploads")
|
app.config["UPLOAD_FOLDER"] = os.getenv("UPLOAD_FOLDER", "uploads")
|
||||||
app.config["MAX_CONTENT_LENGTH"] = int(os.getenv("MAX_UPLOAD_MB", "10")) * 1024 * 1024
|
app.config["MAX_CONTENT_LENGTH"] = int(os.getenv("MAX_UPLOAD_MB", "10")) * 1024 * 1024
|
||||||
app.config["ALLOWED_EXTENSIONS"] = {"png", "jpg", "jpeg", "gif", "webp", "bmp"}
|
app.config["ALLOWED_EXTENSIONS"] = {"png", "jpg", "jpeg", "gif", "webp", "bmp"}
|
||||||
@@ -68,6 +69,7 @@ def create_app(setup_database=True):
|
|||||||
except Exception:
|
except Exception:
|
||||||
return {"site_banners": {}}
|
return {"site_banners": {}}
|
||||||
|
|
||||||
|
if setup_database:
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
from app.models import ( # noqa: F401
|
from app.models import ( # noqa: F401
|
||||||
AdBanner,
|
AdBanner,
|
||||||
@@ -83,7 +85,7 @@ def create_app(setup_database=True):
|
|||||||
|
|
||||||
db.create_all()
|
db.create_all()
|
||||||
|
|
||||||
if setup_database and os.getenv("SKIP_DB_INIT") != "1":
|
if os.getenv("SKIP_DB_INIT") != "1":
|
||||||
from app.bootstrap import run_database_setup
|
from app.bootstrap import run_database_setup
|
||||||
|
|
||||||
run_database_setup(app)
|
run_database_setup(app)
|
||||||
|
|||||||
+1
-1
@@ -12,7 +12,7 @@ if [ "$ALLOW_GIT_DEPLOY" = "true" ] || [ "$ALLOW_GIT_DEPLOY" = "1" ] || [ "$ALLO
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Run DB migrations once before gunicorn workers start.
|
# Run DB migrations once before gunicorn workers start.
|
||||||
gosu appuser python /app/init_db.py
|
gosu appuser python /app/init_db.py || exit 1
|
||||||
|
|
||||||
export SKIP_DB_INIT=1
|
export SKIP_DB_INIT=1
|
||||||
exec gosu appuser "$@"
|
exec gosu appuser "$@"
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
bind = "0.0.0.0:8000"
|
||||||
|
workers = 2
|
||||||
|
timeout = 120
|
||||||
|
accesslog = "-"
|
||||||
|
errorlog = "-"
|
||||||
|
capture_output = True
|
||||||
|
|
||||||
|
|
||||||
|
def post_fork(server, worker):
|
||||||
|
from app import db
|
||||||
|
|
||||||
|
db.engine.dispose()
|
||||||
Reference in New Issue
Block a user