Files
hub/scripts/deploy.sh
Jon Leopard 7629500d2b feat: implement complete Docker containerization for development and production
Implemented full Docker containerization to support both local development
and production deployments with Laravel Sail and custom production builds.

Development Environment (Laravel Sail):
- Installed Laravel Sail with PostgreSQL 17, Redis 7, and Mailpit
- Custom Sail Dockerfile with PHP 8.4, Node.js 22, Chromium/Puppeteer
- Complete development stack with hot module replacement support
- Services accessible: Laravel (port 80), PostgreSQL (5432), Redis (6379), Mailpit (8025)

Production Environment:
- Multi-stage production Dockerfile for optimized image size
- Separate node builder, composer builder, and runtime stages
- PHP-FPM + Nginx for production-ready web server
- Supervisor for queue workers and scheduled tasks
- Production docker-compose.yml with health checks

Infrastructure & Tooling:
- Health check endpoint at /health (tests DB and Redis connectivity)
- Automated deployment script (scripts/deploy.sh)
- Makefile with common Docker commands
- Environment templates (.env.example, .env.production.example)
- Comprehensive documentation (DOCKER.md)

Configuration Updates:
- Updated .env.example with Docker service names (pgsql, redis, mailpit)
- Added health check route to bootstrap/app.php
- Removed deprecated docker-compose.dev.yml
- Updated CLAUDE.md with PDF generation ARM limitation notes

Maintenance & Cleanup:
- Removed redundant migrations causing duplicate column errors
- Added .dockerignore for optimized build context
- Created Sail alias script for convenience

Docker Architecture:
- Development: Ubuntu 24.04, PHP 8.4, Node 22, PostgreSQL 17, Redis 7
- Production: Alpine-based multi-stage build with security hardening
- Both environments use consistent service naming for easy switching

Usage:
- Development: ./vendor/bin/sail up -d && npm run dev
- Production: ./scripts/deploy.sh or docker-compose -f docker-compose.production.yml up -d
- Full documentation in DOCKER.md

Known Limitations:
- PDF generation (Puppeteer) doesn't work on ARM Macs in Docker
- Documented workarounds in DOCKER.md and CLAUDE.md
- Production x86_64 deployments work perfectly

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-20 10:05:15 -07:00

84 lines
2.7 KiB
Bash
Executable File

#!/bin/bash
#===============================================================================
# CannaBrands Production Deployment Script
#===============================================================================
# This script deploys the application to a production/dev server using Docker
#
# Usage:
# ./scripts/deploy.sh
#
# Requirements:
# - Docker and Docker Compose installed on server
# - .env file configured on server
# - Git repository access
#===============================================================================
set -e # Exit on error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN} CannaBrands Deployment${NC}"
echo -e "${GREEN}========================================${NC}"
echo ""
# Check if .env exists
if [ ! -f .env ]; then
echo -e "${RED}Error: .env file not found${NC}"
echo "Please create .env from .env.production.example and configure it"
exit 1
fi
# Pull latest code
echo -e "${YELLOW}→ Pulling latest code...${NC}"
git pull origin $(git branch --show-current)
# Build Docker image
echo -e "${YELLOW}→ Building Docker image...${NC}"
docker build -t cannabrands/app:latest -f Dockerfile .
# Stop existing containers (if any)
echo -e "${YELLOW}→ Stopping existing containers...${NC}"
docker-compose -f docker-compose.production.yml down || true
# Start new containers
echo -e "${YELLOW}→ Starting containers...${NC}"
docker-compose -f docker-compose.production.yml up -d
# Wait for database to be ready
echo -e "${YELLOW}→ Waiting for database...${NC}"
sleep 10
# Run migrations
echo -e "${YELLOW}→ Running database migrations...${NC}"
docker-compose -f docker-compose.production.yml exec -T app php artisan migrate --force
# Clear caches
echo -e "${YELLOW}→ Clearing caches...${NC}"
docker-compose -f docker-compose.production.yml exec -T app php artisan config:cache
docker-compose -f docker-compose.production.yml exec -T app php artisan route:cache
docker-compose -f docker-compose.production.yml exec -T app php artisan view:cache
# Check health
echo -e "${YELLOW}→ Checking application health...${NC}"
sleep 5
if curl -f http://localhost/health > /dev/null 2>&1; then
echo -e "${GREEN}✓ Deployment successful!${NC}"
echo ""
echo -e "${GREEN}Application is now running${NC}"
echo " • App: http://localhost"
echo " • Mailpit: http://localhost:8025"
echo ""
echo "View logs with: docker-compose -f docker-compose.production.yml logs -f"
else
echo -e "${RED}✗ Health check failed${NC}"
echo "Check logs with: docker-compose -f docker-compose.production.yml logs"
exit 1
fi