Some checks are pending
Deploy to Production / deploy (push) Waiting to run
- Added .dockerignore to exclude unnecessary files from Docker builds - Enhanced .env.example with detailed configuration options and added MySQL settings - Created Gitea CI/CD workflow for automated production deployment with health checks - Added comprehensive Caddy server setup guide and configuration for reverse proxy - Created Caddyfile with secure defaults for SSL, compression, and security headers The changes focus on setting up a production-
81 lines
2.1 KiB
Bash
Executable File
81 lines
2.1 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
echo "🚀 VoxBlog Deployment Script"
|
|
echo "=============================="
|
|
|
|
# Colors for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Check if .env exists
|
|
if [ ! -f .env ]; then
|
|
echo -e "${RED}❌ .env file not found!${NC}"
|
|
echo "Please create .env file from .env.example"
|
|
exit 1
|
|
fi
|
|
|
|
# Pull latest code
|
|
echo -e "${YELLOW}📥 Pulling latest code...${NC}"
|
|
git pull origin main
|
|
|
|
# Stop existing containers
|
|
echo -e "${YELLOW}🛑 Stopping existing containers...${NC}"
|
|
docker-compose down
|
|
|
|
# Build new images
|
|
echo -e "${YELLOW}🔨 Building new images...${NC}"
|
|
docker-compose build --no-cache
|
|
|
|
# Start containers
|
|
echo -e "${YELLOW}▶️ Starting containers...${NC}"
|
|
docker-compose up -d
|
|
|
|
# Wait for services to be ready
|
|
echo -e "${YELLOW}⏳ Waiting for services to start...${NC}"
|
|
sleep 15
|
|
|
|
# Run database migrations
|
|
echo -e "${YELLOW}🗄️ Running database migrations...${NC}"
|
|
docker-compose exec -T api pnpm run drizzle:migrate || echo "Migration skipped or failed"
|
|
|
|
# Health check
|
|
echo -e "${YELLOW}🏥 Performing health checks...${NC}"
|
|
|
|
API_HEALTH=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:3001/health || echo "000")
|
|
if [ "$API_HEALTH" = "200" ]; then
|
|
echo -e "${GREEN}✅ API is healthy${NC}"
|
|
else
|
|
echo -e "${RED}❌ API health check failed (HTTP $API_HEALTH)${NC}"
|
|
echo "Checking API logs:"
|
|
docker-compose logs --tail=50 api
|
|
exit 1
|
|
fi
|
|
|
|
ADMIN_HEALTH=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:3000 || echo "000")
|
|
if [ "$ADMIN_HEALTH" = "200" ]; then
|
|
echo -e "${GREEN}✅ Admin is healthy${NC}"
|
|
else
|
|
echo -e "${RED}❌ Admin health check failed (HTTP $ADMIN_HEALTH)${NC}"
|
|
echo "Checking Admin logs:"
|
|
docker-compose logs --tail=50 admin
|
|
exit 1
|
|
fi
|
|
|
|
# Clean up old images
|
|
echo -e "${YELLOW}🧹 Cleaning up old Docker images...${NC}"
|
|
docker image prune -af --filter "until=24h"
|
|
|
|
echo ""
|
|
echo -e "${GREEN}✅ Deployment complete!${NC}"
|
|
echo ""
|
|
echo "Services running:"
|
|
echo " - API: http://localhost:3001"
|
|
echo " - Admin: http://localhost:3000"
|
|
echo ""
|
|
echo "To view logs: docker-compose logs -f"
|
|
echo "To stop: docker-compose down"
|