diff --git a/Makefile b/Makefile index a57c6f2b..955d67a4 100644 --- a/Makefile +++ b/Makefile @@ -116,6 +116,13 @@ k-test: ## Run tests in k8s pod @echo "๐Ÿงช Running tests in k8s pod..." @kubectl -n $(K8S_NS) exec deploy/web -- php artisan test +k-seed: ## Run database seeders in k8s (usage: make k-seed SEEDER=DevSeeder) + @kubectl -n $(K8S_NS) exec deploy/web -- php artisan db:seed --class=$(SEEDER) + +k-migrate-fresh: ## Fresh database with seeding in k8s pod + @echo "๐Ÿ”„ Running fresh migration with seeding..." + @kubectl -n $(K8S_NS) exec deploy/web -- php artisan migrate:fresh --seed + k-status: ## Show k8s environment status @echo "๐Ÿ“Š Status for namespace: $(K8S_NS)" @echo "" @@ -222,6 +229,21 @@ install: ## Initial project setup mailpit: ## Open Mailpit web UI @open http://localhost:8025 || xdg-open http://localhost:8025 || echo "Open http://localhost:8025 in your browser" +new-worktree: ## Create new worktree (usage: make new-worktree BRANCH=feature/my-feature or make new-worktree BRANCH=feature/my-feature NEW=true) + @if [ -z "$(BRANCH)" ]; then \ + echo "โŒ Error: BRANCH parameter required"; \ + echo ""; \ + echo "Usage:"; \ + echo " make new-worktree BRANCH=feature/my-feature # Checkout existing branch"; \ + echo " make new-worktree BRANCH=feature/my-feature NEW=true # Create new branch"; \ + exit 1; \ + fi + @if [ "$(NEW)" = "true" ]; then \ + ./scripts/new-worktree.sh -b $(BRANCH); \ + else \ + ./scripts/new-worktree.sh $(BRANCH); \ + fi + help: ## Show this help message @echo "\n๐Ÿ“ฆ CannaBrands Docker Commands\n" @echo "Local Development (Sail):" diff --git a/scripts/new-worktree.sh b/scripts/new-worktree.sh new file mode 100755 index 00000000..3e5106ba --- /dev/null +++ b/scripts/new-worktree.sh @@ -0,0 +1,96 @@ +#!/bin/bash +# +# Create a new git worktree with proper naming convention and .env setup +# +# Usage: +# ./scripts/new-worktree.sh feature/my-feature # Checkout existing branch +# ./scripts/new-worktree.sh -b feature/my-feature # Create new branch +# + +set -e + +# Color codes for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +# Parse arguments +CREATE_BRANCH=false +BRANCH="" + +while [[ $# -gt 0 ]]; do + case $1 in + -b|--branch) + CREATE_BRANCH=true + shift + ;; + *) + BRANCH="$1" + shift + ;; + esac +done + +# Validate branch name provided +if [ -z "$BRANCH" ]; then + echo -e "${RED}โŒ Error: Branch name required${NC}" + echo "" + echo "Usage:" + echo " ./scripts/new-worktree.sh feature/my-feature # Checkout existing branch" + echo " ./scripts/new-worktree.sh -b feature/my-feature # Create new branch" + exit 1 +fi + +# Get to repo root (works from worktrees and main repo) +# git-common-dir points to .git, so get its parent +REPO_ROOT=$(dirname "$(git rev-parse --git-common-dir)") + +# Derive worktree directory name from branch (strip prefix, replace slashes) +WORKTREE_NAME=$(echo "$BRANCH" | sed 's/feature\///' | sed 's/bugfix\///' | sed 's/hotfix\///' | sed 's/\//-/g') +WORKTREE_PATH="$REPO_ROOT/.worktrees/$WORKTREE_NAME" + +cd "$REPO_ROOT" + +echo "" +echo -e "${BLUE}๐Ÿ“ Creating worktree for branch: ${GREEN}$BRANCH${NC}" +echo -e "${BLUE} Directory: ${GREEN}$WORKTREE_PATH${NC}" +echo "" + +# Create worktree +if [ "$CREATE_BRANCH" = true ]; then + echo -e "${YELLOW}๐ŸŒฟ Creating new branch and worktree...${NC}" + git worktree add -b "$BRANCH" "$WORKTREE_PATH" +else + echo -e "${YELLOW}๐ŸŒฟ Creating worktree from existing branch...${NC}" + git fetch origin + git worktree add "$WORKTREE_PATH" "$BRANCH" +fi + +# Copy .env from example +echo -e "${YELLOW}๐Ÿ“‹ Setting up .env from template...${NC}" +if [ -f "$WORKTREE_PATH/.env.example" ]; then + cp "$WORKTREE_PATH/.env.example" "$WORKTREE_PATH/.env" + echo -e "${GREEN} โœ… Created .env from .env.example${NC}" +elif [ -f ".env" ]; then + # Fallback: copy from main repo if it exists + cp .env "$WORKTREE_PATH/.env" + echo -e "${GREEN} โœ… Copied .env from main repo${NC}" +else + echo -e "${YELLOW} โš ๏ธ No .env.example found - you'll need to create .env manually${NC}" +fi + +echo "" +echo -e "${GREEN}โœ… Worktree created successfully!${NC}" +echo "" +echo -e "${BLUE}๐Ÿ“ Next steps:${NC}" +echo -e " 1. ${YELLOW}cd $WORKTREE_PATH${NC}" +echo -e " 2. ${YELLOW}# Edit .env if needed (DB credentials, etc.)${NC}" +echo -e " 3. ${YELLOW}make k-dev${NC} ${BLUE}# Start k8s environment${NC}" +echo -e " 4. ${YELLOW}make k-artisan CMD=\"db:seed\"${NC} ${BLUE}# Seed database${NC}" +echo "" +echo -e "${BLUE}๐ŸŒ Your app will be available at:${NC}" +K8S_HOST=$(echo "$BRANCH" | sed 's/feature\///' | sed 's/bugfix\///' | sed 's/hotfix\///' | sed 's/\//-/g') +echo -e " ${GREEN}http://${K8S_HOST}.cannabrands.test${NC}" +echo ""