-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
248 lines (204 loc) · 8.48 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
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
# Grab environment information (OSX vs Linux)
UNAME := $(shell uname)
DOCKER_COMPOSE_FILE := docker-compose.yml
export PROJECT := $(shell basename $(CURDIR))
export IMAGE_MAINTAINER := $(shell grep '^IMAGE_MAINTAINER' ./environment | sed 's/^.*=//g')
LABLE_BASE := ${IMAGE_MAINTAINER}/${PROJECT}
ifeq ($(UNAME), Linux)
DOCKER_COMPOSE_FILE += -f docker-compose.linux.yml
endif
INCLUDE_MAKEFILES=
# This should always be the first target so that we know running make without any
# arguments is going to be nondestructive. The @ is to silence the normal make
# behavior of echo'ing commands before running them.
help: # Show this help
@echo "Please specify a target. See README for information about targets."
@echo ""
@cat Makefile ${INCLUDE_MAKEFILES} | \
grep -E '^[a-zA-Z_-]+:.*?#' | \
sed 's/:.*# /,/' | \
sort | \
sed 's/^/\o033[32m/' | # Start Green color on first column \
sed 's/,/\o033[0m,/' | # End Green color on first colum \
column -N "Target,Description" -t -s ","
@echo ""
@echo "Example Usage"
@echo "make <target>"
@echo "make clear-cache"
include ${INCLUDE_MAKEFILES}
##
# Core commands
# The following commands are the basis of the development infrastructure.
##
init: composer-install docker-rebuild wait-healthy import-init config-import fix-permissions clear-cache docker-status # Build environment
safe-update: docker-stop composer-install docker-rebuild wait-healthy clear-cache # Update without importing config
# Use this if you would like a target to require that the project containers
# are running before executing the target contents. Note this doesn't test if
# the containers are healthy.
docker-running:
@docker inspect -f '{{.State.Running}}' ${PROJECT}-{db,php,web} &>/dev/null \
|| (echo "Containers are not running" && exit 1)
wait-healthy:
@echo "Wait for all containers to become healthy"
@python $(CURDIR)/scripts/docker-compose-wait.py
docker-rebuild: # Update docker images if there have been changes to Dockerfiles
docker-compose -f ${DOCKER_COMPOSE_FILE} up -d --build
docker-compose -f ${DOCKER_COMPOSE_FILE} ps
status: docker-status # Alias to docker-status
docker-status: # Display status of containers related to this project
docker-compose -f ${DOCKER_COMPOSE_FILE} ps
start: docker-start # Alias to docker-start
docker-start: # Start containers for this project
docker-compose -f ${DOCKER_COMPOSE_FILE} up -d
docker-compose -f ${DOCKER_COMPOSE_FILE} ps
stop: docker-stop # Alias to docker-stop
docker-stop: # Stop containers for this project
docker-compose -f ${DOCKER_COMPOSE_FILE} down
restart: docker-restart # Alias to docker-restart
docker-restart: docker-stop docker-start # Restart containers for this project
composer-install: # Installs Composer packages from composer.lock file
$(CURDIR)/bin/composer install \
--ignore-platform-reqs \
--no-interaction \
--no-progress
composer-update: # Update all composer managed libraries
$(CURDIR)/bin/composer update \
--ignore-platform-reqs
composer-update-lock:
$(CURDIR)/bin/composer update \
--lock
drupal-upgrade: # Update Drupal Core
$(CURDIR)/bin/composer update drupal/core \
--with-all-dependencies \
--ignore-platform-reqs
destroy: composer-purge docker-destroy # Take down and remove all data related to this project's current state
docker-destroy:
docker-compose -f ${DOCKER_COMPOSE_FILE} down -v
composer-purge:
$(CURDIR)/bin/host-tool \
rm -rf webroot/core/*
$(CURDIR)/bin/host-tool \
rm -rf webroot/libraries/*
$(CURDIR)/bin/host-tool \
rm -rf webroot/modules/contrib/*
$(CURDIR)/bin/host-tool \
rm -rf webroot/profiles/contrib/*
$(CURDIR)/bin/host-tool \
rm -rf webroot/themes/contrib/*
$(CURDIR)/bin/host-tool \
rm -rf vendor/*
clean: destroy # Removes all artifacts built via make or docker
@echo "Removing production tarball"
rm $(CURDIR)/${PROJECT}-prod.tar || true
@echo "Removing docker images"
docker rmi ${LABLE_BASE}{,-prod}-{db,php,web}:latest \
|| true
rebuild: destroy init # Destroy and rebuild the environment
fix-permissions: # Fix issues with permissions by taking ownership of all files
$(CURDIR)/bin/host-tool \
chown $(shell id -u) ./
$(CURDIR)/bin/host-tool \
chmod u=rwx,g=rwxs,o=rx ./
$(CURDIR)/bin/host-tool \
find ./ -not -path "webroot/sites/default/files*" -exec chown $(shell id -u) {} \;
$(CURDIR)/bin/host-tool \
find ./ -not -path "webroot/sites/default/files*" -exec chmod u=rwX,g=rwX,o=rX {} \;
$(CURDIR)/bin/host-tool \
find ./ -type d -not -path "webroot/sites/default/files*" -exec chmod g+s {} \;
$(CURDIR)/bin/host-tool \
chmod -R u=rwx,g=rwxs,o=rwx ./webroot/sites/default/files
export-prod: # Export production tarball
docker build \
--target php-prod \
-t ${LABLE_BASE}-prod-php:latest \
-f docker-src/cms/Dockerfile .
docker build \
--target web-prod \
-t ${LABLE_BASE}-prod-web:latest \
-f docker-src/cms/Dockerfile .
docker build \
-t ${LABLE_BASE}-prod-db:latest \
docker-src/db
docker save \
-o ${PROJECT}-prod.tar \
${LABLE_BASE}-{php,web,db}:latest \
memcached:1.5-alpine
import-db: # Import a db
cat $(filter-out $@,$(MAKECMDGOALS)) | bin/drush sqlc
import-init: #Import Database on init
cat ./databaseBackup/govcon-2018-drupal.sql | bin/drush sqlc
export-db: # Export a db tp ./backupDatabase
bin/drush sql-dump > ./databaseBackup/${PROJECT}.sql
##
# Drupal specific commands
# The following commands are used to strap and control Drupal.
##
init-drupal: drupal-install config-init config-import clear-cache
update: docker-stop composer-install docker-rebuild config-import clear-cache # Run the 'rebuild' task then import configuration and clear Drupal's cache
drupal-install: docker-running
$(CURDIR)/bin/drush \
site-install minimal \
-vv \
--yes \
--account-name=admin \
--account-pass=admin \
install_configure_form.enable_update_status_module=NULL \
install_configure_form.enable_update_status_emails=NULL
$(CURDIR)/bin/tool chmod 777 /var/www/webroot/sites/default/files
config-init: docker-running
@if [ -e ./config/system.site.yml ]; then \
echo "Config found. Processing setting uuid..."; \
cat ./config/system.site.yml | \
grep uuid | tail -c +7 | head -c 36 | \
$(CURDIR)/bin/drush config-set -y system.site uuid - ;\
else \
echo "Config is empty. Skipping uuid init..."; \
fi;
config-import: docker-running
@if [ -e ./config/system.site.yml ]; then \
echo "Config found. Importing config..."; \
$(CURDIR)/bin/drush config-import sync --yes ;\
$(CURDIR)/bin/drush config-import sync --yes ;\
else \
echo "Config is empty. Skipping import..."; \
fi;
config-export: docker-running
$(CURDIR)/bin/drush config-export sync --yes
config-validate: docker-running
$(CURDIR)/bin/drush config-export sync --no
config-refresh: config-init config-import
clear-cache: docker-running # Clear Drupal cache
$(CURDIR)/bin/drush cr
##
# Development commands
# The following commands are used for development purposes.
##
lint: # Check code for formatting or syntax errors
$(CURDIR)/bin/tool parallel-lint \
-e php,module,inc,install,test,profile,theme \
/var/www/drupal/modules/custom \
/var/www/drupal/themes/custom
sniff: # Drupal standards checking
$(CURDIR)/bin/tool phpcs --config-set installed_paths vendor/drupal/coder/coder_sniffer
$(CURDIR)/bin/tool phpcs -n --standard=Drupal,DrupalPractice \
--extensions=php,module,inc,install,test,profile,theme,info \
web/modules/custom web/themes/custom
code-test: lint sniff # Executes PHP linting and Drupal standards checking
code-fix: # Fix minor errors using Drupal standards
$(CURDIR)/bin/tool phpcs --config-set installed_paths vendor/drupal/coder/coder_sniffer
-$(CURDIR)/bin/tool phpcbf --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,info web/modules/custom
-$(CURDIR)/bin/tool phpcbf --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,info web/themes/custom
##
# Removes "No rule to make target" message which allows us to pass an argument
# without having to specify the name when running the make command.
#
# https://stackoverflow.com/questions/6273608/how-to-pass-argument-to-makefile-from-command-line/6273809
#
# Please see the shell or logs targets below for an example.
##
%:
@:
shell: # This command will open a shell in the specified container as root. Usage: make shell <container type>
docker exec -it --user root ${PROJECT}-$(filter-out $@,$(MAKECMDGOALS)) /bin/sh
logs: # This command will watch the logs in the specified container. Usage: make logs <container type>
docker logs -f ${PROJECT}-$(filter-out $@,$(MAKECMDGOALS))