aboutsummaryrefslogtreecommitdiff
path: root/share/templater/drupal-composer/files/Makefile.drupal-composer
blob: c8f26ec8a0880302840a4110a93f1d63c8b65751 (plain)
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
#
# Makefile for a Drupal 8 Application using Composer - https://templater.fluxo.info
#

# Parameters
PROJECT      = drupal
DATABASE     = $(PROJECT)
SITES_FOLDER = web/sites
SITE_FOLDER  = $(SITES_FOLDER)/default
DRUSH        = drush
DATE         = $(shell date +%Y%m%d)

# Setup production environment
production: post_receive composer settings perms

# Setup virtual machine using kvmx
kvmx:
	#kvmx up || true
	kvmx provision
	#echo '( cd /srv/shared && make drush   )'  | kvmx ssh
	#echo '( cd /srv/shared && make vendor  )'  | kvmx ssh
	echo '( cd /srv/shared && make production)' | kvmx ssh
	#kvmx ssh "$(DRUSH) pm-enable devel -y"

# Run composer
composer:
	composer install
	@#composer update
	composer dump-autoload --optimize --profile

# Drupal settings
settings:
	test -s   $(SITES_FOLDER)/sites.php         || cp $(SITES_FOLDER)/example.sites.php            $(SITES_FOLDER)/sites.php
	test -s   $(SITE_FOLDER)/settings.php       || cp $(SITE_FOLDER)/../example.settings.php       $(SITE_FOLDER)/settings.php
	test -s   $(SITE_FOLDER)/settings.local.php || cp $(SITE_FOLDER)/../example.settings.local.php $(SITE_FOLDER)/settings.local.php
	chmod 640 $(SITE_FOLDER)/settings.local.php
	chmod 640 $(SITE_FOLDER)/services.yml

# Permissions
perms:
	chmod 755 cli
	chmod 755 web/sites/default
	chmod 755 web/sites/default/files

# Reset the working copy
reset:
	@#git reset HEAD
	git checkout -f

# Deploy code pushed on remote host
deploy: perms reset
	composer install
	$(DRUSH) updatedb
	$(DRUSH) cache-rebuild
	$(DRUSH) config-import -y

# Load pristine db from the initial upstream developer
initdb_pristine: settings
	test -s sql/dumps/pristine.zip && unzip -p sql/dumps/pristine.zip | $(DRUSH) sql-cli || true
	test -s sql/dumps/pristine.zip && $(DRUSH) updatedb -y || true

# Load the database dump, clear the drupal cache and updated database
# See https://www.drupal.org/node/628130
initdb: settings
	test -s sql/dumps/latest.sql.gz && gzip -dc sql/dumps/latest.sql.gz | $(DRUSH) sql-cli || true
	test -s sql/dumps/latest.sql.gz && $(DRUSH) updatedb -y || true

# Dump the database, clearing the cache to ensure a small package
dumpdb: settings cache
	mkdir -p sql/dumps
	rm -f sql/dumps/latest.sql.gz
	rm -f sql/dumps/$(DATE).sql.gz
	$(DRUSH) sql-dump > sql/dumps/$(DATE).sql
	( cd sql/dumps && gzip $(DATE).sql && ln -s $(DATE).sql.gz latest.sql.gz )

# Destroy the database
destroydb: settings
	echo "DROP DATABASE $(DATABASE); CREATE DATABASE $(DATABASE);" | $(DRUSH) sql-cli

# Reinitializes the database
reinitdb: destroydb initdb

# Clear drupal cache
cache:
	$(DRUSH) cache-rebuild

# Export configuration
export:
	$(DRUSH) config-export -y

# Import configuration
import:
	$(DRUSH) config-import -y

sync_files_from_development:
	rsync -avz --delete $(DEVELOPMENT)/sql/dumps/ sql/dumps/
	rsync -avz --delete $(DEVELOPMENT)/$(SITE_FOLDER)/files/ $(SITE_FOLDER)/files/

sync_files_from_production:
	rsync -avz --delete $(PRODUCTION)/sql/dumps/ sql/dumps/
	rsync -avz --delete $(PRODUCTION)/$(SITE_FOLDER)/files/ $(SITE_FOLDER)/files/

sync_files_to_development:
	rsync -avz --delete sql/dumps/ $(DEVELOPMENT)/sql/dumps/
	rsync -avz --delete $(SITE_FOLDER)/files/ $(DEVELOPMENT)/$(SITE_FOLDER)/files/

sync_files_to_production:
	rsync -avz --delete sql/dumps/ $(PRODUCTION)/sql/dumps/
	rsync -avz --delete $(SITE_FOLDER)/files/ $(PRODUCTION)/$(SITE_FOLDER)/files/

updatedb:
	$(DRUSH) updatedb -y

composer_update:
	composer update drupal/core --with-dependencies

# Upgrade drupal
upgrade-drupal: composer_update updatedb

# Parameters
CORE      = 8
PROJECT   = drupal
DATABASE ?= $(PROJECT)
ENV      ?= dev
DATE      = $(shell date +%Y%m%d)
CWD       = $(shell pwd)
DESTDIR  ?= /var/www/data
DRUPAL    = $(DESTDIR)/drupal-$(CORE)
DRUSH     = drush -r $(DRUPAL) -l $(PROJECT)

# Setup production environment
production: submodules post_receive drush settings ownership

# Setup a development environment
develop: submodules $(CONTAINER)
	#rm -rf $(DRUPAL)/sites/default
	#ln -s $(PROJECT) $(DRUPAL)/sites/default

# Old target
# Install the platform
#platform: drupal drush settings symlinks initdb cache

# Keep code in sync
sync-code: update drush cache import

# Initialize and update git submodules
submodules:
	git submodule sync          --recursive
	git submodule update --init --recursive

# Setup the virtual machine using vagrant
vagrant:
	vagrant up || true
	vagrant provision
	echo '( cd /vagrant && make drush )'    | vagrant ssh
	echo '( cd /vagrant && make settings )' | vagrant ssh
	#vagrant ssh -c "$(DRUSH) pm-enable devel -y"

# Setup the virtual machine using kvmx
kvmx:
	#kvmx up || true
	kvmx provision
	echo '( cd /srv/shared && make drush )'    | kvmx ssh
	echo '( cd /srv/shared && make settings )' | kvmx ssh
	#kvmx ssh "$(DRUSH) pm-enable devel -y"

# Old target
# Download drupal, setup folder structure and config file
#
# You might want to use "-n" to avoid _drush_recursive_copy cpu hog if previous
# installation already exists when using 9p filesystem
#drupal:
#	#rm -rf $(DESTDIR)/drupal-$(CORE)* && drush pm-download -y -v drupal-$(CORE) --destination=/tmp/drupal && mv /tmp/drupal/drupal-$(CORE).* $(DESTDIR)/
#	#drush pm-download -y -v drupal-$(CORE) --destination=$(DESTDIR)
#	#( cd $(DRUPAL)/.. && ln -s drupal-$(CORE).* drupal-$(CORE) )
#	BASE=$(DESTDIR) drupal download $(CORE)

# Old target
# Make the needed symlinks
#symlinks:
#	ln -sf -t $(DRUPAL)/sites/$(PROJECT)/ $(CWD)/files
#	ln -sf -t $(DRUPAL)/sites/$(PROJECT)/ $(CWD)/config
#	ln -sf -t $(DRUPAL)/sites/$(PROJECT)/ $(CWD)/themes
#	ln -sf -t $(DRUPAL)/sites/$(PROJECT)/ $(CWD)/modules
#	ln -sf -t $(DRUPAL)/sites/$(PROJECT)/ $(CWD)/libraries

# Default settings
default_settings:
	test -s sites.php        || cp $(DRUPAL)/sites/example.sites.php            sites.php
	test -s settings.dev.php || cp $(DRUPAL)/sites/default/default.settings.php settings.dev.php
	test -s services.dev.yml || cp $(DRUPAL)/sites/default/default.services.yml services.dev.yml

# Custom settings
custom_settings:
	#test -s   $(DRUPAL)/sites/sites.php                      || cp sites.php              $(DRUPAL)/sites/sites.php
	#mkdir -p  $(DRUPAL)/sites/$(PROJECT)
	#test -s   $(DRUPAL)/sites/$(PROJECT)/settings.$(ENV).php || cp settings.dev.php       $(DRUPAL)/sites/$(PROJECT)/settings.$(ENV).php
	#test -s   $(DRUPAL)/sites/$(PROJECT)/settings.php        || ln -s settings.$(ENV).php $(DRUPAL)/sites/$(PROJECT)/settings.php
	#test -s   $(DRUPAL)/sites/$(PROJECT)/services.$(ENV).yml || cp services.dev.yml       $(DRUPAL)/sites/$(PROJECT)/services.$(ENV).yml
	#test -s   $(DRUPAL)/sites/$(PROJECT)/services.yml        || ln -s services.$(ENV).yml $(DRUPAL)/sites/$(PROJECT)/services.yml
	#chmod 640 $(DRUPAL)/sites/$(PROJECT)/settings.php
	#chmod 640 $(DRUPAL)/sites/$(PROJECT)/services.yml
	test -s   settings.$(ENV).php || cp settings.dev.php       settings.$(ENV).php
	test -s   settings.php        || ln -s settings.$(ENV).php settings.php
	test -s   services.$(ENV).yml || cp services.dev.yml       services.$(ENV).yml
	test -s   services.yml        || ln -s services.$(ENV).yml services.yml
	chmod 640 settings.php
	chmod 640 services.yml

# Setup drupal settings
settings: default_settings custom_settings
	test -s $(DRUPAL)/sites/sites.php || sudo cp sites.php $(DRUPAL)/sites/sites.php

# Fix ownership
ownership:
	sudo chown -R $(PROJECT). $(DRUPAL)/sites/$(PROJECT)
	sudo chmod 755            $(DRUPAL)/sites/$(PROJECT)

# Run drush makefile
drush:
	sudo drush make -n --no-core drupal.make.yml $(DRUPAL)

# Run drush site-install
site_install: settings
	$(DRUSH) site-install -y

# Run drush site-install, sqlite version
# See https://api.drupal.org/api/drupal/core%21INSTALL.sqlite.txt/8.4.x
site_install_sqlite: settings
	mkdir -p sql/.ht.sqlite
	touch sql/dumps/.ht.sqlite
	$(DRUSH) site-install --db-url=sqlite://$(CWD)/sql/dumps/.ht.sqlite

# Update the database
updatedb:
	$(DRUSH) updatedb -y --entity-updates

# Load the database dump, clear the drupal cache and fix image paths
# See https://www.drupal.org/node/628130
initdb: settings
	test -s sql/dumps/latest.sql.gz && gzip -dc sql/dumps/latest.sql.gz | $(DRUSH) sql-cli || true
	test -s sql/dumps/latest.sql.gz && $(DRUSH) updatedb -y || true

# Dump the database, clearing the cache to ensure a small package
dumpdb: settings cache
	mkdir -p sql/dumps
	rm -f sql/dumps/latest.sql.gz
	rm -f sql/dumps/$(DATE).sql.gz
	$(DRUSH) sql-dump > sql/dumps/$(DATE).sql
	( cd sql/dumps && gzip $(DATE).sql && ln -s $(DATE).sql.gz latest.sql.gz )

# Clear drupal cache
cache:
	$(DRUSH) cache-rebuild

# Destroy the database
destroydb: settings
	echo "DROP DATABASE $(DATABASE); CREATE DATABASE $(DATABASE);" | $(DRUSH) sql-cli

# Reinitializes the database
reinitdb: destroydb initdb

# Cleanup develop environment
clean:
	vagrant halt 			 || true
	vagrant destroy -f || true
	kvmx stop 				 || true
	kvmx destroy 			 || true
	rm -rf vendor/drupal*

# Export configuration
export:
	$(DRUSH) config-export -y

# Import configuration
import:
	$(DRUSH) config-import -y

# Diff configuration
# Needs https://github.com/eriktufvesson/drush-config-diff
diff:
	$(DRUSH) config-diff

# Update the codebase
update: pull submodules

# Upgrade modules
upgrade-modules:
	sudo $(DRUSH) up

# Upgrade drupal
upgrade-drupal:
	BASE=$(DESTDIR) sudo drupal upgrade $(CORE)

# Configure update hook on remote host
#post_receive:
#	git config receive.denyCurrentBranch ignore
#	cd .git/hooks && ln -sf ../../bin/post-receive

# Pull changes
pull:
	git pull

# Reset the working copy
reset:
	#git reset HEAD
	git checkout -f

# Fix local folder permission
perms:
	chmod 755 .

# Deploy code pushed on remote host
deploy: perms reset submodules
	drush cache-rebuild
	drush config-import -y

sync_files_from_development:
	rsync -avz --delete $(DEVELOPMENT)/sql/dumps/ sql/dumps/
	rsync -avz --delete $(DEVELOPMENT)/files/     files/

sync_files_from_production:
	rsync -avz --delete $(PRODUCTION)/sql/dumps/ sql/dumps/
	rsync -avz --delete $(PRODUCTION)/files/     files/