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
|
||||
|
||||
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"]
|
||||
|
||||
+18
-16
@@ -30,6 +30,7 @@ def create_app(setup_database=True):
|
||||
"postgresql://photohost:photohost_secret@localhost:5432/photohost",
|
||||
)
|
||||
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["MAX_CONTENT_LENGTH"] = int(os.getenv("MAX_UPLOAD_MB", "10")) * 1024 * 1024
|
||||
app.config["ALLOWED_EXTENSIONS"] = {"png", "jpg", "jpeg", "gif", "webp", "bmp"}
|
||||
@@ -68,25 +69,26 @@ def create_app(setup_database=True):
|
||||
except Exception:
|
||||
return {"site_banners": {}}
|
||||
|
||||
with app.app_context():
|
||||
from app.models import ( # noqa: F401
|
||||
AdBanner,
|
||||
Folder,
|
||||
FolderInvite,
|
||||
FolderMember,
|
||||
PasswordResetToken,
|
||||
Photo,
|
||||
SiteSettings,
|
||||
User,
|
||||
UserGroup,
|
||||
)
|
||||
if setup_database:
|
||||
with app.app_context():
|
||||
from app.models import ( # noqa: F401
|
||||
AdBanner,
|
||||
Folder,
|
||||
FolderInvite,
|
||||
FolderMember,
|
||||
PasswordResetToken,
|
||||
Photo,
|
||||
SiteSettings,
|
||||
User,
|
||||
UserGroup,
|
||||
)
|
||||
|
||||
db.create_all()
|
||||
db.create_all()
|
||||
|
||||
if setup_database and os.getenv("SKIP_DB_INIT") != "1":
|
||||
from app.bootstrap import run_database_setup
|
||||
if os.getenv("SKIP_DB_INIT") != "1":
|
||||
from app.bootstrap import run_database_setup
|
||||
|
||||
run_database_setup(app)
|
||||
run_database_setup(app)
|
||||
|
||||
return app
|
||||
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ if [ "$ALLOW_GIT_DEPLOY" = "true" ] || [ "$ALLOW_GIT_DEPLOY" = "1" ] || [ "$ALLO
|
||||
fi
|
||||
|
||||
# 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
|
||||
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