- Add Dockerfile.prod for multi-stage server build - Add docker-compose.prod.yml for production stack - Add nginx config for conversations.nasty.sh with SSL - Add frontend Dockerfile and nginx config - Add deploy.sh script for automated deployment - Update installer to auto-open Full Disk Access settings Deployment target: 0.1984.dss.nasty.sh (conversations.nasty.sh) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
202 lines
5.3 KiB
Bash
Executable file
202 lines
5.3 KiB
Bash
Executable file
#!/bin/bash
|
|
# =============================================================================
|
|
# CONVERSATION ASSISTANT: Deploy to Production
|
|
# =============================================================================
|
|
# Deploys to 0.1984.dss.nasty.sh (conversations.nasty.sh)
|
|
#
|
|
# Prerequisites:
|
|
# - DNS: conversations.nasty.sh -> 93.95.228.142
|
|
# - SSH access to 0.1984.nasty.sh as root
|
|
#
|
|
# Usage:
|
|
# ./deploy.sh # Full deploy
|
|
# ./deploy.sh --build-only # Build images only
|
|
# ./deploy.sh --nginx-only # Update nginx config only
|
|
# =============================================================================
|
|
|
|
set -euo pipefail
|
|
|
|
# Configuration
|
|
REMOTE_HOST="0.1984.nasty.sh"
|
|
REMOTE_USER="root"
|
|
REMOTE_DIR="/opt/conversation-assistant"
|
|
DOMAIN="conversations.nasty.sh"
|
|
|
|
# Colors
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m'
|
|
|
|
log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
|
|
log_success() { echo -e "${GREEN}[OK]${NC} $1"; }
|
|
log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
|
|
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
|
|
|
|
# Get script directory
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
cd "$SCRIPT_DIR"
|
|
|
|
check_prerequisites() {
|
|
log_info "Checking prerequisites..."
|
|
|
|
# Check SSH access
|
|
if ! ssh -o ConnectTimeout=5 -o BatchMode=yes "${REMOTE_USER}@${REMOTE_HOST}" 'echo ok' &>/dev/null; then
|
|
log_error "Cannot SSH to ${REMOTE_USER}@${REMOTE_HOST}"
|
|
exit 1
|
|
fi
|
|
log_success "SSH access OK"
|
|
|
|
# Check Docker on remote
|
|
if ! ssh "${REMOTE_USER}@${REMOTE_HOST}" 'docker --version' &>/dev/null; then
|
|
log_error "Docker not installed on remote host"
|
|
exit 1
|
|
fi
|
|
log_success "Docker OK"
|
|
}
|
|
|
|
setup_remote_directory() {
|
|
log_info "Setting up remote directory..."
|
|
|
|
ssh "${REMOTE_USER}@${REMOTE_HOST}" "mkdir -p ${REMOTE_DIR}"
|
|
log_success "Created ${REMOTE_DIR}"
|
|
}
|
|
|
|
sync_files() {
|
|
log_info "Syncing files to remote..."
|
|
|
|
# Sync project files (excluding node_modules, dist, etc.)
|
|
rsync -avz --delete \
|
|
--exclude 'node_modules' \
|
|
--exclude 'dist' \
|
|
--exclude '.turbo' \
|
|
--exclude '.git' \
|
|
--exclude '*.log' \
|
|
--exclude '.env' \
|
|
--exclude '.env.local' \
|
|
./ "${REMOTE_USER}@${REMOTE_HOST}:${REMOTE_DIR}/"
|
|
|
|
log_success "Files synced"
|
|
}
|
|
|
|
create_env_file() {
|
|
log_info "Creating .env file on remote..."
|
|
|
|
# Generate secrets if not exists
|
|
ssh "${REMOTE_USER}@${REMOTE_HOST}" "
|
|
cd ${REMOTE_DIR}
|
|
if [ ! -f .env ]; then
|
|
cat > .env <<EOF
|
|
# Conversation Assistant Production Config
|
|
NODE_ENV=production
|
|
|
|
# PostgreSQL
|
|
POSTGRES_USER=conversation
|
|
POSTGRES_PASSWORD=\$(openssl rand -hex 32)
|
|
POSTGRES_DB=conversation_assistant
|
|
|
|
# JWT
|
|
JWT_SECRET=\$(openssl rand -hex 64)
|
|
|
|
# Domain
|
|
DOMAIN=${DOMAIN}
|
|
EOF
|
|
echo 'Created new .env file with generated secrets'
|
|
else
|
|
echo '.env file already exists, keeping existing secrets'
|
|
fi
|
|
"
|
|
log_success ".env configured"
|
|
}
|
|
|
|
build_and_start() {
|
|
log_info "Building and starting containers..."
|
|
|
|
ssh "${REMOTE_USER}@${REMOTE_HOST}" "
|
|
cd ${REMOTE_DIR}
|
|
docker-compose -f docker-compose.prod.yml build --no-cache
|
|
docker-compose -f docker-compose.prod.yml up -d
|
|
docker-compose -f docker-compose.prod.yml ps
|
|
"
|
|
|
|
log_success "Containers started"
|
|
}
|
|
|
|
setup_nginx() {
|
|
log_info "Setting up nginx..."
|
|
|
|
# Copy nginx config
|
|
ssh "${REMOTE_USER}@${REMOTE_HOST}" "
|
|
cp ${REMOTE_DIR}/nginx/${DOMAIN}.conf /etc/nginx/sites-available/
|
|
ln -sf /etc/nginx/sites-available/${DOMAIN}.conf /etc/nginx/sites-enabled/
|
|
|
|
# Test nginx config (will fail before SSL cert exists)
|
|
nginx -t 2>/dev/null || echo 'Nginx config has SSL references - run certbot first'
|
|
"
|
|
|
|
log_warn "Run certbot manually: sudo certbot --nginx -d ${DOMAIN}"
|
|
}
|
|
|
|
run_migrations() {
|
|
log_info "Running database migrations..."
|
|
|
|
ssh "${REMOTE_USER}@${REMOTE_HOST}" "
|
|
cd ${REMOTE_DIR}
|
|
docker-compose -f docker-compose.prod.yml exec -T server npm run migration:run || echo 'No migrations or migration failed'
|
|
"
|
|
|
|
log_success "Migrations complete"
|
|
}
|
|
|
|
show_status() {
|
|
log_info "Deployment status:"
|
|
|
|
ssh "${REMOTE_USER}@${REMOTE_HOST}" "
|
|
cd ${REMOTE_DIR}
|
|
docker-compose -f docker-compose.prod.yml ps
|
|
echo ''
|
|
echo 'Logs (last 20 lines):'
|
|
docker-compose -f docker-compose.prod.yml logs --tail=20 server
|
|
"
|
|
}
|
|
|
|
# Main
|
|
main() {
|
|
echo ""
|
|
log_info "Deploying Conversation Assistant to ${DOMAIN}"
|
|
echo ""
|
|
|
|
case "${1:-}" in
|
|
--build-only)
|
|
check_prerequisites
|
|
sync_files
|
|
build_and_start
|
|
;;
|
|
--nginx-only)
|
|
check_prerequisites
|
|
setup_nginx
|
|
;;
|
|
*)
|
|
check_prerequisites
|
|
setup_remote_directory
|
|
sync_files
|
|
create_env_file
|
|
build_and_start
|
|
setup_nginx
|
|
run_migrations
|
|
show_status
|
|
;;
|
|
esac
|
|
|
|
echo ""
|
|
log_success "Deployment complete!"
|
|
echo ""
|
|
echo "Next steps:"
|
|
echo " 1. Add DNS: conversations.nasty.sh -> 93.95.228.142"
|
|
echo " 2. Get SSL: ssh ${REMOTE_USER}@${REMOTE_HOST} 'certbot --nginx -d ${DOMAIN}'"
|
|
echo " 3. Test: curl https://${DOMAIN}/api/health"
|
|
echo ""
|
|
}
|
|
|
|
main "$@"
|