mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-05-07 03:29:19 +02:00
The default cache directory for the file-based rate limiter was src/cache/rate_limit/, placing transient JSON files inside the source tree. This meant: - The directory was deployed via rsync on every deploy (wasted I/O) - .gitignore had to track a src/-internal path - Developers running tests could leave stale cache state in the source tree Changes: - src/RateLimit.php: default $cacheDir changed from __DIR__.'/cache/rate_limit' to dirname(__DIR__).'/storage/cache/rate_limit'; dirname(__DIR__) resolves to the project root regardless of how the file is loaded (with or without bootstrap) - .gitignore: replaced 'src/cache/rate_limit/' with 'storage/cache/' (broader, covers any future cache subdirs under storage/) - storage/cache/.gitkeep: added so the directory is tracked in VCS and created on fresh clones/deploys, but its contents are ignored - justfile: added '--exclude storage/cache/*' to the deploy rsync recipe so rate-limit state is never transferred to the server - src/cache/: removed (no longer needed) All RateLimit unit tests pass.
167 lines
4.8 KiB
Makefile
167 lines
4.8 KiB
Makefile
# Post-ERG Justfile
|
|
|
|
default:
|
|
@just --list
|
|
|
|
# ============================================================================
|
|
# Development
|
|
# ============================================================================
|
|
|
|
[group('dev')]
|
|
setup:
|
|
@bash scripts/setup-dev.sh
|
|
|
|
[group('dev')]
|
|
serve: migrate
|
|
@php -S 127.0.0.1:8000 -t public/
|
|
|
|
[group('dev')]
|
|
stop:
|
|
@pkill -f "php -S 127.0.0.1:8000" 2>/dev/null && echo "stopped" || echo "no server running"
|
|
|
|
[group('dev')]
|
|
logs:
|
|
@tail -n 20 error.log 2>/dev/null || echo "no error log"
|
|
|
|
# ============================================================================
|
|
# Deploy
|
|
# ============================================================================
|
|
|
|
[group('deploy')]
|
|
deploy:
|
|
rsync -vur --progress \
|
|
--chown="www-data:posterg" \
|
|
--exclude 'vendor' \
|
|
--exclude 'tests' \
|
|
--exclude 'test.db' \
|
|
--exclude '*.md' \
|
|
--exclude '.git*' \
|
|
--exclude '.jj' \
|
|
--exclude '.claude' \
|
|
--exclude '.pi' \
|
|
--exclude '.DS_Store' \
|
|
--exclude 'storage/backup_*' \
|
|
--exclude 'storage/cache/*' \
|
|
--exclude 'storage/fixtures' \
|
|
--exclude 'storage/docs' \
|
|
--exclude 'nginx' \
|
|
--exclude 'docs' \
|
|
--exclude 'justfile*' \
|
|
--exclude 'scripts' \
|
|
--exclude 'var/cache/*' \
|
|
--exclude 'var/logs/*' \
|
|
./ posterg:/var/www/posterg/
|
|
ssh posterg "mkdir -p /var/www/posterg/var/{cache,logs,tmp}"
|
|
|
|
[group('deploy')]
|
|
setup-server:
|
|
rsync -v scripts/setup-server.sh posterg:/tmp/setup-server.sh
|
|
@echo ""
|
|
@echo "Script uploaded. SSH into the server and run:"
|
|
@echo ""
|
|
@echo " sudo DEPLOY_USER=\$USER bash /tmp/setup-server.sh"
|
|
@echo ""
|
|
|
|
[group('deploy')]
|
|
deploy-nginx:
|
|
rsync -v nginx/posterg.conf posterg:/tmp/posterg.conf
|
|
rsync -v scripts/deploy-server.sh posterg:/tmp/deploy-server.sh
|
|
@echo ""
|
|
@echo "Files uploaded. SSH into the server and run:"
|
|
@echo ""
|
|
@echo " sudo bash /tmp/deploy-server.sh"
|
|
@echo " sudo systemctl reload nginx"
|
|
@echo ""
|
|
|
|
[group('deploy')]
|
|
deploy-db:
|
|
@ssh posterg '[ ! -f /var/www/posterg/storage/test.db ]' || (echo "ERROR: remote database already exists. Remove it manually if you intend to overwrite." && exit 1)
|
|
rsync -v --progress ./storage/test.db posterg:/var/www/posterg/storage/test.db
|
|
ssh posterg "chown www-data:posterg /var/www/posterg/storage/test.db && chmod 660 /var/www/posterg/storage/test.db"
|
|
|
|
# ============================================================================
|
|
# Testing
|
|
# ============================================================================
|
|
|
|
[group('test')]
|
|
test:
|
|
@DB_ENV=test php tests/run-tests.php
|
|
|
|
[group('test')]
|
|
test-unit:
|
|
@DB_ENV=test php tests/Unit/DatabaseTest.php
|
|
@DB_ENV=test php tests/Unit/RateLimitTest.php
|
|
|
|
[group('test')]
|
|
test-integration:
|
|
@DB_ENV=test php tests/Integration/SearchTest.php
|
|
|
|
[group('test')]
|
|
test-security:
|
|
@DB_ENV=test php tests/Security/SecurityTest.php
|
|
|
|
[group('test')]
|
|
syntax:
|
|
@find . -maxdepth 1 -name "*.php" -not -path "./vendor/*" -exec php -l {} \; | grep -v "No syntax errors"
|
|
@find admin/ -name "*.php" -exec php -l {} \; 2>/dev/null | grep -v "No syntax errors" || true
|
|
@find src/ -name "*.php" -exec php -l {} \; | grep -v "No syntax errors"
|
|
@echo "✅ Syntax OK"
|
|
|
|
# ============================================================================
|
|
# Database
|
|
# ============================================================================
|
|
|
|
[group('database')]
|
|
migrate:
|
|
@echo "Running migrations…"
|
|
@bash scripts/migrate.sh both
|
|
|
|
[group('database')]
|
|
migrate-test:
|
|
@bash scripts/migrate.sh test
|
|
|
|
[group('database')]
|
|
migrate-prod:
|
|
@bash scripts/migrate.sh prod
|
|
|
|
[group('database')]
|
|
init-db:
|
|
@sqlite3 storage/test.db < storage/schema.sql
|
|
@sqlite3 storage/test.db "SELECT COUNT(*) || ' tables' FROM sqlite_master WHERE type='table';"
|
|
|
|
[group('database')]
|
|
reset-db:
|
|
@rm -f storage/test.db
|
|
@just init-db
|
|
|
|
[group('database')]
|
|
query:
|
|
@sqlite3 storage/test.db
|
|
|
|
[group('database')]
|
|
show id:
|
|
@sqlite3 -column -header storage/test.db "SELECT * FROM v_theses_full WHERE id = {{id}};"
|
|
|
|
[group('database')]
|
|
backup:
|
|
@sqlite3 storage/test.db .dump > storage/backup_$(date +%Y%m%d_%H%M%S).sql
|
|
|
|
[group('database')]
|
|
fixtures:
|
|
@php storage/fixtures/CreateTestDatabase.php
|
|
|
|
# ============================================================================
|
|
# Utils
|
|
# ============================================================================
|
|
|
|
[group('utils')]
|
|
clean:
|
|
@rm -f error.log admin/error.log
|
|
@rm -rf src/cache/rate_limit/*
|
|
@rm -f /tmp/posterg-*.log /tmp/posterg-*.pid
|
|
|
|
[group('utils')]
|
|
setup-dirs:
|
|
@mkdir -p admin/data/{theses,covers,yaml} src/cache/rate_limit
|
|
@touch admin/data/theses/.gitkeep admin/data/covers/.gitkeep
|