-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
124 lines (102 loc) · 3.51 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
SRCS_PATH = ./srcs/
CLI_PATH = cli/cli.py
COMPOSE_FILE = docker-compose.yml
CLI = $(addprefix $(SRCS_PATH), $(CLI_PATH))
include .env
export
all:
@echo "Launching ft_transcendence ..."
@docker compose -f $(COMPOSE_FILE) up --build
up:
@echo "Start service of ft_transcendence in the foreground ..."
@docker compose -f $(COMPOSE_FILE) up --build
up-detached:
@echo "Start service of ft_transcendence in the background ..."
@docker compose -f $(COMPOSE_FILE) up -d
build-no-cache:
@echo "Build ft_transcendence with no cache ..."
@docker compose -f $(COMPOSE_FILE) build --no-cache
stop:
@echo "Stopping ft_transcendence ..."
@docker compose -f $(COMPOSE_FILE) stop
down:
@echo "Stopping and removing containers, networks, volumes in ft_transcendence ..."
@docker compose -f $(COMPOSE_FILE) down
debug: clean
@echo "Launching ft_transcendence with debug logs ..."
@docker compose -f $(COMPOSE_FILE) up --build
remove_images:
@if [ -n "$$(docker image ls -q)" ]; then \
echo "Removing docker images ..."; \
docker compose -f $(COMPOSE_FILE) down --rmi all; \
echo "Images removed $(GREEN)\t\t\t\t[ ✔ ]$(RESET)"; \
else \
echo "\n$(BOLD)$(RED)No Docker images found.\n$(RESET)"; \
fi
remove_containers:
@if [ -n "$$(docker ps -aq)" ]; then \
echo "$(YELLOW)\n. . . stopping and removing docker containers . . . \n$(RESET)"; \
docker compose -f $(COMPOSE_FILE) down; \
echo "\n$(BOLD)$(GREEN)Containers stopped and removed [ ✔ ]\n$(RESET)"; \
else \
echo "\n$(BOLD)$(RED)No Docker containers found.$(RESET)\n"; \
fi
remove_certs:
@if [ -n "$$(docker volume ls -q)" ]; then \
echo "$(YELLOW)\n. . . removing docker volumes . . . \n$(RESET)"; \
docker compose -f $(COMPOSE_FILE) down --volumes; \
echo "\n$(BOLD)$(GREEN)Volumes removed [ ✔ ]\n$(RESET)"; \
else \
echo "\n$(BOLD)$(RED)No Docker volumes found.\n$(RESET)"; \
fi
clean: remove_certs
@echo "ft_transcendence certs cleaned $(GREEN)\t\t[ ✔ ]$(RESET)"
fclean : remove_certs remove_containers remove_images
@echo "ft_transcendence cleaned $(GREEN)\t\t[ ✔ ]$(RESET)"
prune:
@echo "$(YELLOW)\n Pruning all docker environment... \n$(RESET)"
docker system prune -a -f
docker volume prune -f
@echo "ft_transcendence pruned $(GREEN)\t\t[ ✔ ]$(RESET)"
re: prune all
# Execute a command in a running container
# Usage: make exec service=[service_name] cmd="[command]"
exec:
docker exec -it $(service) $(cmd)
cli:
@python3 $(CLI) $(HOST_IN_USE) $(BACKEND_PORT)
status:
@echo "\n$(YELLOW)docker ps -a $(RESET)" && docker ps -a
@echo "\n$(YELLOW)docker volume ls $(RESET)" && docker volume ls
@echo "\n$(YELLOW)docker images -a $(RESET)" && docker images -a
@echo "\n$(YELLOW)docker network ls $(RESET)" && docker network ls
logs:
@if [ -n "$$(docker ps -aq)" ]; then \
echo "$(YELLOW)\n. . . showing docker logs . . . \n$(RESET)"; \
echo "\n$(YELLOW)Backend container logs:$(RESET)"; docker logs backend; \
echo "\n$(YELLOW)Frontend container logs:$(RESET)"; docker logs frontend; \
else \
echo "\n$(BOLD)$(RED)No Docker containers found.$(RESET)\n"; \
fi
.PHONY: all up up-detached build-no-cache stop down debug remove_images remove_containers remove_certs prune re clean fclean exec cli status logs
# COLORS
RESET = \033[0m
WHITE = \033[37m
GREY = \033[90m
RED = \033[91m
DRED = \033[31m
GREEN = \033[92m
DGREEN = \033[32m
YELLOW = \033[93m
DYELLOW = \033[33m
BLUE = \033[94m
DBLUE = \033[34m
MAGENTA = \033[95m
DMAGENTA = \033[35m
CYAN = \033[96m
DCYAN = \033[36m
# FORMAT
BOLD = \033[1m
ITALIC = \033[3m
UNDERLINE = \033[4m
STRIKETHROUGH = \033[9m