-
-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathexamples.ahoy.yml
More file actions
403 lines (355 loc) · 13.9 KB
/
examples.ahoy.yml
File metadata and controls
403 lines (355 loc) · 13.9 KB
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
# Ahoy Configuration Example
# ==========================
# This file demonstrates development workflows and Ahoy's powerful features.
# Includes examples for various development stacks - adapt to your project's needs.
# Copy this file to your project root as .ahoy.yml and customise it for your workflow.
ahoyapi: v2
# Global environment files (loaded in order, later files override earlier ones)
env:
- .env
- .env.local
# Optional - Custom usage description for your project
usage: "Development workflow commands for your project"
commands:
# =============================================================================
# DEVELOPMENT ENVIRONMENT
# =============================================================================
up:
usage: Start the development environment
aliases: ["start"]
cmd: |
echo "Starting development environment..."
docker compose up -d
echo "Environment ready! Visit http://localhost"
down:
usage: Stop the development environment
aliases: ["stop"]
cmd: |
ahoy confirm "This will stop all containers and may remove volumes. Continue?" || exit 0
echo "Stopping development environment..."
docker compose down
echo "Environment stopped"
restart:
usage: Restart the development environment
cmd: |
echo "Restarting development environment..."
ahoy down
ahoy up
status:
usage: Show status of all services
aliases: ["ps"]
cmd: |
echo "Service Status:"
docker compose ps
echo ""
echo "Available URLs:"
echo " App: http://localhost:3000"
echo " API: http://localhost:8080"
echo " Database: localhost:3306"
# =============================================================================
# DEVELOPMENT TOOLS
# =============================================================================
shell:
usage: "Open a shell in a container (default: app)"
aliases: ["sh", "bash"]
cmd: |
CONTAINER="${1:-app}"
echo "Opening shell in $CONTAINER container..."
docker compose exec "$CONTAINER" bash
logs:
usage: "Follow logs for a service (default: all services)"
cmd: |
if [ -z "$1" ]; then
echo "Following logs for all services (Ctrl+C to exit)..."
docker compose logs -f
else
echo "Following logs for $1 service (Ctrl+C to exit)..."
docker compose logs -f "$1"
fi
# =============================================================================
# PACKAGE MANAGEMENT
# =============================================================================
install:
usage: Install project dependencies
aliases: ["deps"]
cmd: |
echo "Installing dependencies..."
if [ -f "package.json" ]; then
echo "Installing Node.js dependencies..."
docker compose exec app npm install
fi
if [ -f "composer.json" ]; then
echo "Installing PHP dependencies..."
docker compose exec app composer install
fi
if [ -f "requirements.txt" ]; then
echo "Installing Python dependencies..."
docker compose exec app pip install -r requirements.txt
fi
echo "Dependencies installed"
# =============================================================================
# TESTING & QUALITY
# =============================================================================
test:
usage: Run the test suite
cmd: |
echo "Running tests..."
if [ -f "package.json" ]; then
docker compose exec app npm test
elif [ -f "composer.json" ]; then
docker compose exec app ./vendor/bin/phpunit
elif [ -f "pytest.ini" ] || [ -f "setup.cfg" ]; then
docker compose exec app pytest
fi
lint:
usage: Run code linting
cmd: |
echo "Running linting..."
if [ -f "package.json" ]; then
docker compose exec app npm run lint
elif [ -f "phpcs.xml" ] || [ -f "phpcs.xml.dist" ]; then
docker compose exec app ./vendor/bin/phpcs
elif [ -f ".flake8" ] || [ -f "setup.cfg" ]; then
docker compose exec app flake8
fi
# =============================================================================
# DATABASE OPERATIONS
# =============================================================================
db:
usage: Connect to the database
cmd: |
echo "Connecting to database..."
# Detect database type and connect appropriately
if [ "${DB_TYPE:-mysql}" = "postgres" ]; then
docker compose exec db psql -U "$DB_USER" -d "$DB_NAME"
else
docker compose exec db mysql -u"$DB_USER" -p"$DB_PASSWORD" "$DB_NAME"
fi
# =============================================================================
# DRUPAL-SPECIFIC EXAMPLES
# =============================================================================
drush:
usage: Run Drush commands in the CLI container
cmd: docker compose exec cli drush --root=/var/www/html/web "$@"
drupal:
usage: Run Drupal Console commands in the CLI container
cmd: docker compose exec cli drupal --root=/var/www/html/web "$@"
composer:
usage: Run Composer commands in the CLI container
cmd: docker compose exec cli composer "$@"
cr:
usage: Clear Drupal cache
aliases: ["cache-rebuild"]
cmd: docker compose exec cli drush --root=/var/www/html/web cache:rebuild
cex:
usage: Export Drupal configuration
aliases: ["config-export"]
cmd: docker compose exec cli drush --root=/var/www/html/web config:export
cim:
usage: Import Drupal configuration
aliases: ["config-import"]
cmd: |
ahoy confirm "This will import configuration and may overwrite existing settings. Continue?" || exit 0
docker compose exec cli drush --root=/var/www/html/web config:import
uli:
usage: Generate a one-time login link for user 1
cmd: |
echo "Generating login link..."
docker compose exec cli drush --root=/var/www/html/web user:login --uri=http://localhost
site-install:
usage: Install Drupal site from scratch
cmd: |
ahoy confirm "This will completely reinstall the Drupal site and destroy all existing data. Continue?" || exit 0
echo "Installing Drupal site..."
docker compose exec cli drush --root=/var/www/html/web site:install --yes --account-name=admin --account-pass=admin
echo "Site installed! Login with admin/admin"
# =============================================================================
# BUILD & DEPLOYMENT
# =============================================================================
build:
usage: Build the application
cmd: |
echo "Building application..."
if [ -f "package.json" ]; then
docker compose exec app npm run build
elif [ -f "Makefile" ]; then
docker compose exec app make build
elif [ -f "gulpfile.js" ]; then
docker compose exec app gulp build
fi
echo "Build complete!"
deploy:
usage: "Deploy to specified environment (staging|production)"
env: .env.deploy
cmd: |
set -euo pipefail
ENVIRONMENT="${1:-staging}"
if [ "$ENVIRONMENT" != "staging" ] && [ "$ENVIRONMENT" != "production" ]; then
echo "Invalid environment. Use: staging or production"
exit 1
fi
if [ "$ENVIRONMENT" = "production" ] && [ -t 0 ] && [ -z "$CI" ]; then
ahoy confirm "Deploying to PRODUCTION environment. This cannot be undone. Continue?" || exit 0
fi
echo "Deploying to $ENVIRONMENT..."
ahoy test
ahoy build
# Add your deployment commands here (rsync, git push, etc.)
echo "Deployed to $ENVIRONMENT!"
db:backup:
usage: Create a database backup
cmd: |
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="backup_${TIMESTAMP}.sql"
echo "Creating database backup: $BACKUP_FILE"
mkdir -p backups
if [ "${DB_TYPE:-mysql}" = "postgres" ]; then
docker compose exec db pg_dump -U "$DB_USER" "$DB_NAME" > "backups/$BACKUP_FILE"
else
docker compose exec db mysqldump -u"$DB_USER" -p"$DB_PASSWORD" "$DB_NAME" > "backups/$BACKUP_FILE"
fi
echo "Backup created: backups/$BACKUP_FILE"
db:import:
usage: "Import database from backup file"
cmd: |
if [ -z "$1" ]; then
echo "Please provide a backup file: ahoy db:import backup_20231201_120000.sql"
exit 1
fi
ahoy confirm "This will completely replace the current database with $1. All existing data will be lost. Continue?" || exit 0
echo "Importing database from $1..."
if [ "${DB_TYPE:-mysql}" = "postgres" ]; then
docker compose exec -T db psql -U "$DB_USER" -d "$DB_NAME" < "backups/$1"
else
docker compose exec -T db mysql -u"$DB_USER" -p"$DB_PASSWORD" "$DB_NAME" < "backups/$1"
fi
echo "Database import complete"
db:reset:
usage: Reset database to clean state
cmd: |
ahoy confirm "This will drop and recreate the database, destroying all data. Continue?" || exit 0
echo "Resetting database..."
if [ "${DB_TYPE:-mysql}" = "postgres" ]; then
docker compose exec db psql -U "$DB_USER" -c "DROP DATABASE IF EXISTS \"$DB_NAME\"; CREATE DATABASE \"$DB_NAME\";"
else
docker compose exec db mysql -u"$DB_USER" -p"$DB_PASSWORD" -e "DROP DATABASE IF EXISTS \`$DB_NAME\`; CREATE DATABASE \`$DB_NAME\`;"
fi
echo "Database reset complete"
# =============================================================================
# UTILITY COMMANDS
# =============================================================================
clean:
usage: Clean up development environment
cmd: |
ahoy confirm "This will remove all containers, unused images, and volumes. All data will be lost. Continue?" || exit 0
echo "Cleaning up development environment..."
docker compose down
docker system prune -f
docker volume prune -f
echo "Cleanup complete"
fresh:
usage: Fresh start - rebuild everything from scratch
cmd: |
ahoy confirm "This will completely destroy and rebuild the entire development environment. All data will be lost. Continue?" || exit 0
echo "Starting fresh rebuild..."
export AHOY_CONFIRM_RESPONSE=y && export AHOY_CONFIRM_WAIT_SKIP=1
ahoy clean
docker compose build --no-cache
ahoy up
ahoy install
echo "Fresh environment ready!"
urls:
usage: Show all available URLs and endpoints
cmd: |
echo "Available URLs:"
echo " Application: http://localhost:3000"
echo " API: http://localhost:8080"
echo " Database Admin: http://localhost:8081"
echo ""
echo "Useful commands:"
echo " View logs: ahoy logs"
echo " Run tests: ahoy test"
echo " Check status: ahoy status"
# =============================================================================
# ADVANCED EXAMPLES
# =============================================================================
release:
usage: "Create a new release (requires version number)"
cmd: |
set -euo pipefail
if [ -z "$1" ]; then
echo "Please provide a version number: ahoy release 1.2.3"
exit 1
fi
VERSION="$1"
echo "Creating release v$VERSION..."
# Run tests
echo "Running tests..."
ahoy test
# Build assets
echo "Building assets..."
ahoy build
# Create git tag
echo "Creating git tag..."
git add -A
git commit --allow-empty -m "Release v$VERSION"
git tag -a "v$VERSION" -m "Release version $VERSION"
git push origin main
git push origin "v$VERSION"
echo "Release v$VERSION created successfully!"
security:
usage: Run security audit and vulnerability scan
cmd: |
echo "Running security audit..."
if [ -f "package.json" ]; then
echo "Checking npm dependencies..."
docker compose exec app npm audit
fi
if [ -f "composer.json" ]; then
echo "Checking Composer dependencies..."
docker compose exec app composer audit
fi
if [ -f "requirements.txt" ]; then
echo "Checking Python dependencies..."
docker compose exec app pip check
fi
echo "Security audit complete"
# =============================================================================
# UTILITY COMMANDS
# =============================================================================
# Internal utility command to confirm actions before running them.
# This command helps prevent accidental execution of destructive operations.
#
# Usage: ahoy confirm "Your confirmation message here" || exit 0
#
# Features:
# - Interactive mode: Prompts user for y/N confirmation
# - Automated mode: Uses AHOY_CONFIRM_RESPONSE environment variable
# - CI-friendly: Set AHOY_CONFIRM_WAIT_SKIP=1 to skip delays
# - Chain-friendly: Can be used with other commands using environment variables
#
# Environment variables:
# - AHOY_CONFIRM_RESPONSE: Pre-set response ('y' or 'true' to proceed)
# - AHOY_CONFIRM_WAIT_SKIP: Set to '1' to skip the 3-second wait in automated mode
#
# Examples:
# Interactive: ahoy down (will prompt user)
# Automated: AHOY_CONFIRM_RESPONSE=y ahoy down (auto-confirms with 3s delay)
# CI mode: AHOY_CONFIRM_RESPONSE=y AHOY_CONFIRM_WAIT_SKIP=1 ahoy down (immediate)
confirm:
cmd: |
if [ -z "${AHOY_CONFIRM_RESPONSE}" ]; then
read -r -p ">> $1 [y/N] " AHOY_CONFIRM_RESPONSE
RESPONSE_LOWER=$(printf '%s' "${AHOY_CONFIRM_RESPONSE}" | tr '[:upper:]' '[:lower:]')
if [ "$RESPONSE_LOWER" != "y" ] && [ "$RESPONSE_LOWER" != "yes" ] && [ "$RESPONSE_LOWER" != "true" ]; then
echo "The operation was canceled."
exit 1
fi
else
if [ "${AHOY_CONFIRM_WAIT_SKIP}" != "1" ]; then
echo ">> $1 [y/N] ${AHOY_CONFIRM_RESPONSE}"
echo "Waiting for 3 seconds... Press Ctrl+C to cancel."
sleep 3
fi
fi
hide: true