mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-05-06 11:09:18 +02:00
Major refactor
- update the structure to have monolithic setup - updated deployments - added live-reloading for devops
This commit is contained in:
406
justfile
406
justfile
@@ -1,205 +1,299 @@
|
||||
# Post-ERG Justfile
|
||||
# Unified recipes for the complete site (public + admin)
|
||||
|
||||
# Default recipe - show available commands
|
||||
default:
|
||||
@just --list
|
||||
|
||||
# ============================================================================
|
||||
# Development Setup
|
||||
# ============================================================================
|
||||
|
||||
[group('dev')]
|
||||
setup:
|
||||
@echo "🛠️ Setting up development environment..."
|
||||
@bash setup-dev.sh
|
||||
|
||||
# ============================================================================
|
||||
# Development Server
|
||||
# ============================================================================
|
||||
|
||||
[group('dev')]
|
||||
serve:
|
||||
@echo "🚀 Starting Post-ERG development server"
|
||||
@echo "========================================"
|
||||
@echo ""
|
||||
@echo "📍 Public site: http://localhost:8000"
|
||||
@echo "📍 Admin panel: http://localhost:8000/admin/"
|
||||
@echo ""
|
||||
@if [ -d "vendor/php-live-reload" ]; then \
|
||||
echo "✨ Live reload enabled - browser auto-refreshes on file save!"; \
|
||||
else \
|
||||
echo "💡 Tip: Run 'just setup' to enable live reload"; \
|
||||
fi
|
||||
@echo ""
|
||||
@echo "Press Ctrl+C to stop"
|
||||
@echo ""
|
||||
@php -S 127.0.0.1:8000
|
||||
|
||||
[group('dev')]
|
||||
stop:
|
||||
@echo "🛑 Stopping development server..."
|
||||
@pkill -f "php -S 127.0.0.1:8000" 2>/dev/null && echo "✓ Server stopped" || echo "No server running"
|
||||
|
||||
[group('dev')]
|
||||
logs:
|
||||
@echo "📋 Development logs"
|
||||
@echo "==================="
|
||||
@echo ""
|
||||
@if [ -f error.log ]; then \
|
||||
echo "Application errors:"; \
|
||||
echo "------------------"; \
|
||||
tail -n 20 error.log; \
|
||||
else \
|
||||
echo "No error log found"; \
|
||||
fi
|
||||
|
||||
# ============================================================================
|
||||
# Deploy Group
|
||||
# ============================================================================
|
||||
# Note: Regular deploy recipes exclude test.db and all *.db files by default
|
||||
# Use test-deploy explicitly to deploy the test database
|
||||
|
||||
[group('deploy')]
|
||||
deploy-public:
|
||||
rsync -vur --progress --exclude 'test.db' --exclude '*.db' --exclude 'tests/' --exclude 'cache/' --exclude '*.md' --exclude 'run-tests.php' ./apps/public/ posterg:/var/www/html/
|
||||
rsync -vur --progress --exclude 'test.db' ./shared/ posterg:/var/www/html/shared/
|
||||
@echo "Fixing shared library paths for production..."
|
||||
ssh posterg "cd /var/www/html && find . -maxdepth 1 -name '*.php' -type f -exec sed -i \"s|__DIR__ \. '/\.\./\.\./shared/|__DIR__ . '/shared/|g\" {} \;"
|
||||
deploy:
|
||||
@echo "📤 Deploying Post-ERG complete site"
|
||||
@echo "===================================="
|
||||
@echo ""
|
||||
@echo "Deploying public site..."
|
||||
rsync -vur --progress \
|
||||
--exclude 'vendor' \
|
||||
--exclude 'tests' \
|
||||
--exclude 'test.db' \
|
||||
--exclude '*.db' \
|
||||
--exclude 'cache' \
|
||||
--exclude '*.md' \
|
||||
--exclude '.git*' \
|
||||
--exclude '.DS_Store' \
|
||||
--exclude 'admin' \
|
||||
--exclude 'database' \
|
||||
--exclude 'nginx' \
|
||||
--exclude 'docs' \
|
||||
--exclude 'justfile*' \
|
||||
--exclude 'migrate-structure.sh' \
|
||||
--exclude 'setup-dev.sh' \
|
||||
./ posterg:/var/www/html/
|
||||
@echo ""
|
||||
@echo "Deploying admin panel..."
|
||||
rsync -vur --progress \
|
||||
--exclude 'test.db' \
|
||||
--exclude '*.db' \
|
||||
--exclude 'cache' \
|
||||
--exclude '*.md' \
|
||||
./admin/ posterg:/var/www/html/admin/
|
||||
@echo ""
|
||||
@echo "Deploying shared libraries..."
|
||||
rsync -vur --progress --exclude 'test.db' ./lib/ posterg:/var/www/html/lib/
|
||||
@echo ""
|
||||
@echo "Fixing permissions..."
|
||||
ssh posterg "chgrp -R posterg /var/www/html/inc && chmod 755 /var/www/html/inc && chmod 644 /var/www/html/inc/*"
|
||||
@echo "✓ Deployment complete"
|
||||
|
||||
[group('deploy')]
|
||||
deploy-admin:
|
||||
rsync -vur --progress --exclude 'test.db' --exclude '*.db' --exclude 'cache/' --exclude '*.md' ./apps/admin/ posterg:/var/www/html/admin/
|
||||
rsync -vur --progress --exclude 'test.db' ./shared/ posterg:/var/www/html/shared/
|
||||
@echo "Fixing shared library paths for production (admin)..."
|
||||
ssh posterg "cd /var/www/html/formulaire && find . -maxdepth 1 -name '*.php' -type f -exec sed -i \"s|__DIR__ \. '/\.\./\.\./shared/|__DIR__ . '/../shared/|g\" {} \;"
|
||||
@echo "✓ Admin paths fixed"
|
||||
|
||||
[group('deploy')]
|
||||
deploy: deploy-public deploy-admin
|
||||
ssh posterg "chgrp -R posterg /var/www/html/inc /var/www/html/lib && \
|
||||
chmod 755 /var/www/html/inc && chmod 644 /var/www/html/inc/* && \
|
||||
find /var/www/html/lib -type d -exec chmod 755 {} \; && \
|
||||
find /var/www/html/lib -type f -exec chmod 644 {} \;"
|
||||
@echo ""
|
||||
@echo "✅ Deployment complete (test.db excluded)"
|
||||
@echo "To deploy test database, run: just test-deploy"
|
||||
|
||||
[group('deploy')]
|
||||
deploy-database:
|
||||
@echo "Deploying database directory (excludes test.db by default)..."
|
||||
rsync -vur --progress --exclude 'test.db' --exclude '*.db-journal' ./database/ posterg:/var/www/html/database/
|
||||
@echo "✅ Database directory deployed (schema, fixtures, docs only)"
|
||||
|
||||
[group('deploy')]
|
||||
test-deploy:
|
||||
@echo "⚠️ Deploying test database (will overwrite remote test.db)"
|
||||
@echo "Creating database directory if needed..."
|
||||
ssh posterg "mkdir -p /var/www/html/database"
|
||||
rsync -vur --progress ./database/test.db posterg:/var/www/html/database/test.db
|
||||
@echo "Setting correct permissions..."
|
||||
ssh posterg "chgrp posterg /var/www/html/database /var/www/html/database/test.db && chmod 775 /var/www/html/database && chmod 660 /var/www/html/database/test.db"
|
||||
@echo "✅ Test database deployed and configured"
|
||||
|
||||
[group('deploy')]
|
||||
deploy-nginx:
|
||||
@echo "🚀 Deploying production nginx configuration..."
|
||||
rsync -vur --progress ./nginx/posterg.conf posterg:/tmp/posterg.conf
|
||||
rsync -vur --progress ./nginx/deploy-production.sh posterg:/tmp/deploy-production.sh
|
||||
@echo "✅ Files uploaded to server"
|
||||
@echo "✅ Deployment complete!"
|
||||
@echo ""
|
||||
@echo "Next steps on the server:"
|
||||
@echo " ssh posterg"
|
||||
@echo " sudo bash /tmp/deploy-production.sh"
|
||||
@echo ""
|
||||
@echo "This will:"
|
||||
@echo " • Fix file permissions (posterg group)"
|
||||
@echo " • Install nginx configuration"
|
||||
@echo " • Set up admin password (if needed)"
|
||||
@echo " • Test and reload nginx"
|
||||
|
||||
[group('deploy')]
|
||||
deploy-admin-tools:
|
||||
@echo "📤 Uploading admin user management tools..."
|
||||
rsync -vur --progress ./nginx/manage-admin-users.sh posterg:/tmp/manage-admin-users.sh
|
||||
@echo "✅ Script uploaded"
|
||||
@echo ""
|
||||
@echo "To manage admin users on the server:"
|
||||
@echo " ssh posterg"
|
||||
@echo " sudo bash /tmp/manage-admin-users.sh"
|
||||
@echo "🔍 Verify deployment:"
|
||||
@echo " • Public: https://posterg.erg.be/"
|
||||
@echo " • Admin: https://posterg.erg.be/admin/"
|
||||
|
||||
# ============================================================================
|
||||
# Public Site Development
|
||||
# Testing
|
||||
# ============================================================================
|
||||
|
||||
[group('public-dev')]
|
||||
serve-public:
|
||||
@echo "Starting public site on http://localhost:8002"
|
||||
@echo "Press Ctrl+C to stop"
|
||||
@cd apps/public && php -S 127.0.0.1:8002
|
||||
[group('test')]
|
||||
test:
|
||||
@echo "🧪 Running Post-ERG Test Suite"
|
||||
@echo "==============================="
|
||||
@echo ""
|
||||
@php tests/run-tests.php
|
||||
|
||||
[group('public-dev')]
|
||||
test-public:
|
||||
@echo "Testing public site..."
|
||||
@cd apps/public && php test_db.php
|
||||
[group('test')]
|
||||
test-unit:
|
||||
@echo "🧪 Unit Tests"
|
||||
@echo "============="
|
||||
@php tests/Unit/DatabaseTest.php
|
||||
@echo ""
|
||||
@php tests/Unit/RateLimitTest.php
|
||||
|
||||
[group('public-dev')]
|
||||
test-public-all:
|
||||
@echo "Running all public site tests..."
|
||||
@cd apps/public && php run-tests.php
|
||||
[group('test')]
|
||||
test-integration:
|
||||
@echo "🧪 Integration Tests"
|
||||
@echo "===================="
|
||||
@php tests/Integration/SearchTest.php
|
||||
|
||||
[group('public-dev')]
|
||||
stats-public:
|
||||
@echo "=== Public Database Statistics ==="
|
||||
[group('test')]
|
||||
test-security:
|
||||
@echo "🧪 Security Tests"
|
||||
@echo "================="
|
||||
@php tests/Security/SecurityTest.php
|
||||
|
||||
[group('test')]
|
||||
syntax:
|
||||
@echo "🔍 Checking PHP Syntax"
|
||||
@echo "======================"
|
||||
@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 lib/ -name "*.php" -exec php -l {} \; | grep -v "No syntax errors"
|
||||
@echo "✅ All PHP files have valid syntax"
|
||||
|
||||
# ============================================================================
|
||||
# Database Management
|
||||
# ============================================================================
|
||||
|
||||
# ============================================================================
|
||||
# Database Statistics
|
||||
# ============================================================================
|
||||
|
||||
[group('stats')]
|
||||
stats:
|
||||
@echo "📊 Database Statistics"
|
||||
@echo "======================"
|
||||
@echo ""
|
||||
@sqlite3 database/test.db "SELECT COUNT(*) || ' total theses' FROM theses;"
|
||||
@sqlite3 database/test.db "SELECT COUNT(*) || ' published theses' FROM theses WHERE is_published = 1;"
|
||||
@sqlite3 database/test.db "SELECT COUNT(*) || ' authors' FROM authors;"
|
||||
@sqlite3 database/test.db "SELECT COUNT(*) || ' supervisors' FROM supervisors;"
|
||||
@sqlite3 database/test.db "SELECT COUNT(*) || ' keywords' FROM keywords;"
|
||||
@sqlite3 database/test.db "SELECT COUNT(*) || ' files uploaded' FROM thesis_files;"
|
||||
|
||||
[group('public-dev')]
|
||||
recent-public:
|
||||
@echo "=== Recent Published Theses ==="
|
||||
[group('stats')]
|
||||
recent:
|
||||
@echo "📅 Recent Theses"
|
||||
@echo "================"
|
||||
@sqlite3 -column -header database/test.db "SELECT id, title, year, authors FROM v_theses_public ORDER BY year DESC, title LIMIT 10;"
|
||||
|
||||
[group('public-dev')]
|
||||
check-public:
|
||||
@echo "Checking public site PHP syntax..."
|
||||
@cd apps/public && find . -name "*.php" -not -path "./vendor/*" -not -path "./tests/*" -exec php -l {} \; | grep -v "No syntax errors"
|
||||
@echo "✓ All files have valid syntax"
|
||||
|
||||
[group('public-dev')]
|
||||
logs-public:
|
||||
@if [ -f apps/public/error.log ]; then tail -n 50 apps/public/error.log; else echo "No error log found"; fi
|
||||
|
||||
# ============================================================================
|
||||
# Admin Panel Development
|
||||
# Database Management
|
||||
# ============================================================================
|
||||
|
||||
[group('admin-dev')]
|
||||
init-test-db:
|
||||
@echo "Creating test database from schema..."
|
||||
[group('database')]
|
||||
init-db:
|
||||
@echo "📊 Creating test database from schema..."
|
||||
@sqlite3 database/test.db < database/schema.sql
|
||||
@echo "✓ Test database created"
|
||||
@sqlite3 database/test.db "SELECT COUNT(*) || ' tables created' FROM sqlite_master WHERE type='table';"
|
||||
@sqlite3 database/test.db "SELECT COUNT(*) || ' orientations loaded' FROM orientations;"
|
||||
@sqlite3 database/test.db "SELECT COUNT(*) || ' AP programs loaded' FROM ap_programs;"
|
||||
|
||||
[group('admin-dev')]
|
||||
serve-admin: init-test-db
|
||||
@echo "Starting admin panel on http://localhost:3000"
|
||||
@echo "Press Ctrl+C to stop"
|
||||
@cd apps/admin && php -S 127.0.0.1:3000
|
||||
|
||||
[group('admin-dev')]
|
||||
serve-admin-only:
|
||||
@echo "Starting admin panel on http://localhost:3000"
|
||||
@echo "Press Ctrl+C to stop"
|
||||
@cd apps/admin && php -S 127.0.0.1:3000
|
||||
|
||||
[group('admin-dev')]
|
||||
cleanup-admin:
|
||||
@echo "Cleaning up admin test files..."
|
||||
[group('database')]
|
||||
reset-db:
|
||||
@echo "⚠️ Resetting database (will delete all data)..."
|
||||
@rm -f database/test.db
|
||||
@rm -f apps/admin/error.log
|
||||
@rm -rf apps/admin/data/theses/*
|
||||
@rm -rf apps/admin/data/covers/*
|
||||
@echo "✓ Cleanup complete"
|
||||
|
||||
[group('admin-dev')]
|
||||
reset-admin: cleanup-admin init-test-db
|
||||
@echo "✓ Admin test environment reset"
|
||||
|
||||
[group('admin-dev')]
|
||||
stats-admin:
|
||||
@echo "=== Admin Database Statistics ==="
|
||||
@sqlite3 database/test.db "SELECT COUNT(*) || ' theses' FROM theses;"
|
||||
@sqlite3 database/test.db "SELECT COUNT(*) || ' authors' FROM authors;"
|
||||
@sqlite3 database/test.db "SELECT COUNT(*) || ' supervisors' FROM supervisors;"
|
||||
@sqlite3 database/test.db "SELECT COUNT(*) || ' keywords' FROM keywords;"
|
||||
@sqlite3 database/test.db "SELECT COUNT(*) || ' files uploaded' FROM thesis_files;"
|
||||
|
||||
[group('admin-dev')]
|
||||
recent-admin:
|
||||
@echo "=== Recent Submissions ==="
|
||||
@sqlite3 -column -header database/test.db "SELECT identifier, title, year, submitted_at FROM theses ORDER BY submitted_at DESC LIMIT 5;"
|
||||
|
||||
[group('admin-dev')]
|
||||
setup-dirs:
|
||||
@mkdir -p apps/admin/data/theses
|
||||
@mkdir -p apps/admin/data/covers
|
||||
@mkdir -p apps/admin/data/yaml
|
||||
@touch apps/admin/data/theses/.gitkeep
|
||||
@touch apps/admin/data/covers/.gitkeep
|
||||
@echo "✓ Data directories created"
|
||||
|
||||
[group('admin-dev')]
|
||||
dev-admin: setup-dirs init-test-db serve-admin
|
||||
|
||||
# ============================================================================
|
||||
# Database Operations
|
||||
# ============================================================================
|
||||
@just init-db
|
||||
@echo "✓ Database reset complete"
|
||||
|
||||
[group('database')]
|
||||
query-db:
|
||||
query:
|
||||
@sqlite3 database/test.db
|
||||
|
||||
[group('database')]
|
||||
show-thesis id:
|
||||
show id:
|
||||
@echo "Thesis #{{id}}"
|
||||
@echo "=============="
|
||||
@sqlite3 -column -header database/test.db "SELECT * FROM v_theses_full WHERE id = {{id}};"
|
||||
|
||||
[group('database')]
|
||||
dump-db:
|
||||
backup:
|
||||
@echo "💾 Backing up database..."
|
||||
@sqlite3 database/test.db .dump > database/backup_$(date +%Y%m%d_%H%M%S).sql
|
||||
@echo "✓ Database dumped to database/backup_$(date +%Y%m%d_%H%M%S).sql"
|
||||
|
||||
[group('database')]
|
||||
create-fixtures:
|
||||
@echo "Creating test database with fixtures..."
|
||||
fixtures:
|
||||
@echo "🎭 Creating test database with fixtures..."
|
||||
@php database/fixtures/CreateTestDatabase.php
|
||||
|
||||
[group('database')]
|
||||
deploy-test-db:
|
||||
@echo "⚠️ Deploying test database to server (will overwrite remote test.db)"
|
||||
@echo "Creating database directory if needed..."
|
||||
ssh posterg "mkdir -p /var/www/html/database"
|
||||
rsync -vur --progress ./database/test.db posterg:/var/www/html/database/test.db
|
||||
@echo "Setting correct permissions..."
|
||||
ssh posterg "chgrp posterg /var/www/html/database /var/www/html/database/test.db && \
|
||||
chmod 775 /var/www/html/database && \
|
||||
chmod 660 /var/www/html/database/test.db"
|
||||
@echo "✅ Test database deployed"
|
||||
|
||||
# ============================================================================
|
||||
# Server Tools
|
||||
# ============================================================================
|
||||
|
||||
[group('server')]
|
||||
deploy-nginx:
|
||||
@echo "🔧 Deploying nginx configuration..."
|
||||
rsync -vur --progress ./nginx/posterg.conf posterg:/tmp/posterg.conf
|
||||
rsync -vur --progress ./nginx/deploy-production.sh posterg:/tmp/deploy-production.sh
|
||||
@echo "✅ Files uploaded to /tmp/ on server"
|
||||
@echo ""
|
||||
@echo "Next steps on the server:"
|
||||
@echo " ssh posterg"
|
||||
@echo " sudo bash /tmp/deploy-production.sh"
|
||||
|
||||
[group('server')]
|
||||
deploy-admin-tools:
|
||||
@echo "🔑 Uploading admin user management tools..."
|
||||
rsync -vur --progress ./nginx/manage-admin-users.sh posterg:/tmp/manage-admin-users.sh
|
||||
@echo "✅ Script uploaded"
|
||||
@echo ""
|
||||
@echo "To manage admin users:"
|
||||
@echo " ssh posterg"
|
||||
@echo " sudo bash /tmp/manage-admin-users.sh"
|
||||
|
||||
[group('server')]
|
||||
server-logs:
|
||||
@echo "📋 Server logs (last 50 lines)"
|
||||
@echo "=============================="
|
||||
@echo ""
|
||||
@echo "Nginx error log:"
|
||||
@echo "----------------"
|
||||
ssh posterg "sudo tail -50 /var/log/nginx/posterg_error.log" || echo "Cannot read logs (permission denied)"
|
||||
@echo ""
|
||||
@echo "Nginx access log:"
|
||||
@echo "-----------------"
|
||||
ssh posterg "sudo tail -20 /var/log/nginx/posterg_access.log" || echo "Cannot read logs (permission denied)"
|
||||
|
||||
[group('server')]
|
||||
server-status:
|
||||
@echo "🔍 Server Status"
|
||||
@echo "================"
|
||||
@ssh posterg "systemctl is-active nginx && echo '✓ Nginx running' || echo '✗ Nginx stopped'"
|
||||
@ssh posterg "systemctl is-active php8.4-fpm && echo '✓ PHP-FPM running' || echo '✗ PHP-FPM stopped'"
|
||||
@echo ""
|
||||
@echo "Site check:"
|
||||
@curl -s -o /dev/null -w " • Public: %{http_code}\n" https://posterg.erg.be/ || echo " • Public: offline"
|
||||
@curl -s -o /dev/null -w " • Admin: %{http_code}\n" https://posterg.erg.be/admin/ || echo " • Admin: offline"
|
||||
|
||||
# ============================================================================
|
||||
# Utility Commands
|
||||
# ============================================================================
|
||||
|
||||
[group('utils')]
|
||||
clean:
|
||||
@echo "🧹 Cleaning up development files..."
|
||||
@rm -f error.log
|
||||
@rm -f admin/error.log
|
||||
@rm -rf lib/cache/rate_limit/*
|
||||
@rm -f /tmp/posterg-*.log
|
||||
@rm -f /tmp/posterg-*.pid
|
||||
@echo "✓ Cleanup complete"
|
||||
|
||||
[group('utils')]
|
||||
setup-dirs:
|
||||
@echo "📁 Creating data directories..."
|
||||
@mkdir -p admin/data/theses
|
||||
@mkdir -p admin/data/covers
|
||||
@mkdir -p admin/data/yaml
|
||||
@mkdir -p lib/cache/rate_limit
|
||||
@touch admin/data/theses/.gitkeep
|
||||
@touch admin/data/covers/.gitkeep
|
||||
@echo "✓ Directories created"
|
||||
|
||||
Reference in New Issue
Block a user