From 4ccfa6e42ce39389cdff5528b9212f747899b710 Mon Sep 17 00:00:00 2001 From: ClumsyAdmin <59402569+ClumsyAdmin@users.noreply.github.com> Date: Fri, 21 Mar 2025 12:02:23 -0400 Subject: [PATCH] refactor docker startup to use supervisord --- backend/Dockerfile | 9 ++++++--- backend/entrypoint.sh | 7 +++++-- backend/supervisord.conf | 10 ++++++++++ frontend/startup.sh | 2 +- 4 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 backend/supervisord.conf diff --git a/backend/Dockerfile b/backend/Dockerfile index aa0f9f4..fae48fb 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -12,7 +12,7 @@ WORKDIR /code # Install system dependencies (Nginx included) RUN apt-get update \ - && apt-get install -y git postgresql-client gdal-bin libgdal-dev nginx \ + && apt-get install -y git postgresql-client gdal-bin libgdal-dev nginx supervisor \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* @@ -31,6 +31,9 @@ COPY ./server /code/ # Copy Nginx configuration COPY ./nginx.conf /etc/nginx/nginx.conf +# Copy Supervisor configuration +COPY ./supervisord.conf /etc/supervisor/conf.d/supervisord.conf + # Collect static files RUN python3 manage.py collectstatic --noinput --verbosity 2 @@ -41,5 +44,5 @@ RUN chmod +x /code/entrypoint.sh # Expose ports for NGINX and Gunicorn EXPOSE 80 8000 -# Command to start Nginx and Gunicorn -CMD ["bash", "-c", "service nginx start && /code/entrypoint.sh"] \ No newline at end of file +# Command to start Supervisor (which starts Nginx and Gunicorn) +CMD ["supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"] diff --git a/backend/entrypoint.sh b/backend/entrypoint.sh index 9ca926c..780a182 100644 --- a/backend/entrypoint.sh +++ b/backend/entrypoint.sh @@ -62,5 +62,8 @@ fi cat /code/adventurelog.txt -# Start gunicorn -gunicorn main.wsgi:application --bind [::]:8000 --timeout 120 --workers 2 \ No newline at end of file +# Start Gunicorn in foreground +exec gunicorn main.wsgi:application \ + --bind 0.0.0.0:8000 \ + --workers 4 \ + --timeout 120 diff --git a/backend/supervisord.conf b/backend/supervisord.conf new file mode 100644 index 0000000..7657f7f --- /dev/null +++ b/backend/supervisord.conf @@ -0,0 +1,10 @@ +[supervisord] +nodaemon=true + +[program:nginx] +command=/usr/sbin/nginx -g "daemon off;" +autorestart=true + +[program:gunicorn] +command=/code/entrypoint.sh +autorestart=true diff --git a/frontend/startup.sh b/frontend/startup.sh index 1b611e3..67dbb1e 100644 --- a/frontend/startup.sh +++ b/frontend/startup.sh @@ -2,4 +2,4 @@ echo "The origin to be set is: $ORIGIN" # Start the application -ORIGIN=$ORIGIN node build \ No newline at end of file +ORIGIN=$ORIGIN exec node build