Files
basil/scripts/deploy.sh
Paul R Kartchner d1156833a2
Some checks failed
CI/CD Pipeline / Run Tests (pull_request) Has been cancelled
CI/CD Pipeline / Code Quality (pull_request) Has been cancelled
CI Pipeline / Lint Code (pull_request) Has been cancelled
CI Pipeline / Test API Package (pull_request) Has been cancelled
CI Pipeline / Test Web Package (pull_request) Has been cancelled
CI Pipeline / Test Shared Package (pull_request) Has been cancelled
Docker Build & Deploy / Build Docker Images (pull_request) Has been cancelled
E2E Tests / End-to-End Tests (pull_request) Has been cancelled
E2E Tests / E2E Tests (Mobile) (pull_request) Has been cancelled
Security Scanning / NPM Audit (pull_request) Has been cancelled
Security Scanning / Dependency License Check (pull_request) Has been cancelled
Security Scanning / Code Quality Scan (pull_request) Has been cancelled
Security Scanning / Docker Image Security (pull_request) Has been cancelled
CI/CD Pipeline / Build and Push Docker Images (pull_request) Has been cancelled
CI Pipeline / Build All Packages (pull_request) Has been cancelled
CI Pipeline / Generate Coverage Report (pull_request) Has been cancelled
Docker Build & Deploy / Push Docker Images (pull_request) Has been cancelled
Docker Build & Deploy / Deploy to Staging (pull_request) Has been cancelled
Docker Build & Deploy / Deploy to Production (pull_request) Has been cancelled
Security Scanning / Security Summary (pull_request) Has been cancelled
feat: add CI/CD pipeline, backup system, and deployment automation
## Summary
- Add complete CI/CD pipeline with Gitea Actions for automated testing, building, and deployment
- Implement backup and restore system with full database and file backup to ZIP
- Add deployment automation with webhook receiver and systemd service
- Enhance recipe editing UI with improved ingredient parsing and cooking mode features
- Add comprehensive documentation for CI/CD, deployment, and backup features

## CI/CD Pipeline
- New workflow in .gitea/workflows/ci-cd.yml with test, build, and deploy stages
- Automated Docker image building and pushing to registry
- Webhook-triggered deployments to production servers

## Backup & Restore
- New backup service with ZIP creation including database dump and uploads
- REST API endpoints for create, list, download, restore, and delete operations
- Configurable backup path via BACKUP_PATH environment variable

## Deployment
- Automated deployment scripts (deploy.sh, manual-deploy.sh)
- Webhook receiver with systemd service for deployment triggers
- Environment configuration template (.env.deploy.example)

## Documentation
- docs/CI-CD-SETUP.md - Complete CI/CD pipeline setup guide
- docs/DEPLOYMENT-QUICK-START.md - Quick deployment reference
- docs/BACKUP.md - Backup and restore documentation
- docs/REMOTE_DATABASE.md - Remote database configuration guide
- scripts/README.md - Deployment scripts documentation

## Web Improvements
- Enhanced ingredient parser with better unit and quantity detection
- Improved recipe editing interface with unified edit experience
- Better cooking mode functionality
- Updated dependencies in package.json

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-08 05:04:39 +00:00

199 lines
5.1 KiB
Bash
Executable File

#!/bin/bash
# Basil Deployment Script
# This script pulls the latest Docker images and restarts the containers
set -e # Exit on error
# Configuration
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
LOG_FILE="$PROJECT_DIR/deploy.log"
BACKUP_DIR="$PROJECT_DIR/backups"
DOCKER_REGISTRY="${DOCKER_REGISTRY:-docker.io}"
DOCKER_USERNAME="${DOCKER_USERNAME}"
IMAGE_TAG="${IMAGE_TAG:-latest}"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Logging function
log() {
echo -e "${GREEN}[$(date +'%Y-%m-%d %H:%M:%S')]${NC} $1" | tee -a "$LOG_FILE"
}
error() {
echo -e "${RED}[$(date +'%Y-%m-%d %H:%M:%S')] ERROR:${NC} $1" | tee -a "$LOG_FILE"
}
warning() {
echo -e "${YELLOW}[$(date +'%Y-%m-%d %H:%M:%S')] WARNING:${NC} $1" | tee -a "$LOG_FILE"
}
# Check if Docker is running
check_docker() {
if ! docker info > /dev/null 2>&1; then
error "Docker is not running. Please start Docker and try again."
exit 1
fi
log "Docker is running"
}
# Create backup before deployment
create_backup() {
log "Creating pre-deployment backup..."
# Ensure backup directory exists
mkdir -p "$BACKUP_DIR"
# Create backup using the API if running
if docker ps | grep -q basil-api; then
log "Creating database backup via API..."
curl -X POST http://localhost:3001/api/backup -o "$BACKUP_DIR/pre-deploy-$(date +%Y%m%d-%H%M%S).zip" 2>/dev/null || warning "API backup failed, continuing anyway"
else
warning "API container not running, skipping automatic backup"
fi
}
# Pull latest images from registry
pull_images() {
log "Pulling latest Docker images..."
if [ -z "$DOCKER_USERNAME" ]; then
error "DOCKER_USERNAME environment variable not set"
exit 1
fi
# Pull API image
log "Pulling API image: ${DOCKER_REGISTRY}/${DOCKER_USERNAME}/basil-api:${IMAGE_TAG}"
docker pull "${DOCKER_REGISTRY}/${DOCKER_USERNAME}/basil-api:${IMAGE_TAG}" || {
error "Failed to pull API image"
exit 1
}
# Pull Web image
log "Pulling Web image: ${DOCKER_REGISTRY}/${DOCKER_USERNAME}/basil-web:${IMAGE_TAG}"
docker pull "${DOCKER_REGISTRY}/${DOCKER_USERNAME}/basil-web:${IMAGE_TAG}" || {
error "Failed to pull Web image"
exit 1
}
log "Successfully pulled all images"
}
# Update docker-compose.yml to use registry images
update_docker_compose() {
log "Updating docker-compose configuration..."
# Create docker-compose.override.yml to use registry images
cat > "$PROJECT_DIR/docker-compose.override.yml" <<EOF
services:
api:
image: ${DOCKER_REGISTRY}/${DOCKER_USERNAME}/basil-api:${IMAGE_TAG}
build:
# Override build to prevent building from source
context: .
dockerfile: packages/api/Dockerfile
web:
image: ${DOCKER_REGISTRY}/${DOCKER_USERNAME}/basil-web:${IMAGE_TAG}
build:
context: .
dockerfile: packages/web/Dockerfile
EOF
log "Docker Compose override file created"
}
# Restart containers
restart_containers() {
log "Restarting containers..."
cd "$PROJECT_DIR"
# Stop containers
log "Stopping containers..."
docker-compose down || warning "Failed to stop some containers"
# Start containers with new images
log "Starting containers with new images..."
docker-compose up -d || {
error "Failed to start containers"
exit 1
}
log "Containers restarted successfully"
}
# Health check
health_check() {
log "Performing health checks..."
# Wait for API to be ready
log "Waiting for API to be healthy..."
MAX_RETRIES=30
RETRY_COUNT=0
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
if curl -f http://localhost:3001/health > /dev/null 2>&1; then
log "API is healthy"
break
fi
RETRY_COUNT=$((RETRY_COUNT + 1))
if [ $RETRY_COUNT -eq $MAX_RETRIES ]; then
error "API health check failed after $MAX_RETRIES attempts"
docker-compose logs api
exit 1
fi
sleep 2
done
# Check web container
if docker ps | grep -q basil-web; then
log "Web container is running"
else
error "Web container is not running"
docker-compose logs web
exit 1
fi
log "All health checks passed"
}
# Cleanup old images
cleanup_old_images() {
log "Cleaning up old Docker images..."
docker image prune -f > /dev/null 2>&1 || warning "Failed to prune some images"
log "Cleanup complete"
}
# Main deployment flow
main() {
log "========================================="
log "Starting Basil deployment"
log "Registry: ${DOCKER_REGISTRY}"
log "Username: ${DOCKER_USERNAME}"
log "Tag: ${IMAGE_TAG}"
log "========================================="
check_docker
create_backup
pull_images
update_docker_compose
restart_containers
health_check
cleanup_old_images
log "========================================="
log "Deployment completed successfully!"
log "========================================="
}
# Run main function
main "$@"