-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
154 lines (126 loc) · 4.44 KB
/
Copy pathMakefile
File metadata and controls
154 lines (126 loc) · 4.44 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
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
#
# Makefile
# Les Polypodes, 2014-06-25 12:44
# Licence: MIT
# Source: https://github.com/polypodes/Build-and-Deploy/blob/master/deploy/Makefile
# Usage:
#
# make help
# make init
# make release
# make rollback
# make update
# make check
############################################################################
# Vars
PWD := $(shell pwd)
RELEASES := $(PWD)/releases
CURRENT := $(PWD)/current
WEB := $(PWD)/current/web
OLD := $(PWD)/old
NOW := $(shell date +%Y-%m-%d--%H-%M-%S)
NEW := $(RELEASES)/NEW
REPO := "https://github.com/polypodes/Deploy.git"
BRANCH := 'master'
DB_USER := $(shell if [ -f app/config/parameters.yml ] ; then cat app/config/parameters.yml | grep 'database_user' | sed 's/database_user: //' | sed 's/^ *//;s/ *$$//' ; fi)
DB_PASSWORD := $(shell if [ -f app/config/parameters.yml ] ; then cat app/config/parameters.yml | grep 'database_password' | sed 's/database_password: //' | sed 's/null//' | sed 's/^ *//;s/ *$$//' ; fi)
DB_NAME := $(shell if [ -f app/config/parameters.yml ] ; then cat app/config/parameters.yml | grep 'database_name' | sed 's/database_name: //' | sed 's/^ *//;s/ *$$//' ; fi)
# Linux user & group
WWWUSER := myLinuxUser
WWWGROUP := myLinuxGroup
# Colors
YELLOW := $(shell tput bold ; tput setaf 3)
GREEN := $(shell tput bold ; tput setaf 2)
RESETC := $(shell tput sgr0)
# Custom MAKE options
ifndef VERBOSE
MAKEFLAGS += --no-print-directory
endif
# `make`command will run this default task set:
all: check help
############################################################################
# Specific tasks:
check:
@test -d $(RELEASES) || mkdir -p $(RELEASES)
permissions:
@chmod -R 775 $(CURRENT)
@chown -R $(WWWUSER):$(WWWGROUP) $(CURRENT)
create:
@echo "Creating the very first release"
@mv $(NEW) $(RELEASES)/$(NOW)
@ln -s $(RELEASES)/$(NOW) $(CURRENT)
switch:
@echo "Switching actual 'current' & 'old' symlinks using the new release..."
@rm $(OLD);
@mv $(CURRENT) $(OLD);
@mv $(NEW) $(RELEASES)/$(NOW)
@ln -s $(RELEASES)/$(NOW) $(CURRENT)
@cp $(OLD)/sites/default/settings.php $(CURRENT)/sites/default/settings.php
@cp -R $(OLD)/sites/default/files/* $(CURRENT)/sites/default/files/
rollback:
@mv $(CURRENT) rollbacked
@mv $(OLD) $(CURRENT)
clear:
@echo "Clearing caches using drush..."
# @drush cc all
robot:
@echo "User-agent: *" > $(WEB)/robots.txt
@echo "Disallow: " >> $(WEB)/robots.txt
unrobot:
@echo "User-agent: *" > $(WEB)/robots.txt
@echo "Disallow: /" >> $(WEB)/robots.txt
dumps:
@echo "Creating dump folder for SQL exports..."
@mkdir ./dumps
mysqldump: dumps
@echo "dumping existing db into ./dumps ..."
@mysqldump --user=${DB_USER} --password=${DB_PASSWORD} ${DB_NAME} > dumps/${NOW}.sql 2>/dev/null
mysqlinfo:
@echo "mysql --user=${DB_USER} --password=${DB_PASSWORD} ${DB_NAME}"
clone:
@git clone -b $(BRANCH) $(REPO) $(NEW)
@cd $(NEW) && git config core.filemode false && cd $(PWD)
done:
@echo
@ls -la
@echo "${GREEN}Done.${RESETC}"
@echo
help:
@echo
@echo "${GREEN}Usual tasks:${RESETC}"
@echo
@echo "\t* (clone) create the initial release:\t\t${YELLOW}make init${RESETC}"
@echo "\t* (clone) add a new, up-to-date release:\t${YELLOW}make release${RESETC}"
@echo "\t* (pull) update the current release:\t\t${YELLOW}make update${RESETC}"
@echo
@echo "${GREEN}Other specific tasks:${RESETC}"
@echo
@echo "\t* display this help message:\t\t\t${YELLOW}make help${RESETC}"
@echo "\t* (mkdir) check dirs structure:\t\t\t${YELLOW}make check${RESETC}"
@echo "\t* (rm) clear cache:\t\t\t\t${YELLOW}make clear${RESETC}"
@echo "\t* (chown+chmod) set up files/dirs permissions:\t${YELLOW}make permissions${RESETC}"
@echo "\t* (mv) rollback to the previous/old release:\t${YELLOW}make switch${RESETC}"
@echo
############################################################################
# Usual tasks:
init: check
@echo "Git-cloning sources using ${GREEN}$(BRANCH)${RESETC} branch..."
@$(MAKE) clone
@$(MAKE) create
@$(MAKE) clear
@$(MAKE) done
release: check mysqldump
@echo "Git-cloning sources using ${GREEN}$(BRANCH)${RESETC} branch..."
@$(MAKE) clone
@$(MAKE) switch
@$(MAKE) clear
@$(MAKE) done
update: check mysqldump
@echo "Git-pulling sources using $(BRANCH) branch..."
@cd $(CURRENT) && git pull origin $(BRANCH) && cd $(PWD)
@$(MAKE) clear
@$(MAKE) done
.PHONY: all check permissions switch rollback clear done
.PHONY: help init clone release update robot unrobot mysqldump mysqlinfo
# vim:ft=make
#