From 17bfae0b442aedcbf87a389c288ee809a7b22915 Mon Sep 17 00:00:00 2001 From: Areeb Ahmed Date: Sat, 16 Nov 2024 00:54:40 +0530 Subject: [PATCH] Update Heroku deployment for Celery and Redis integration --- Procfile | 2 + app.json | 74 +++++++++++++++++++----------- docs/local-setup/configuration.rst | 42 +++++++++++++++++ 3 files changed, 91 insertions(+), 27 deletions(-) diff --git a/Procfile b/Procfile index 6b2fde1d76..6b94ccc4e2 100644 --- a/Procfile +++ b/Procfile @@ -1,2 +1,4 @@ web: gunicorn config.wsgi:application release: python manage.py collectstatic --noinput && python manage.py migrate +worker: celery -A config.celery_app worker --loglevel=info +beat: celery -A config.celery_app beat --loglevel=info diff --git a/app.json b/app.json index 5ddac1159f..5adcf417fd 100644 --- a/app.json +++ b/app.json @@ -1,27 +1,47 @@ - { - "environments": { - "test": { - "scripts": { - "test": "python manage.py test" - }, - "buildpacks": [{ - "url": "https://github.com/cyberdelia/heroku-geo-buildpack.git" - }, - { - "url": "heroku/python" - } - ], - "env": { - "DJANGO_SETTINGS_MODULE": { - "value": "config.settings.test" - }, - "LD_LIBRARY_PATH": { - "value": "/app/lib" - }, - "BUILD_WITH_GEO_LIBRARIES": { - "value": "1" - } - } - } - } - } +{ + "environments": { + "test": { + "scripts": { + "test": "python manage.py test" + }, + "buildpacks": [ + { + "url": "https://github.com/cyberdelia/heroku-geo-buildpack.git" + }, + { + "url": "heroku/python" + } + ], + "env": { + "DJANGO_SETTINGS_MODULE": { + "value": "config.settings.test" + }, + "LD_LIBRARY_PATH": { + "value": "/app/lib" + }, + "BUILD_WITH_GEO_LIBRARIES": { + "value": "1" + } + } + }, + "production": { + "scripts": { + "postdeploy": "python manage.py migrate && python manage.py load_redis_index" + }, + "env": { + "DJANGO_SETTINGS_MODULE": { + "value": "config.settings.production" + }, + "DATABASE_URL": { + "value": "${DATABASE_URL}" + }, + "REDIS_URL": { + "value": "${REDIS_URL}" + }, + "CELERY_BROKER_URL": { + "value": "${CELERY_BROKER_URL}" + } + } + } + } +} diff --git a/docs/local-setup/configuration.rst b/docs/local-setup/configuration.rst index c6143b4b42..36a1185833 100644 --- a/docs/local-setup/configuration.rst +++ b/docs/local-setup/configuration.rst @@ -207,3 +207,45 @@ If you get an :code:`ImproperlyConfigured` error regarding the Spatialite librar :: $ sudo apt install libsqlite3-mod-spatialite + +Heroku Deployment +================= + +To deploy the backend along with Celery on Heroku, follow these steps: + +1. Ensure you have the Heroku CLI installed and are logged in. + +2. Create a new Heroku app: + + .. code-block:: bash + + heroku create your-app-name + +3. Add the necessary add-ons for PostgreSQL and Redis: + + .. code-block:: bash + + heroku addons:create heroku-postgresql:hobby-dev + heroku addons:create heroku-redis:hobby-dev + +4. Set the environment variables: + + .. code-block:: bash + + heroku config:set DJANGO_SETTINGS_MODULE=config.settings.production + heroku config:set DATABASE_URL=your-database-url + heroku config:set REDIS_URL=your-redis-url + heroku config:set CELERY_BROKER_URL=your-redis-url + +5. Deploy the app: + + .. code-block:: bash + + git push heroku main + +6. Run the migrations and load the Redis index: + + .. code-block:: bash + + heroku run python manage.py migrate + heroku run python manage.py load_redis_index