la-chariotte/Makefile
PierreDubrulle 2f9ea5683f docs
2024-01-23 12:10:26 +01:00

85 lines
No EOL
2.6 KiB
Makefile

SHELL := /bin/bash
ENV_FILE := .env
# PYTHON
VENV_NAME := .venv
PYTHON := $(VENV_NAME)/bin/python
PIP := $(VENV_NAME)/bin/pip
REQUIREMENTS := requirements-dev.txt
# Docker
DOCKER_COMPOSE := docker-compose
DOCKER_COMPOSE_FILE := docker-compose.yml
DOCKER_DIRECTORY := dev_env
POSTGRES_CONTAINER := postgres_chariotte
MAX_TRIES := 10
.PHONY: python venv_python install_python clean_python db_start db_stop front_install help
.DEFAULT_GOAL := help
help:
@echo "Available targets:"
@echo " python : Create and activate a Python virtual environment. Install dependencies."
@echo " install_python: Install Python dependencies from requirements file."
@echo " clean_python : Remove the Python virtual environment."
@echo " db_start : Start Docker containers and run database migrations."
@echo " db_stop : Stop Docker containers and remove volumes."
@echo " front_install : Install front-end dependencies using Yarn or NPM."
@echo " run_server : Run the Django development server."
@echo " help : Display this help message."
python: venv_python install_python
venv_python:
python3 -m venv $(VENV_NAME)
@echo "Activating virtual environment with 'source $(VENV_NAME)/bin/activate'. Run 'deactivate' to exit."
install_python: venv_python
@$(VENV_NAME)/bin/pip install --upgrade pip
@$(VENV_NAME)/bin/pip install -r $(REQUIREMENTS)
clean_python:
rm -rf $(VENV_NAME)
db_start:
@if [ ! -x $$(command -v $(DOCKER_COMPOSE)) ]; then \
echo "Docker Compose not installed. Please install Docker Compose."; \
exit 1; \
fi
@$(DOCKER_COMPOSE) -f $(DOCKER_DIRECTORY)/$(DOCKER_COMPOSE_FILE) --env-file ${ENV_FILE} up -d
@for ((tries=0; tries<$(MAX_TRIES); tries++)); do \
if docker inspect --format '{{json .State.Health.Status }}' $(POSTGRES_CONTAINER) | grep -q 'healthy'; then \
break; \
fi; \
echo "Waiting for the container to be healthy..."; \
sleep 1; \
done; \
if [ $$tries -ge $(MAX_TRIES) ]; then \
echo "Timed out waiting for the container to be healthy."; \
exit 1; \
fi
@echo "Running migrations..."
@$(PYTHON) manage.py migrate
db_stop:
@$(DOCKER_COMPOSE) -f $(DOCKER_DIRECTORY)/$(DOCKER_COMPOSE_FILE) down -v
front_install:
@if command -v yarn > /dev/null; then \
echo "Installing dependencies with Yarn ..."; \
yarn install; \
elif command -v npm > /dev/null; then \
echo "Installing dependencies with NPM ..."; \
npm install; \
else \
echo "Neither Yarn nor NPM found. Please install one of them."; \
exit 1; \
fi
run_server:
@$(PYTHON) manage.py runserver
superuser:
@$(PYTHON) manage.py createsuperuser