-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
123 lines (100 loc) · 4.43 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
COMPOSE_VERSION = $$(grep COMPOSE_VERSION= srcs/.env | cut -d'=' -f2)
ALPINE_VERSION = $$(grep ALPINE_VERSION= srcs/.env | cut -d'=' -f2)
NGINX_VERSION = $$(grep NGINX_VERSION= srcs/.env | cut -d'=' -f2)
WORDPRESS_VERSION = $$(grep WORDPRESS_VERSION= srcs/.env | cut -d'=' -f2)
MARIADB_VERSION = $$(grep MARIADB_VERSION= srcs/.env | cut -d'=' -f2)
MYSQL_DATABASE = $$(grep MYSQL_DATABASE= srcs/.env | cut -d'=' -f2)
MYSQL_ROOT_PASSWORD = $$(grep MYSQL_ROOT_PASSWORD= srcs/.env | cut -d'=' -f2)
MYSQL_USER = $$(grep MYSQL_USER= srcs/.env | cut -d'=' -f2)
MYSQL_PASSWORD = $$(grep MYSQL_PASSWORD= srcs/.env | cut -d'=' -f2)
MYSQL_ADMIN = $$(grep MYSQL_ADMIN= srcs/.env | cut -d'=' -f2)
MYSQL_ADMIN_PASSWORD= $$(grep MYSQL_ADMIN_PASSWORD= srcs/.env | cut -d'=' -f2)
WP_ADMIN = $$(grep WP_ADMIN= srcs/.env | cut -d'=' -f2)
WP_ADMIN_PASSWORD = $$(grep WP_ADMIN_PASSWORD= srcs/.env | cut -d'=' -f2)
WP_ADMIN_EMAIL = $$(grep WP_ADMIN_EMAIL= srcs/.env | cut -d'=' -f2)
LOGIN = $$(grep LOGIN= srcs/.env | cut -d'=' -f2)
WORDPRESS_FILES = /home/$(LOGIN)/data/wordpress_files
WORDPRESS_DATABASE = /home/$(LOGIN)/data/wordpress_database
DOCKER_COMPOSE = docker-compose --project-directory srcs \
-f srcs/docker-compose.yaml
NAME = inception
all : help
$(NAME) : build
help : ## Print command manual
@echo "Project by [email protected]"
@echo ""
@echo "Makefile commands:"
@echo ""
@echo "version: Show services versions"
@echo "variable: Show project variables"
@echo "setup: Update docker-compose installation"
@echo ""
@echo "build: Build the project with docker-compose build"
@echo "up: Start services in detached mode with docker-compose up"
@echo "down: Remove services with docker-compose down"
@echo "ps: Show running services with docker-compose ps"
@echo "stop: Stop running services with docker-compose stop"
@echo ""
@echo "ilean: Remove project build images"
@echo "vlean: Remove project volumes"
@echo "clean: Remove project images and volumes"
@echo "uclean: Remove created project user"
@echo "re: Run clean and build command to re make the project from scratch"
version : ## Print services versions
@echo "Services versions"
@echo ""
@echo "compose version - $(COMPOSE_VERSION)"
@echo "alpine version - $(ALPINE_VERSION)"
@echo "nginx version - $(NGINX_VERSION)"
@echo "wordpress version - $(WORDPRESS_VERSION)"
@echo "mariadb version - $(MARIADB_VERSION)"
variable: ## Print project variables
@echo "Project variables"
@echo ""
@echo "MYSQL_DATABASE - $(MYSQL_DATABASE)"
@echo "MYSQL_ROOT_PASSWORD - $(MYSQL_ROOT_PASSWORD)"
@echo "MYSQL_USER - $(MYSQL_USER)"
@echo "MYSQL_PASSWORD - $(MYSQL_PASSWORD)"
@echo "MYSQL_ADMIN - $(MYSQL_ADMIN)"
@echo "MYSQL_ADMIN_PASSWORD - $(MYSQL_ADMIN_PASSWORD)"
@echo ""
@echo "WP_ADMIN - $(WP_ADMIN)"
@echo "WP_ADMIN_PASSWORD - $(WP_ADMIN_PASSWORD)"
@echo "WP_ADMIN_EMAIL - $(WP_ADMIN_EMAIL)"
setup : ## Update docker-compose installation and setting up project
sudo service nginx stop
-sudo adduser --gecos "" $(LOGIN)
sudo usermod -aG docker $$USER
sudo usermod -aG sudo $(LOGIN)
sudo usermod -aG docker $(LOGIN)
sudo mkdir -p $(WORDPRESS_FILES) $(WORDPRESS_DATABASE)
sudo curl -Lo /usr/local/bin/docker-compose "https://github.com/docker/compose/releases/download/$(COMPOSE_VERSION)/docker-compose-$$(uname -s)-$$(uname -m)"
sudo chmod +x /usr/local/bin/docker-compose
@sudo /bin/bash -c 'if ! grep "127.0.0.1 $(LOGIN).42.fr" /etc/hosts; then echo "127.0.0.1 $(LOGIN).42.fr" >> /etc/hosts; fi'
#su $(LOGIN)
build : ## Build the project with docker-compose
$(DOCKER_COMPOSE) build
up : ## Starts services containers
$(DOCKER_COMPOSE) up -d
down : ## Remove services
$(DOCKER_COMPOSE) down
ps : ## Show services
$(DOCKER_COMPOSE) ps
stop : ## Stop services
$(DOCKER_COMPOSE) stop
iclean : ## Remove docker images
-docker rmi -f alpine:$(ALPINE_VERSION)
-docker rmi -f nginx:inception
-docker rmi -f wordpress:inception
-docker rmi -f mariadb:inception
vclean : ## Remove docker volumes
-docker volume rm wordpress_files
-docker volume rm wordpress_database
clean : iclean vclean
uclean : ## Remove project user
sudo userdel $(LOGIN)
sudo rm -rf /home/$(LOGIN)
re : clean build
.PHONY : all build help version variable \
setup up down stop ps \
iclean vclean clean uclean re