Files
basil/scripts/README.md
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

6.0 KiB

Basil Deployment Scripts

This directory contains scripts for automated deployment of Basil.

Scripts Overview

deploy.sh

Main deployment script that handles the complete deployment process.

Features:

  • Pre-deployment backup creation
  • Docker image pulling from registry
  • Container restart with health checks
  • Automatic cleanup of old images
  • Comprehensive logging

Usage:

# With environment variables
DOCKER_USERNAME=myuser DOCKER_REGISTRY=docker.io IMAGE_TAG=latest ./deploy.sh

# Or source from .env.deploy
source ../.env.deploy && ./deploy.sh

Environment Variables:

  • DOCKER_USERNAME (required): Docker registry username
  • DOCKER_REGISTRY (optional, default: docker.io): Registry URL
  • IMAGE_TAG (optional, default: latest): Image tag to pull

manual-deploy.sh

Interactive wrapper around deploy.sh with user prompts.

Features:

  • Interactive prompts for configuration
  • Saves configuration to .env.deploy for future use
  • Confirmation before deployment

Usage:

./manual-deploy.sh

The script will prompt for:

  1. Docker Hub username
  2. Docker registry (default: docker.io)
  3. Image tag (default: latest)
  4. Confirmation to proceed

webhook-receiver.sh

Webhook server that listens for deployment triggers from CI/CD.

Features:

  • HTTP webhook endpoint
  • Secret-based authentication
  • Automatic deployment on webhook call
  • Systemd service support

Usage:

# Manual run (foreground)
WEBHOOK_PORT=9000 WEBHOOK_SECRET=mysecret ./webhook-receiver.sh

# Or install as systemd service (recommended)
sudo cp basil-webhook.service /etc/systemd/system/
sudo systemctl enable basil-webhook
sudo systemctl start basil-webhook

Environment Variables:

  • WEBHOOK_PORT (optional, default: 9000): Port to listen on
  • WEBHOOK_SECRET (optional, default: changeme): Authentication secret

Webhook Endpoint:

POST http://localhost:9000/hooks/basil-deploy
Header: X-Webhook-Secret: your-secret

basil-webhook.service

Systemd service file for running webhook receiver as a system service.

Installation:

# 1. Copy service file
sudo cp basil-webhook.service /etc/systemd/system/

# 2. Edit environment variables in the file
sudo nano /etc/systemd/system/basil-webhook.service

# 3. Reload systemd
sudo systemctl daemon-reload

# 4. Enable and start service
sudo systemctl enable basil-webhook
sudo systemctl start basil-webhook

# 5. Check status
sudo systemctl status basil-webhook

Service Management:

# Start service
sudo systemctl start basil-webhook

# Stop service
sudo systemctl stop basil-webhook

# Restart service
sudo systemctl restart basil-webhook

# View logs
sudo journalctl -u basil-webhook -f

# Check status
sudo systemctl status basil-webhook

Deployment Workflow

Automatic Deployment (CI/CD)

  1. Developer pushes to main branch
  2. Gitea Actions runs tests and builds images
  3. Images pushed to Docker registry
  4. Gitea Actions calls webhook endpoint
  5. Webhook server receives call and executes deploy.sh
  6. Production server pulls new images and restarts

Manual Deployment

  1. Run ./manual-deploy.sh
  2. Enter configuration when prompted
  3. Confirm deployment
  4. Script executes deployment process

Logs

All scripts log to the parent directory:

  • deploy.log - Deployment script logs
  • webhook.log - Webhook server logs
  • webhook-error.log - Webhook server errors

View logs:

# Deployment logs
tail -f ../deploy.log

# Webhook logs
tail -f ../webhook.log

# Webhook errors
tail -f ../webhook-error.log

# Systemd service logs
sudo journalctl -u basil-webhook -f

Configuration Files

.env.deploy (in parent directory)

Stores deployment configuration. Created from .env.deploy.example.

DOCKER_USERNAME=your-dockerhub-username
DOCKER_REGISTRY=docker.io
IMAGE_TAG=latest
WEBHOOK_PORT=9000
WEBHOOK_SECRET=your-random-secret

Important: This file is gitignored and should never be committed.

webhook-config.json (auto-generated)

Generated by webhook-receiver.sh. Configures the webhook endpoint.

Location: Created in scripts directory when webhook-receiver.sh runs.

Troubleshooting

Script Permission Denied

chmod +x *.sh

Docker Pull Fails

# Check credentials
docker login -u $DOCKER_USERNAME

# Check image exists
docker pull $DOCKER_REGISTRY/$DOCKER_USERNAME/basil-api:$IMAGE_TAG

Webhook Not Responding

# Check service status
sudo systemctl status basil-webhook

# Check if port is listening
sudo netstat -tlnp | grep 9000

# Check firewall
sudo ufw status

Health Check Fails

# Check API logs
docker-compose logs api

# Check API manually
curl http://localhost:3001/health

# Check database connection
docker-compose exec api npx prisma studio

Security Notes

  1. Never commit secrets: .env.deploy is gitignored
  2. Use strong webhook secret: 32+ character random string
  3. Firewall webhook port: Allow only from known IPs if possible
  4. Use HTTPS: Configure reverse proxy for webhook in production
  5. Backup before deploy: Script creates automatic backups

Directory Structure

scripts/
├── README.md                    # This file
├── deploy.sh                    # Main deployment script
├── manual-deploy.sh             # Interactive deployment
├── webhook-receiver.sh          # Webhook server
├── basil-webhook.service        # Systemd service file
└── webhook-config.json          # Generated webhook config (auto-created)

Parent directory:
├── .env.deploy                  # Deployment config (gitignored)
├── .env.deploy.example          # Example config
├── deploy.log                   # Deployment logs (gitignored)
├── webhook.log                  # Webhook logs (gitignored)
└── backups/                     # Automatic backups (gitignored)

References