-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
94 lines (74 loc) · 2.61 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# Variables
VENV = venv
PYTHON = $(VENV)/bin/python
PIP = $(VENV)/bin/pip
# Used by `image`, `push` & `deploy` targets, override as required
IMAGE_REG ?= localhost:5000
IMAGE_REPO ?= bloggersunity-web
IMAGE_TAG ?= latest
# Project directory
PROJECT_DIR = BloggersUnity
APP_DIR = Tech
# Help message
help:
@echo "Makefile for Django project"
@echo "Available commands:"
@echo " make venv - Create a virtual environment"
@echo " make install - Install dependencies"
@echo " make run - Run the Django development server"
@echo " make migrate - Apply database migrations"
@echo " make makemigrations - Create new database migrations"
@echo " make test - Run tests"
@echo " make image - Build container image from Dockerfile"
@echo " make push - Push container image to registry "
@echo " make lint - Run linters (flake8)"
@echo " make format - Format code using black"
@echo " make clean - Clean up Project"
@echo " make compose:build - Build the Docker images using Docker Compose"
@echo " make compose:up - Run the container using Docker Compose"
@echo " make compose:down - Stop the container using Docker Compose"
# Create virtual environment
venv:
python3 -m venv $(VENV)
# Install dependencies
install: venv
$(PIP) install -r requirements.txt
# Run linters
lint: venv
$(VENV)/bin/flake8 $(PROJECT_DIR)
# Format code
format: venv
$(VENV)/bin/black $(PROJECT_DIR) $(APP_DIR)
# Create new database migrations
makemigrations: venv
$(PYTHON) manage.py makemigrations
# Apply database migrations
migrate: venv
$(PYTHON) manage.py migrate
# Run tests
test: venv
$(PYTHON) manage.py test
# Run the Django development server
run: venv
$(PYTHON) manage.py runserver
image: ## 🔨 Build container image from Dockerfile
docker build . --file docker/Dockerfile \
--tag $(IMAGE_REG)/$(IMAGE_REPO):$(IMAGE_TAG)
push: ## 📤 Push container image to registry
docker push $(IMAGE_REG)/$(IMAGE_REPO):$(IMAGE_TAG)
# Build the Docker images using Docker Compose
compose:build:
docker compose -f docker/docker-compose.yaml build
# Run the container using Docker Compose
compose:up:
docker compose -f docker/docker-compose.yaml up -d
# Stop the container using Docker Compose
compose:down:
docker compose -f docker/docker-compose.yaml down
# Clean the project
clean:
-find . -name "*.pyc" -exec rm -f {} +
-find . -name "*.pyo" -exec rm -f {} +
-find . -name "__pycache__" -exec rm -rf {} + || true
@if [ -d "$(VENV)" ]; then rm -rf $(VENV); fi
.PHONY: help venv install run migrate makemigrations test clean compose:build compose:up compose:down