aboutsummaryrefslogtreecommitdiff
path: root/share/templater/drupal-composer/files/Makefile.drupal-composer
blob: 451f4816e2e5d74d92c8c33076bc1159f77351d9 (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
#
# 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
CONTAINER   ?= kvmx
DATE         = $(shell date +%Y%m%d)

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

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

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

# Setup production environment
production: post_receive composer settings perms

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

# Setup virtual machine using kvmx
kvmx:
	@#kvmx up || true
	kvmx provision
	@#echo '( cd /srv/shared && make composer )' | kvmx ssh
	@#echo '( cd /srv/shared && make settings )' | 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 .
	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 submodules
	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/pristinet.sql.gz && gzip -dc sql/dumps/pristinet.sql.gz | $(DRUSH) sql-cli || true
	test -s sql/dumps/pristinet.sql.gz && $(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
	$(DRUSH) updatedb -y --entity-updates

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

# Upgrade drupal
upgrade-drupal: composer_update updatedb

# 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

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

# 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

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

# 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

# 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