-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
223 lines (182 loc) · 6.41 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: agaley <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/12/15 15:51:13 by agaley #+# #+# #
# Updated: 2024/07/23 14:56:27 by agaley ### ########lyon.fr #
# #
# **************************************************************************** #
NAME = webserv
CXX = c++
CXXFLAGS = -Wall -Wextra -Werror -MMD -std=c++98
DEBUGFLAGS = -gdwarf-3 #-fsanitize=address
SRC_DIR = src
OBJ_DIR = .obj
DEBUG_OBJ_DIR = .obj_debug
LOG_DIR = ./logs
LOG_FILE_EXT = .log
export MY_GID ?= $(id -g)
export BUILD_TYPE ?= production
export MY_UID ?= $(id -u)
export NGINX_PORT_1 ?= 8000
export NGINX_PORT_2 ?= 8001
export CONTAINER ?= webserv-production
export PORT ?= 8080
SRC = $(SRC_DIR)/Server.cpp \
$(SRC_DIR)/Config.cpp $(SRC_DIR)/ConfigManager.cpp $(SRC_DIR)/ConfigParser.cpp \
$(SRC_DIR)/FileManager.cpp \
$(SRC_DIR)/ConnectionHandler.cpp $(SRC_DIR)/CacheHandler.cpp \
$(SRC_DIR)/Worker.cpp $(SRC_DIR)/EventQueue.cpp $(SRC_DIR)/EventData.cpp \
$(SRC_DIR)/HTTPRequest.cpp $(SRC_DIR)/HTTPResponse.cpp $(SRC_DIR)/URI.cpp \
$(SRC_DIR)/CGIHandler.cpp $(SRC_DIR)/VirtualServer.cpp \
$(SRC_DIR)/Exception.cpp $(SRC_DIR)/HTTPMethods.cpp \
$(SRC_DIR)/Logger.cpp $(SRC_DIR)/Utils.cpp \
$(SRC_DIR)/main.cpp
OBJ = $(patsubst $(SRC_DIR)/%.cpp, $(OBJ_DIR)/%.o, $(SRC))
DEBUG_OBJ = $(patsubst $(SRC_DIR)/%.cpp, $(DEBUG_OBJ_DIR)/%.o, $(SRC))
DEPS = $(patsubst $(SRC_DIR)/%.cpp, $(OBJ_DIR)/%.d, $(SRC))
DEBUG_DEPS = $(patsubst $(SRC_DIR)/%.cpp, $(DEBUG_OBJ_DIR)/%.d, $(SRC))
VPATH = $(SRC_DIR)
all: $(NAME) setup
fix:
dos2unix *.sh && chmod +x *.sh
setup:
NUM=1; \
for dir in /var/www/html/static_templates/* ; do \
if [ "$$(basename "$$dir")" != "images" ] && [ "$$(basename "$$dir")" != "README.md" ]; then \
echo "$$dir"; \
mv "$$dir" /var/www/html/static_templates/static$$NUM || true; \
NUM=$$((NUM + 1)); \
if [ "$$NUM" -eq 5 ]; then \
break; \
fi; \
fi; \
done; \
NUM=1; \
for dir in /mnt/e/webserv/html-website-templates/* ; do \
if [ "$$(basename "$$dir")" != "images" ] && [ "$$(basename "$$dir")" != "README.md" ]; then \
echo "$$dir"; \
mv "$$dir" /home/mchenava/webserv/html-website-templates/static$$NUM || true; \
NUM=$$((NUM + 1)); \
if [ "$$NUM" -eq 5 ]; then \
break; \
fi; \
fi; \
done
$(NAME): $(OBJ) update_gitignore
$(CXX) $(CXXFLAGS) $(OBJ) -lpthread -o $(NAME)
mkdir -p $(LOG_DIR)
$(OBJ_DIR)/%.o: %.cpp
@mkdir -p $(OBJ_DIR)
$(CXX) $(CXXFLAGS) -c $< -o $@
debug: $(DEBUG_OBJ)
$(CXX) $(CXXFLAGS) $(DEBUGFLAGS) $(DEBUG_OBJ) -lpthread -o $(NAME)
$(DEBUG_OBJ_DIR)/%.o: %.cpp
@mkdir -p $(DEBUG_OBJ_DIR)
$(CXX) $(CXXFLAGS) $(DEBUGFLAGS) -c $< -o $@
run: daemon
$(MAKE) wait-for-healthy
docker compose exec -it webserv make
docker compose exec -it webserv bash -c "kill 1"
sleep 1
@make logs
daemon:
BUILD_TYPE=production docker compose up --build -d webserv
watch:
while true; do \
$(MAKE); \
inotifywait -qre close_write /app/src; \
done
dev:
export BUILD_TYPE=debug
docker compose up --build -d webserv-dev
docker compose exec -it webserv-dev make debug
docker compose exec -it webserv-dev bash -c "./webserv"
valgrind:
export BUILD_TYPE=debug
docker compose up --build -d webserv-dev
docker compose exec -it webserv-dev make debug
docker compose exec -it webserv-dev bash -c "ulimit -n 1024 && valgrind --track-origins=yes ./webserv"
valgrind-full:
export BUILD_TYPE=debug
docker compose up --build -d webserv-dev
docker compose exec -it webserv-dev make debug
docker compose exec -it webserv-dev bash -c "ulimit -n 1024 && valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes ./webserv"
helgrind:
export BUILD_TYPE=debug
docker compose up --build -d webserv-dev
docker compose exec -it webserv-dev make debug
docker compose exec -it webserv-dev bash -c "ulimit -n 1024 && valgrind --tool=helgrind -s ./webserv"
logs:
docker compose logs -f
stop:
docker compose stop
test: stop daemon
$(MAKE) wait-for-healthy
./test.sh
@make clean
test-compare: stop daemon
@$(MAKE) nginxd
$(MAKE) wait-for-healthy
$(MAKE) wait-for-nginx-healthy
./test_compare.sh
@make clean
siege: stop daemon
$(MAKE) wait-for-healthy
echo "init" > siege.log
docker compose up siege
# make logs
@make clean
cat siege.log
siege-nginx: stop nginxd
$(MAKE) wait-for-nginx-healthy
CONTAINER=nginx docker compose up siege
@make clean
cat siege.log
run_tests:
@./test.sh
@./test_compare.sh
wait-for-healthy:
@echo "Waiting for webserv docker to be healthy..."
@while ! docker inspect --format='{{json .State.Health.Status}}' webserv-production | grep -q '"healthy"'; do \
echo "Waiting for webserv to become healthy..."; \
sleep 2; \
done
wait-for-nginx-healthy:
@echo "Waiting for nginx docker to be healthy..."
@while ! docker inspect --format='{{json .State.Health.Status}}' nginx | grep -q '"healthy"'; do \
echo "Waiting for nginx to become healthy..."; \
sleep 2; \
done
update_gitignore:
@if ! grep -q "$(LOG_FILE_EXT)" .gitignore; then \
echo "$(LOG_FILE_EXT)" >> .gitignore; \
echo "Added $(LOG_FILE_EXT) to .gitignore"; \
else \
echo "$(LOG_FILE_EXT) already in .gitignore"; \
fi
nginx:
NGINX_PORT_1=$(NGINX_PORT_1) NGINX_PORT_2=$(NGINX_PORT_2) docker compose up nginx --build
nginxd:
NGINX_PORT_1=$(NGINX_PORT_1) NGINX_PORT_2=$(NGINX_PORT_2) docker compose up -d nginx --build
docker-clean:
docker compose down --rmi all
docker-fclean:
docker system prune --all --volumes -f
-include $(DEPS)
-include $(DEBUG_DEPS)
clean: docker-stop docker-clean
rm -f $(OBJ) $(DEBUG_OBJ)
rm -f $(DEPS) $(DEBUG_DEPS)
fclean: clean docker-fclean
rm -f $(NAME)
rm -rf $(OBJ_DIR) $(DEBUG_OBJ_DIR)
re: fclean all
debug_re: fclean debug
.PHONY: all clean fclean re debug debug_re update_gitignore
.PHONY: run daemon dev logs stop
.PHONY: test test-compare wait-for-healthy wait-for-nginx-healthy
.PHONY: nginx nginxd docker-stop docker-fclean run_tests