forked from dpc-sdp/tide_landing_page
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
219 lines (182 loc) · 8.22 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
##
# Build project dependncies.
#
# Usage:
# make <target>
#
# make help - show a list of available targets.
# make build - build project
#
include .env
-include .env.local
.DEFAULT_GOAL := help
.PHONY: build clean clean-full docker-cli docker-destroy docker-restart docker-start docker-stop help install install-site install-module lint rebuild rebuild-full test-behat update-fixtures
.EXPORT_ALL_VARIABLES: ;
## Build project.
build:
$(call title,Building project)
$(call exec,$(MAKE) docker-start)
$(call exec,$(MAKE) install)
$(call exec,$(MAKE) install-site)
$(call exec,$(MAKE) install-module)
@echo ''
$(call title,Build complete)
## Remove dependencies.
clean:
$(call title,Removing dependencies)
$(call exec,[ -d $(WEBROOT)/sites/default ] && chmod -Rf 777 $(WEBROOT)/sites/default||true)
$(call exec,git ls-files --directory --other -i --exclude-from=.gitignore | xargs rm -Rf)
## Remove dependencies and Docker images.
clean-full: docker-stop docker-destroy clean
## Destroy Docker containers.
docker-destroy:
$(call title,Destroying Dockert containers)
$(call exec,docker-compose down)
## Re-start Docker containers.
docker-restart:
$(call title,Restarting Docker containers)
$(call exec,docker-compose restart)
## Start Docker containers.
docker-start:
$(call title,Starting Docker containers)
$(call exec,COMPOSE_CONVERT_WINDOWS_PATHS=1 docker-compose up -d $(filter-out $@,$(MAKECMDGOALS)))
$(call exec,if docker-compose logs |grep "\[Error\]"; then exit 1; fi)
@docker ps -a --filter name=^/$(COMPOSE_PROJECT_NAME)_
## Stop Docker containers.
docker-stop:
$(call title,Stopping Docker containers)
$(call exec,docker-compose stop $(filter-out $@,$(MAKECMDGOALS)))
## Run Drush command.
drush:
$(call title,Executing Drush command inside CLI container)
$(call exec,docker-compose exec cli drush -r $(APP)/$(WEBROOT) $(filter-out $@,$(MAKECMDGOALS)))
## Display this help message.
help:
@echo ''
@echo 'Usage:'
@echo ' ${YELLOW}make${RESET} ${GREEN}<target>${RESET}'
@echo ''
@echo 'Targets:'
@awk '/^[a-zA-Z\-0-9][a-zA-Z\-\_0-9]+:/ { \
helpMessage = match(lastLine, /^## (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
printf " ${YELLOW}%-$(HELP_TARGET_WIDTH)s${RESET} ${GREEN}%s${RESET}\n", helpCommand, helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)
## Install dependencies
install:
$(call title,Installing dependencies)
$(call exec,docker-compose exec cli apk add --update make jq)
# Download development config from Tide profile repository.
$(call exec,docker-compose exec cli bash -c "curl -L --header 'Accept: application/vnd.github.v3.raw' --header 'User-Agent: dpc-sdp/tide curl v7.47.0' $(COMPOSER_DEV_URL) > $(APP)/composer.dev.json")
# Clear composer caches
$(call exec,docker-compose exec cli bash -c "composer clearcache")
# Merge module's and development composer configs.
$(call exec,docker-compose exec cli bash -c "jq --indent 4 -M -s '.[0] * .[1]' $(APP)/composer.json $(APP)/composer.dev.json > $(COMPOSER_BUILD)")
$(call exec,docker-compose exec cli bash -c "COMPOSER=$(COMPOSER_BUILD) composer install -n --ansi --prefer-dist --no-suggest")
## Install current module.
install-module:
# Clear Caches.
$(call exec,docker-compose exec cli composer clearcache)
$(call exec,docker-compose exec cli drush cr)
$(call title,Installing current module and dependencies)
# If running with suggested modules, requre them first.
$(call exec,docker-compose exec cli bash -c "if [ "$(INSTALL_SUGGEST)" = "1" ] ; then cat $(COMPOSER_BUILD) | jq -r 'select(.suggest != null) | .suggest | keys[]' | xargs -i composer require {}; fi")
# Copy module code into local vendor directory.
$(call exec,docker-compose exec cli rm -Rf $(APP)/vendor-local/$(MODULE_NAME))
$(call exec,docker-compose exec cli mkdir -p $(APP)/vendor-local/$(MODULE_NAME))
$(call exec,docker-compose exec cli bash -c "git ls-tree HEAD --name-only|xargs -I '{}' cp -R '{}' $(APP)/vendor-local/$(MODULE_NAME)/")
# Add local module repository.
$(call exec,docker-compose exec cli bash -c "COMPOSER=$(COMPOSER_BUILD) composer config repositories.dpc-sdp/$(MODULE_NAME) path vendor-local/$(MODULE_NAME)")
# Require module from local repository.
$(call exec,docker-compose exec cli bash -c "COMPOSER=$(COMPOSER_BUILD) composer require dpc-sdp/$(MODULE_NAME)")
# If running with suggested modules, install them first.
$(call exec,docker-compose exec cli bash -c "if [ "$(INSTALL_SUGGEST)" = "1" ] ; then cat $(COMPOSER_BUILD) | jq -r 'select(.suggest != null) | .suggest | keys[]' | sed 's/dpc-sdp\///' | xargs -i drush -r $(APP)/$(WEBROOT) en -y {}; fi")
# Enable current module.
$(call exec,docker-compose exec cli drush -r $(APP)/$(WEBROOT) en -y $(MODULE_NAME))
## Install site.
install-site:
$(call title,Installing a site)
$(call exec,docker-compose exec cli drush -r $(APP)/$(WEBROOT) si testing -y --db-url=mysql://drupal:drupal@$(MYSQL_HOST)/drupal --account-name=admin --account-pass=admin install_configure_form.enable_update_status_module=NULL install_configure_form.enable_update_status_emails=NULL)
$(call exec,docker-compose exec cli bash -c "COMPOSER=$(COMPOSER_BUILD) composer --working-dir=$(APP)/$(BUILD) drupal-post-install")
## Lint code.
lint:
$(call title,Linting code)
$(call exec,docker-compose exec cli vendor/bin/parallel-lint --exclude vendor $(PHP_LINT_EXCLUDES) -e $(PHP_LINT_EXTENSIONS) $(PHP_LINT_TARGETS))
$(call exec,docker-compose exec cli vendor/bin/phpcs $(PHPCS_TARGETS))
update-fixtures:
$(call title,Updating fixture files for Drupal $(DRUPAL_VERSION))
$(call exec,rsync -av --delete --no-progress --exclude-from=$(BUILD)/.rsync-exclude $(BUILD)/ $(FIXTURES)/d$(DRUPAL_VERSION)/)
## Re-build project dependencies.
rebuild: clean build
## Clean and fully re-build project dependencies.
rebuild-full: clean-full build
## Run Behat tests.
test-behat:
$(call title,Running behat tests)
$(call exec,docker-compose exec cli vendor/bin/behat --format=progress_fail --strict --colors $(BEHAT_PROFILE) $(filter-out $@,$(MAKECMDGOALS)))
#-------------------------------------------------------------------------------
# VARIABLES.
#-------------------------------------------------------------------------------
COMPOSE_PROJECT_NAME ?= app
APP ?= /app
WEBROOT ?= build/docroot
BUILD ?= build
FIXTURES ?= tests/behat/fixtures
URL ?= http://$(MODULE_NAME).docker.amazee.io/
DRUPAL_VERSION ?= 8
MODULES_PATH ?= modules
INSTALL_SUGGEST ?= 0
MYSQL_HOST ?= mariadb
MYSQL_PORT ?= 3306
PHP_LINT_EXTENSIONS ?= php,inc,module,theme,install
PHP_LINT_TARGETS ?= ./
PHP_LINT_TARGETS := $(subst $\",,$(PHP_LINT_TARGETS))
PHP_LINT_EXCLUDES ?= --exclude vendor --exclude node_modules --exclude build
PHP_LINT_EXCLUDES := $(subst $\",,$(PHP_LINT_EXCLUDES))
PHPCS_TARGETS := $(subst $\",,$(PHPCS_TARGETS))
# Path to a file with additional sanitization commands.
DB_SANITIZE_SQL ?= .dev/sanitize.sql
# Prefix of the Docker images.
DOCKER_IMAGE_PREFIX ?= amazeeio
# GitHub token to not be limited by API calls.
GITHUB_TOKEN ?= ""
# GitHub token to allow access to private repos to download files.
# This is NOT the same token as above! It has a larger security scope and should
# be used with caution. It will be removed once project go open-source.
GITHUB_PRIVATE_TOKEN ?= ""
# Override composer configuration file with the one used for build.
COMPOSER_BUILD ?= $(APP)/composer.build.json
# URL of the development Composer configuration file.
COMPOSER_DEV_URL ?= file:///composer.dev.json
# Width of the target column in help target.
HELP_TARGET_WIDTH = 20
# Print verbose messages.
VERBOSE ?= 1
# Colors for output text.
GREEN := $(shell tput -Txterm setaf 2)
YELLOW := $(shell tput -Txterm setaf 3)
WHITE := $(shell tput -Txterm setaf 7)
RESET := $(shell tput -Txterm sgr0)
#-------------------------------------------------------------------------------
# FUNCTIONS.
#-------------------------------------------------------------------------------
##
# Execute command and display executed command to user.
#
define exec
@printf "$$ ${YELLOW}${subst ",',${1}}${RESET}\n" && $1
endef
##
# Display the target title to user.
#
define title
$(if $(VERBOSE),@printf "${GREEN}==> ${1}...${RESET}\n")
endef
# Pass arguments from CLI to commands.
# @see https://stackoverflow.com/a/6273809/1826109
%:
@: