-
Notifications
You must be signed in to change notification settings - Fork 14
/
.ahoy.yml
299 lines (252 loc) · 11.6 KB
/
.ahoy.yml
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
#
# Ahoy configuration file.
# http://www.ahoycli.com/
#
# Provides development experience shortcuts to work with the stack.
# Any command can be copy-pasted directly into terminal and ran without using
# Ahoy.
#
# Do not add values directly into this file. Use .env file instead.
# Run `ahoy up cli` to apply environment variables changes to containers.
---
ahoyapi: v2
commands:
build:
usage: Build or rebuild the project.
cmd: |
ahoy confirm "Running this command will remove your current database and files. Are you sure?" &&
./scripts/drevops/build.sh &&
ahoy info
info:
usage: Show information about this project.
cmd: |
COMPOSE_PROJECT_NAME=${COMPOSE_PROJECT_NAME:-${PWD##*/}} \
DREVOPS_HOST_DB_PORT=$(docker compose port mariadb 3306 2>/dev/null | cut -d : -f 2) \
DREVOPS_HOST_SOLR_PORT=$(docker compose port solr 8983 2>/dev/null | cut -d : -f 2) \
DREVOPS_HOST_HAS_SEQUELACE=$(uname -a | grep -i -q darwin && mdfind -name 'Sequel Ace' 2>/dev/null | grep -q "Ace" && echo 1 || true) \
DREVOPS_DRUPAL_SHOW_LOGIN_LINK=${DREVOPS_DRUPAL_SHOW_LOGIN_LINK} \
ahoy cli ./scripts/drevops/info.sh "$@"
db:
usage: Open DB in Sequel Ace.
cmd: |
uname -a | grep -i -q darwin && mdfind -name 'Sequel Ace' 2>/dev/null |grep -q "Ace" \
&& DREVOPS_HOST_DB_PORT="$(docker port $(docker compose ps -q mariadb 2>/dev/null) 3306 2>/dev/null | cut -d : -f 2)" \
&& open "mysql://${MARIADB_USERNAME:-drupal}:${MARIADB_PASSWORD:-drupal}@127.0.0.1:${DREVOPS_HOST_DB_PORT}/drupal" -a "Sequel Ace" \
|| echo "Not a supported OS or Sequel Ace is not installed."
# ----------------------------------------------------------------------------
# Docker commands.
# ----------------------------------------------------------------------------
up:
usage: Build and start Docker containers.
cmd: |
docker compose up -d "$@" && if docker compose logs | grep -q "\[Error\]"; then exit 1; fi
mkdir -p ${DREVOPS_WEBROOT}/sites/default/files && docker compose port cli 35729 | cut -d : -f 2 | xargs -I{} ahoy cli 'echo {} > /app/${DREVOPS_WEBROOT}/sites/default/files/livereload.sock'
down:
usage: Stop Docker containers and remove container, images, volumes and networks.
cmd: |
ahoy confirm "Running this command will remove your current database. Are you sure?" &&
if [ -f "docker-compose.yml" ]; then docker compose down --remove-orphans --volumes > /dev/null 2>&1; fi
start:
usage: Start existing Docker containers.
cmd: |
docker compose start "$@"
mkdir -p ${DREVOPS_WEBROOT}/sites/default/files && docker compose port cli 35729 | cut -d : -f 2 | xargs -I{} ahoy cli 'echo {} > /app/${DREVOPS_WEBROOT}/sites/default/files/livereload.sock'
stop:
usage: Stop running Docker containers.
cmd: docker compose stop "$@"
restart:
usage: Restart stopped or running Docker containers.
cmd: docker compose restart "$@"
logs:
usage: Show Docker logs for services.
cmd: docker compose logs "$@"
pull:
usage: Pull latest Docker images.
cmd: if [ ! -z "$(docker image ls -q)" ]; then docker image ls --format \"{{.Repository}}:{{.Tag}}\" | grep uselagoon/ | grep -v none | xargs -n1 docker pull -q | cat; fi
cli:
usage: Start a shell or run a command inside the CLI service container.
# This will drop into shell if no arguments are supplied to this command.
# If arguments supplied, a new shell with TERM, COMPOSE_*, GITHUB_*,
# DOCKER_*, DRUPAL_* and DREVOPS_* environment variables will be started.
# This allows passing of the environment variables to Ahoy commands which
# will then be forwarded to the container.
# Escape double quotes with \" (slash double-quote) when passing arguments
# with spaces.
cmd: if \[ "${#}" -ne 0 \]; then docker compose exec $(env | cut -f1 -d= | grep "TERM\|COMPOSE_\|GITHUB_\|DOCKER_\DRUPAL_\|DREVOPS_" | sed 's/^/-e /') -T cli bash -c "$*"; else docker compose exec cli bash; fi
composer:
usage: Run Composer commands in the CLI service container.
cmd: ahoy cli composer "$@"
drush:
usage: Run Drush commands in the CLI service container.
cmd: ahoy cli "drush -l \${DREVOPS_LOCALDEV_URL} $*"
flush-redis:
usage: Flush Redis cache.
cmd: docker compose exec redis redis-cli flushall
# ----------------------------------------------------------------------------
# Application commands.
# ----------------------------------------------------------------------------
login:
usage: Login to a website.
# Unblock user 1 and generate a one time login link.
cmd: ahoy cli ./scripts/drevops/login.sh
download-db:
usage: Download database.
cmd: ./scripts/drevops/download-db.sh
reload-db:
usage: Reload the database container using local database image.
cmd: |
ahoy confirm "Running this command will replace your current database. Are you sure?" &&
docker compose rm -f -s -v mariadb \
&& ahoy up -- --build mariadb \
&& ahoy up wait_dependencies \
&& sleep 15 \
&& ahoy provision \
&& ahoy info \
&& ahoy login
provision:
usage: Provision a site from the database dump or profile.
cmd: ahoy cli ./scripts/drevops/provision.sh
export-db:
usage: Export database dump or database image (if DREVOPS_DB_DOCKER_IMAGE variable is set).
cmd: ./scripts/drevops/export-db.sh "$@"
pull-db:
usage: Download database image with the latest nightly dump. Run "ahoy reload-db" to reload DB in the running stack.
cmd: |
[ -n "${DREVOPS_DB_DOCKER_IMAGE}" ] && docker pull $DREVOPS_DB_DOCKER_IMAGE
reset:
usage: "Remove containers, all build files. Use with `hard` to reset repository to the last commit."
cmd: |
ahoy confirm "All containers and build files will be removed. Proceed?" &&
AHOY_CONFIRM_RESPONSE=y ahoy down && ./scripts/drevops/reset.sh "$@"
fei:
usage: Install front-end assets.
cmd: ahoy cli "npm --prefix web/themes/contrib/${DRUPAL_THEME} install"
fe:
usage: Build front-end assets.
cmd: ahoy cli "cd web/themes/contrib/${DRUPAL_THEME} && npm run build"
lint:
usage: Lint back-end and front-end code.
cmd: ahoy lint-be && ahoy lint-fe
# Base theme has own tooling config files - use them with tools installed in
# the project root. This allows to lint base theme code without installing
# tools in the base theme directory. But it also allows to link the base theme
# when the theme is tested in isolated mode.
lint-be:
usage: Lint back-end code.
cmd: |
ahoy cli vendor/bin/phpcs
ahoy cli vendor/bin/phpstan
ahoy cli vendor/bin/rector process --dry-run --clear-cache
ahoy cli vendor/bin/phpmd . text phpmd.xml
lint-fe:
usage: Lint front-end code (NodeJS dependencies should already be installed).
cmd: |
ahoy cli "npm run --prefix \${DREVOPS_WEBROOT}/themes/contrib/\${DRUPAL_THEME} lint"
lint-config:
usage: Lint config
cmd: |
ahoy cli ./scripts/lint.theme-config.sh
ahoy cli "./vendor/bin/drush inspect_config civictheme.settings --detail --only-error"
lint-fix:
usage: Fix lint issues of back-end and front-end code.
cmd: |
ahoy cli vendor/bin/rector --clear-cache
ahoy cli vendor/bin/phpcbf
test:
usage: Run all tests.
cmd: ahoy test-unit && ahoy test-kernel && ahoy test-functional && ahoy test-bdd
test-unit:
usage: Run PhpUnit unit tests.
cmd: ahoy cli vendor/bin/phpunit --testsuite=unit "$@"
test-kernel:
usage: Run PhpUnit kernel tests.
cmd: ahoy cli vendor/bin/phpunit --testsuite=kernel "$@"
test-functional:
usage: Run PhpUnit functional tests.
cmd: ahoy cli vendor/bin/phpunit --testsuite=functional "$@"
test-bdd:
usage: Run BDD tests.
cmd: ahoy cli php -d memory_limit=-1 vendor/bin/behat --colors "$@"
test-bats:
usage: Run Bats tests (host only).
cmd: ./scripts/test.assets.sh
debug:
usage: Enable PHP Xdebug.
cmd: ahoy cli php -v | grep -q Xdebug || XDEBUG_ENABLE=true ahoy up cli php nginx && ahoy cli php -v | grep -q Xdebug && echo "Enabled debug configuration. Use 'ahoy up' to disable."
deploy:
usage: Run remote deployment procedures.
cmd: |
ahoy confirm "Deployment usually runs in CI. Are you sure you want to proceed with manual deployment? (Run as DREVOPS_DEPLOY_PROCEED=1 ahoy deploy [type1,[type2..]], where [type] is 'code', 'docker', 'webhook')" &&
./scripts/drevops/deploy.sh "$@"
github-labels:
usage: Update project's GitHub labels.
cmd: ./scripts/drevops/github-labels.sh "$@"
doctor:
usage: Find problems with current project setup.
cmd: ./scripts/drevops/doctor.sh "$@"
update-drevops:
usage: Update DrevOps stack.
cmd: |
ahoy confirm "Some committed files may become overwritten. Proceed?" &&
./scripts/drevops/update-drevops.sh $@
local:
usage: Custom local commands. See `ahoy local help`.
cmd: |
if [ -f .ahoy.local.yml ]; then
ahoy -f ".ahoy.local.yml" "$@"
else
echo ".ahoy.local.yml does not exist."
echo "Copy .ahoy.local.example.yml to .ahoy.local.yml and rerun this command.";
fi
export-config:
usage: Export theme config.
cmd: |
ahoy cli "./scripts/update.theme-config.sh"
ahoy drush cde civictheme_dev || true
if ahoy drush pm:list --status=Enabled --field=name | grep -q 'cs_generated_content'; then
ahoy drush cde cs_generated_content || true
fi
export-content:
usage: Export content (run with CIVICTHEME_CONTENT_PROFILE=corporate ahoy install-site) .
cmd: |
ahoy confirm "This will uninstall several modules and users. Proceed?" \
&& ahoy cli "CIVICTHEME_CONTENT_PROFILE=${CIVICTHEME_CONTENT_PROFILE:-default} ./scripts/update.default-content.sh" || echo "The operation was canceled."
# ----------------------------------------------------------------------------
# Utilities.
# ----------------------------------------------------------------------------
confirm:
cmd: |
if [ -z "$AHOY_CONFIRM_RESPONSE" ]; then
read -r -p ">> $1 [y/N] " AHOY_CONFIRM_RESPONSE
[ "$AHOY_CONFIRM_RESPONSE" = "y" ] || [ "$AHOY_CONFIRM_RESPONSE" = true ] || ( echo "The operation was canceled." && exit 1 )
else
echo ">> $1 [y/N] $AHOY_CONFIRM_RESPONSE" \
&& if [ "${AHOY_CONFIRM_WAIT_SKIP}" != "1" ]; then echo "Waiting for 3 seconds... Press Ctrl+C to cancel."; sleep 3; fi
fi
hide: true
# Override entrypoint to alter default behaviour of Ahoy.
entrypoint:
# Run all commands in Bash.
- bash
# Read the commands from the string.
- -c
# Exit the script if any statement returns a non-true return value.
- -e
# Read variables from .env file, respecting existing environment variable values.
#
# It is important to understand that variables set in .env file are already
# available inside the containers after stack is running (as a part of
# docker compose functionality), so most of the commands are using these
# values taken from containers.
#
# However, since Docker does not support changes to environment variables in
# running containers without restarting containers, we are adding this
# mechanism of reading variables here to allow adjustments of some variables
# (like PHPCS scan targets) without the need to restart containers.
#
# As a rule of thumb, use `ahoy up cli` to apply changes to variables.
- |
t=$(mktemp) && export -p > "$t" && set -a && . ./.env && if [ -f ./.env.local ];then . ./.env.local;fi && set +a && . "$t" && rm "$t" && unset t
bash -e -c "$0" "$@"
- '{{cmd}}'
- '{{name}}'