-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
119 lines (96 loc) · 3.59 KB
/
Makefile
File metadata and controls
119 lines (96 loc) · 3.59 KB
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
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: dbarba-v <dbarba-v@student.42madrid.com +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2026/02/23 09:42:26 by dbarba-v #+# #+# #
# Updated: 2026/03/17 10:35:49 by dbarba-v ### ########.fr #
# #
# **************************************************************************** #
NAME = inception
COMPOSE = docker compose
DOCKERFILE = srcs/docker-compose.yml
# .env file, can be overridden
ENV ?= srcs/.env
UP = $(COMPOSE) -f $(DOCKERFILE) up -d
DOWN = $(COMPOSE) -f $(DOCKERFILE) down
STOP = $(COMPOSE) -f $(DOCKERFILE) stop
RESTART = $(COMPOSE) -f $(DOCKERFILE) restart
PS = $(COMPOSE) -f $(DOCKERFILE) ps
BUILD = $(COMPOSE) --env-file $(ENV) -f $(DOCKERFILE) build
CONFIG = $(COMPOSE) -f $(DOCKERFILE) config
# clean removes volumes
# fclean also prunes images
CLEAN = $(COMPOSE) -f $(DOCKERFILE) down --volumes
FCLEAN = $(COMPOSE) -f $(DOCKERFILE) down --volumes --rmi all
-include srcs/.env
export $(shell sed 's/=.*//' srcs/.env)
.PHONY: inception all secrets up down stop restart ps shell build config clean fclean re help
inception: all
all: up
secrets:
@sh srcs/tools/check-secrets.sh
up: secrets
@mkdir -p "/home/$$USER/data/mariadb" && \
mkdir -p "/home/$$USER/data/wordpress"
$(UP)
down:
$(DOWN)
stop:
$(STOP)
restart:
$(RESTART)
ps:
$(PS)
shell:
@if [ -z "$(SERVICE)" ]; then \
echo "Error: SERVICE is not set"; \
echo "Usage: make shell SERVICE=<service>"; \
exit 1; \
fi
$(COMPOSE) -f $(DOCKERFILE) exec $(SERVICE) /bin/sh
build:
$(BUILD)
config:
$(CONFIG)
clean:
@docker run --rm \
-v "/home/$$USER/data:/mnt/data" \
debian:12 sh -c "rm -rf /mnt/data/mariadb /mnt/data/wordpress"
@ rm -rf /home/$$USER/data
$(CLEAN)
fclean: clean
$(FCLEAN)
re: fclean all
help:
@printf "\n"
@echo "Inception - Makefile targets"
@echo "Usage: make TARGET [VAR=value] (e.g. make shell SERVICE=nginx)"
@echo ""
@echo "Targets:"
@echo " all Start all containers (default -> up)"
@echo " up Start all containers in detached mode"
@echo " down Stop and remove all containers"
@echo " stop Stop running containers"
@echo " restart Restart containers"
@echo " ps Show container status"
@echo " shell Open a shell in a service (SERVICE=<name>)"
@echo " build Build images (uses $(ENV) for build args)"
@echo " config Validate and show compose configuration"
@echo " secrets Check for secrets and create missing ones"
@echo " clean Stop/remove containers and volumes"
@echo " fclean Full cleanup: containers, volumes and images"
@echo " re Full rebuild (fclean + all)"
@echo " help Show this help"
@echo ""
@echo "Useful variables:"
@echo " SERVICE Service name for 'shell' and 'exec' operations"
@echo " ENV .env file used by build ($(ENV))"
@echo ""
@echo "Examples:"
@echo " make up # Start everything"
@echo " make shell SERVICE=nginx # Open sh in nginx container"
@echo " make build # Build images with env from $(ENV)"
@echo ""