From 210ec4adff412ceb96f97c876eeb4644688113da Mon Sep 17 00:00:00 2001 From: dmunoz Date: Mon, 8 Jul 2024 12:53:01 +0200 Subject: [PATCH] add gunicorn-aio mode, powered by whitenoise --- docker-platform/Dockerfile | 2 +- docker-platform/docker-entrypoint.sh | 14 +++++++++++--- .../platform_project_template/project_name/wsgi.py | 9 +++++++++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/docker-platform/Dockerfile b/docker-platform/Dockerfile index a768bb4b42..74ef8efe9c 100644 --- a/docker-platform/Dockerfile +++ b/docker-platform/Dockerfile @@ -45,7 +45,7 @@ RUN --mount=type=bind,from=builder,source=/wirecloud/src/dist/,target=/dist/ \ --mount=type=cache,target=/root/.cache/pip,sharing=locked \ pip install /dist/*.whl \ social-auth-app-django "gunicorn==21.2" "psycopg2==2.8.6" pylibmc pysolr "elasticsearch==2.4.1" \ - "regex==2019.02.18" "channels<2.3" "channels-redis" "wirecloud-keycloak>=0.3.0" && \ + "regex==2019.02.18" "channels<2.3" "channels-redis" "wirecloud-keycloak>=0.3.0" "whitenoise" && \ pip uninstall selenium -y RUN adduser --system --group --shell /bin/bash wirecloud && \ diff --git a/docker-platform/docker-entrypoint.sh b/docker-platform/docker-entrypoint.sh index cffc6937b1..dc3647e9d4 100755 --- a/docker-platform/docker-entrypoint.sh +++ b/docker-platform/docker-entrypoint.sh @@ -20,14 +20,22 @@ case "$1" in createsuperuser) manage.py createsuperuser ;; - gunicorn) + gunicorn|gunicorn-aio) + manage.py collectstatic --noinput manage.py migrate --fake-initial manage.py populate + # select wirecloud_instance.wsgi:application or wirecloud_instance.wsgi:allInOneApplication depending on the value of $1 + if [ "$1" = 'gunicorn' ]; then + WSGI_APPLICATION='wirecloud_instance.wsgi:application' + else + WSGI_APPLICATION='wirecloud_instance.wsgi:allInOneApplication' + fi + # allow the container to be started with `--user` if [ "$(id -u)" = '0' ]; then - exec gosu wirecloud /usr/local/bin/gunicorn wirecloud_instance.wsgi:application \ + exec gosu wirecloud /usr/local/bin/gunicorn $WSGI_APPLICATION \ --forwarded-allow-ips "${FORWARDED_ALLOW_IPS}" \ --workers ${WORKERS} \ --threads ${THREADS} \ @@ -35,7 +43,7 @@ case "$1" in --log-file - \ --logger-class wirecloud.glogger.GunicornLogger else - exec /usr/local/bin/gunicorn wirecloud_instance.wsgi:application \ + exec /usr/local/bin/gunicorn $WSGI_APPLICATION \ --forwarded-allow-ips "${FORWARDED_ALLOW_IPS}" \ --workers ${WORKERS} \ --threads ${THREADS} \ diff --git a/src/wirecloud/commons/conf/platform_project_template/project_name/wsgi.py b/src/wirecloud/commons/conf/platform_project_template/project_name/wsgi.py index f768265b23..031d7aec37 100644 --- a/src/wirecloud/commons/conf/platform_project_template/project_name/wsgi.py +++ b/src/wirecloud/commons/conf/platform_project_template/project_name/wsgi.py @@ -30,3 +30,12 @@ # Apply WSGI middleware here. # from helloworld.wsgi import HelloWorldApplication # application = HelloWorldApplication(application) + +try: + from whitenoise import WhiteNoise + allInOneApplication = WhiteNoise(application, root = "/var/www/static", prefix="static/", autorefresh=True) +except ImportError: + # Whitenoise is not installed + # Only error if wgsi attempts to access allInOneApplication + def allInOneApplication(environ, start_response): + raise Exception("Whitenoise is not installed, wirecloud cannot run in allInOne mode") \ No newline at end of file