From 00bf0ac45fab3b05f458ef4f23980039b40a27ae Mon Sep 17 00:00:00 2001 From: SureshPradhana Date: Tue, 23 Jul 2024 09:02:28 +0530 Subject: [PATCH 1/3] makefile for local setup --- makefile | 75 +++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 63 insertions(+), 12 deletions(-) diff --git a/makefile b/makefile index f881c608..0e6a474b 100644 --- a/makefile +++ b/makefile @@ -1,17 +1,68 @@ -migrations: - python3 backend/manage.py makemigrations +# Backend commands +VENV := backend/venv +PYTHON := $(VENV)/bin/python +PIP := $(VENV)/bin/pip -migrate: - python3 backend/manage.py migrate +# Load environment variables from .env file +ifneq (,$(wildcard ./.env)) + include .env + export +endif -runserver: - python3 backend/manage.py runserver +create-venv: + python3 -m venv $(VENV) -install-backend: - pip3 install -r backend/requirements/local.txt +install-backend: create-venv + $(PIP) install -r backend/requirements/local.txt -superuser: - python3 backend/manage.py createsuperuser +migrations: install-backend + $(PYTHON) backend/manage.py makemigrations -collectstatic: - python backend/manage.py collectstatic --no-input +migrate: install-backend + $(PYTHON) backend/manage.py migrate + +runserver: install-backend + $(PYTHON) backend/manage.py runserver + +superuser: install-backend + $(PYTHON) backend/manage.py createsuperuser + +collectstatic: install-backend + $(PYTHON) backend/manage.py collectstatic --no-input + +# PostgreSQL and RabbitMQ commands +start-postgres: + docker run --name postgres -e POSTGRES_DB=$(POSTGRES_DB) -e POSTGRES_USER=$(POSTGRES_USER) -e POSTGRES_PASSWORD=$(POSTGRES_PASSWORD) -p $(POSTGRES_PORT):5432 -v postgres_data:/var/lib/postgresql/data -d postgres + +stop-postgres: + docker stop postgres || true + docker rm postgres || true + +start-rabbitmq: + docker run --name rabbitmq -d -p 5672:5672 -p 15672:15672 rabbitmq:3-management + +stop-rabbitmq: + docker stop rabbitmq || true + docker rm rabbitmq || true + + +# Frontend commands +install-frontend: + cd frontend && npm install + +build-frontend: + cd frontend && npm run build + +run-frontend: + cd frontend && npm run dev + +# Combined commands +start-services: stop-postgres stop-rabbitmq start-postgres start-rabbitmq + +stop-services: stop-postgres stop-rabbitmq + +backend: install-backend migrations migrate runserver + +frontend: install-frontend builamid-frontend run-frontend + +.PHONY: create-venv install-backend migrations migrate runserver superuser collectstatic install-frontend build-frontend run-frontend backend frontend start-services stop-services \ No newline at end of file From e145ac6c2ef085cf0beff708de00fe24881a4c56 Mon Sep 17 00:00:00 2001 From: SureshPradhana Date: Sun, 28 Jul 2024 22:07:10 +0530 Subject: [PATCH 2/3] remove start-serivces --- makefile | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/makefile b/makefile index 0e6a474b..f1abf24e 100644 --- a/makefile +++ b/makefile @@ -30,39 +30,15 @@ superuser: install-backend collectstatic: install-backend $(PYTHON) backend/manage.py collectstatic --no-input -# PostgreSQL and RabbitMQ commands -start-postgres: - docker run --name postgres -e POSTGRES_DB=$(POSTGRES_DB) -e POSTGRES_USER=$(POSTGRES_USER) -e POSTGRES_PASSWORD=$(POSTGRES_PASSWORD) -p $(POSTGRES_PORT):5432 -v postgres_data:/var/lib/postgresql/data -d postgres - -stop-postgres: - docker stop postgres || true - docker rm postgres || true - -start-rabbitmq: - docker run --name rabbitmq -d -p 5672:5672 -p 15672:15672 rabbitmq:3-management - -stop-rabbitmq: - docker stop rabbitmq || true - docker rm rabbitmq || true - - # Frontend commands install-frontend: cd frontend && npm install -build-frontend: - cd frontend && npm run build - run-frontend: cd frontend && npm run dev -# Combined commands -start-services: stop-postgres stop-rabbitmq start-postgres start-rabbitmq - -stop-services: stop-postgres stop-rabbitmq - backend: install-backend migrations migrate runserver -frontend: install-frontend builamid-frontend run-frontend +frontend: install-frontend run-frontend -.PHONY: create-venv install-backend migrations migrate runserver superuser collectstatic install-frontend build-frontend run-frontend backend frontend start-services stop-services \ No newline at end of file +.PHONY: create-venv install-backend migrations migrate runserver superuser collectstatic install-frontend run-frontend backend frontend \ No newline at end of file From 9c7df800399e9f1f7b842c57e5733a52fc520182 Mon Sep 17 00:00:00 2001 From: SureshPradhana Date: Sun, 28 Jul 2024 22:07:29 +0530 Subject: [PATCH 3/3] update docs --- contributing.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/contributing.md b/contributing.md index cd2f8662..6fd3e191 100644 --- a/contributing.md +++ b/contributing.md @@ -57,6 +57,42 @@ We will then take care of the issue as soon as possible. git clone https://github.com//djangoindia.org ``` +### Configuring Environment Variables + + Create a .env file in the project root with necessary environment variables. Refer to .env.example for the latest variables. + +### Running with Makefile + + 1. Backend(Django) + + ```sh + make backend + ``` + 2. Frontend(Next.js) + + ```sh + make frontend + ``` + +### Working with RabbitMQ +Install and start RabbitMQ: + +- Ubuntu: + ```sh + sudo apt-get update + sudo apt-get install rabbitmq-server + sudo systemctl enable rabbitmq-server + sudo systemctl start rabbitmq-server + ``` +- macOS: + ```sh + brew install rabbitmq + brew services start rabbitmq + ``` +- Windows: + + Follow the [official installation guide](https://www.rabbitmq.com/docs/install-windows) to install RabbitMQ and then start the service using the RabbitMQ Service Manager. + ### Without Docker #### Backend (Django) We are in root directory right now.