aboutsummaryrefslogtreecommitdiff
path: root/share/templater/drupal8/files/Makefile.drupal8
blob: 55375a5a64447e56a927c6fd93991076f94b7489 (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
#
# Makefile for a Drupal 8 Website
#

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

# Include local customizations/overrides, which might be .gitignore'd
# See https://www.gnu.org/software/make/manual/html_node/Include.html
#-include Makefile.local

# 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
	#vagrant ssh -c "$(DRUSH) pm-enable devel -y"
	echo '( cd /srv/kvmx && make drush )' | kvmx ssh
	#kvmx    ssh    "$(DRUSH) pm-enable devel -y"

# 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

# Setup the virtual machine using kvmx
kvmx:
	kvmx provision

# 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

# Load the database dump, clear the drupal cache and fix image paths
# See https://www.drupal.org/node/628130
initdb:
	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
dumpdb:
	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:
	echo "DROP DATABASE $(PROJECT); CREATE DATABASE $(PROJECT);" | $(DRUSH) sql-cli

# Reinitializes the database
reinitdb: destroydb initdb

# Cleanup develop environment
clean:
	vagrant halt
	vagrant destroy -f
	kvmx stop
	kvmx destroy
	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:
	$(DRUSH) up

# Upgrade drupal
upgrade-drupal:
	BASE=$(DESTDIR) 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