buckets/shell.nix

233 lines
7.4 KiB
Nix
Raw Normal View History

2026-06-14 20:42:06 +02:00
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
buildInputs = with pkgs; [
# PHP and tools
php84
php84Packages.composer
symfony-cli
# Node.js and npm (React/Vite SPA)
nodejs_22
# Container tools
podman
podman-compose
# Database client (for direct DB access)
postgresql
2026-06-14 20:42:06 +02:00
# Utilities
git
curl
gnumake
];
shellHook = ''
export USER_ID=$(id -u)
export GROUP_ID=$(id -g)
export PODMAN_USERNS=keep-id
# Compose files (symfony-docker convention: root compose.yaml + compose.override.yaml).
# Both must be passed explicitly so the dev override is merged.
# NOTE: $COMPOSE is invoked unquoted (word-split into args) — assumes the repo path
# contains no spaces. Fine here; would break if checked out under a path with spaces.
COMPOSE="podman-compose -f $PWD/compose.yaml -f $PWD/compose.override.yaml"
2026-06-14 20:42:06 +02:00
# ===================
# ALIASES
# ===================
alias pc="$COMPOSE"
2026-06-14 20:42:06 +02:00
# ===================
# DEV COMMANDS
# ===================
dev-up() {
echo "Starting services..."
PODMAN_USERNS=keep-id $COMPOSE up -d "$@"
2026-06-14 20:42:06 +02:00
echo ""
$COMPOSE ps
2026-06-14 20:42:06 +02:00
echo ""
echo "App available at: http://localhost:8100"
}
dev-down() {
if [[ "$1" == "-v" ]]; then
echo "Stopping services and removing volumes..."
$COMPOSE down -v
2026-06-14 20:42:06 +02:00
else
echo "Stopping services..."
$COMPOSE down
2026-06-14 20:42:06 +02:00
fi
}
dev-restart() {
echo "Restarting services..."
$COMPOSE restart "$@"
2026-06-14 20:42:06 +02:00
}
dev-rebuild() {
echo "Rebuilding services (down -v + up)..."
$COMPOSE down -v
PODMAN_USERNS=keep-id $COMPOSE up -d "$@"
2026-06-14 20:42:06 +02:00
echo ""
$COMPOSE ps
2026-06-14 20:42:06 +02:00
echo ""
echo "App available at: http://localhost:8100"
}
dev-logs() {
$COMPOSE logs -f php "$@"
2026-06-14 20:42:06 +02:00
}
dev-logs-db() {
$COMPOSE logs -f database "$@"
2026-06-14 20:42:06 +02:00
}
dev-shell() {
$COMPOSE exec php sh
2026-06-14 20:42:06 +02:00
}
dev-console() {
$COMPOSE exec php php bin/console "$@"
2026-06-14 20:42:06 +02:00
}
dev-composer() {
$COMPOSE exec php composer "$@"
2026-06-14 20:42:06 +02:00
}
2026-06-15 01:04:32 +02:00
# ===================
# QA COMMANDS (run in the php container)
# ===================
dev-test() {
$COMPOSE exec php php bin/phpunit "$@"
}
2026-06-20 23:51:13 +02:00
dev-coverage() {
# Code coverage as a plain text table in the terminal (needs Xdebug, which is installed).
# --colors=never keeps the table readable (the ANSI colors garble it).
# Pass-through args, e.g. scope to one class: dev-coverage --filter BucketRoomCalculator
$COMPOSE exec -e XDEBUG_MODE=coverage php php bin/phpunit --coverage-text --colors=never "$@"
}
2026-06-15 01:11:08 +02:00
dev-stan() {
# Warm the dev cache so phpstan-symfony can read the compiled container, then analyse.
$COMPOSE exec php php bin/console cache:warmup --quiet
$COMPOSE exec php vendor/bin/phpstan analyse --memory-limit=512M "$@"
}
2026-06-15 01:15:21 +02:00
dev-cs() {
# Dry-run code-style check (no changes). Use for CI / verification.
$COMPOSE exec php vendor/bin/php-cs-fixer check --diff "$@"
}
dev-cs-fix() {
# Apply code-style fixes in place.
$COMPOSE exec php vendor/bin/php-cs-fixer fix "$@"
}
2026-06-18 23:48:27 +02:00
# ===================
# DATABASE / MIGRATION COMMANDS
# ===================
# The Doctrine migration workflow, simplified. Typical loop:
# 1. change an entity mapping
# 2. dev-migrate-diff -> generate ONE migration from the mapping (review it!)
# 3. dev-migrate -> apply to BOTH dev and test DBs
# If you generated/applied a wrong migration: dev-migrate-prev rolls back BOTH DBs,
# then delete the bad migrations/Version*.php file and re-run dev-migrate-diff.
dev-migrate-diff() {
# Generate a migration from the diff between entity mappings and the dev DB schema.
# ALWAYS read the generated migrations/Version*.php before applying it.
echo "Generating migration from entity mapping diff..."
$COMPOSE exec php php bin/console doctrine:migrations:diff "$@"
echo ""
echo ">> Review the new file in migrations/ before running dev-migrate."
}
dev-migrate() {
# Apply pending migrations to BOTH the dev and test databases.
# Interactive: Doctrine will prompt before destructive/unregistered changes — read them.
echo "=== Migrating DEV database (buckets) ==="
$COMPOSE exec php php bin/console doctrine:migrations:migrate "$@"
echo ""
echo "=== Migrating TEST database (buckets_test) ==="
$COMPOSE exec php php bin/console doctrine:migrations:migrate --env=test "$@"
}
dev-migrate-prev() {
# Roll back the most recent migration on BOTH the dev and test databases.
echo "=== Rolling back DEV database (buckets) one step ==="
$COMPOSE exec php php bin/console doctrine:migrations:migrate prev "$@"
echo ""
echo "=== Rolling back TEST database (buckets_test) one step ==="
$COMPOSE exec php php bin/console doctrine:migrations:migrate prev --env=test "$@"
}
2026-06-14 20:42:06 +02:00
# ===================
# BUILD COMMANDS
# ===================
base-build() {
local image="forge.lvl0.xyz/lvl0/buckets:latest"
# Check if logged in, prompt if not
if ! podman login --get-login forge.lvl0.xyz &>/dev/null; then
echo "Not logged in to forge.lvl0.xyz"
podman login forge.lvl0.xyz || return 1
fi
echo "Building image: $image"
if ! podman build -t "$image" -f Dockerfile .; then
echo "Build failed!"
return 1
fi
echo ""
echo "Pushing to registry..."
if ! podman push "$image"; then
echo "Push failed!"
return 1
fi
echo ""
echo "Done! Image pushed: $image"
}
# ===================
# WELCOME MESSAGE
# ===================
echo ""
echo "================================================="
echo " Buckets Dev Environment "
echo "================================================="
echo ""
echo " PHP: $(php --version | head -1 | cut -d' ' -f2)"
echo " Symfony: $(symfony version 2>/dev/null | head -1 || echo 'symfony-cli')"
echo " Podman: $(podman --version | cut -d' ' -f3)"
echo ""
echo "Commands:"
echo " dev-up [services] Start all or specific services"
echo " dev-down [-v] Stop services (-v removes volumes)"
echo " dev-rebuild Fresh start (down -v + up)"
echo " dev-restart Restart services"
echo " dev-logs Tail app logs"
echo " dev-logs-db Tail database logs"
echo " dev-shell Shell into app container"
echo " dev-console <cmd> Run Symfony console command"
echo " dev-composer <cmd> Run composer in the container"
2026-06-15 01:04:32 +02:00
echo " dev-test [args] Run PHPUnit (bin/phpunit)"
2026-06-15 01:11:08 +02:00
echo " dev-stan [args] Run PHPStan static analysis"
2026-06-15 01:15:21 +02:00
echo " dev-cs [args] Check code style (dry-run)"
echo " dev-cs-fix [args] Apply code style fixes"
2026-06-18 23:48:27 +02:00
echo " dev-migrate-diff Generate a migration from entity mappings"
echo " dev-migrate Apply migrations to dev + test DBs"
echo " dev-migrate-prev Roll back one migration on dev + test DBs"
2026-06-14 20:42:06 +02:00
echo " base-build Build and push image"
echo ""
echo "Services:"
echo " php Symfony/FrankenPHP http://localhost:8100"
echo " database Postgres 16 localhost:5433"
2026-06-14 20:42:06 +02:00
echo ""
'';
}