|
| 1 | +#!/bin/bash |
| 2 | +# ───────────────────────────────────────────── |
| 3 | +# JurisFind – Azure VM Bootstrap Script |
| 4 | +# |
| 5 | +# Run this once after SSH-ing into a fresh Ubuntu 22.04 VM: |
| 6 | +# chmod +x deploy.sh |
| 7 | +# sudo ./deploy.sh |
| 8 | +# |
| 9 | +# What it does: |
| 10 | +# 1. Installs Docker + Docker Compose |
| 11 | +# 2. Installs Nginx |
| 12 | +# 3. Clones/updates the repo |
| 13 | +# 4. Copies Nginx config and reloads |
| 14 | +# 5. Starts the API container via Docker Compose |
| 15 | +# ───────────────────────────────────────────── |
| 16 | + |
| 17 | +set -euo pipefail |
| 18 | + |
| 19 | +REPO_URL="https://github.com/YOUR_GITHUB_USERNAME/YOUR_REPO_NAME.git" |
| 20 | +APP_DIR="/opt/jurisfind" |
| 21 | +NGINX_CONF="/etc/nginx/sites-available/jurisfind" |
| 22 | + |
| 23 | +echo "════════════════════════════════════════" |
| 24 | +echo " JurisFind VM Setup" |
| 25 | +echo "════════════════════════════════════════" |
| 26 | + |
| 27 | +# ── 1. System update ───────────────────────── |
| 28 | +echo "[1/6] Updating system packages..." |
| 29 | +apt-get update -q && apt-get upgrade -y -q |
| 30 | + |
| 31 | +# ── 2. Install Docker ──────────────────────── |
| 32 | +echo "[2/6] Installing Docker..." |
| 33 | +if ! command -v docker &> /dev/null; then |
| 34 | + curl -fsSL https://get.docker.com | sh |
| 35 | + systemctl enable docker |
| 36 | + systemctl start docker |
| 37 | + # Allow current user to run docker without sudo |
| 38 | + usermod -aG docker "$SUDO_USER" || true |
| 39 | + echo "Docker installed. You may need to log out and back in for group changes." |
| 40 | +else |
| 41 | + echo "Docker already installed: $(docker --version)" |
| 42 | +fi |
| 43 | + |
| 44 | +# Docker Compose (v2 plugin) |
| 45 | +if ! docker compose version &> /dev/null; then |
| 46 | + apt-get install -y docker-compose-plugin |
| 47 | +fi |
| 48 | +echo "Docker Compose: $(docker compose version)" |
| 49 | + |
| 50 | +# ── 3. Install Nginx ───────────────────────── |
| 51 | +echo "[3/6] Installing Nginx..." |
| 52 | +apt-get install -y nginx |
| 53 | +systemctl enable nginx |
| 54 | +systemctl start nginx |
| 55 | + |
| 56 | +# ── 4. Clone / update repo ─────────────────── |
| 57 | +echo "[4/6] Setting up application directory..." |
| 58 | +if [ -d "$APP_DIR/.git" ]; then |
| 59 | + echo "Repo exists — pulling latest..." |
| 60 | + git -C "$APP_DIR" pull |
| 61 | +else |
| 62 | + echo "Cloning repo to $APP_DIR..." |
| 63 | + git clone "$REPO_URL" "$APP_DIR" |
| 64 | +fi |
| 65 | + |
| 66 | +# ── 5. Configure Nginx ─────────────────────── |
| 67 | +echo "[5/6] Configuring Nginx..." |
| 68 | +cp "$APP_DIR/nginx.conf" "$NGINX_CONF" |
| 69 | +ln -sf "$NGINX_CONF" /etc/nginx/sites-enabled/jurisfind |
| 70 | +rm -f /etc/nginx/sites-enabled/default |
| 71 | +nginx -t && systemctl reload nginx |
| 72 | +echo "Nginx configured and reloaded." |
| 73 | + |
| 74 | +# ── 6. Start API container ─────────────────── |
| 75 | +echo "[6/6] Starting JurisFind API container..." |
| 76 | + |
| 77 | +# Make sure .env exists |
| 78 | +if [ ! -f "$APP_DIR/api/.env" ]; then |
| 79 | + echo "" |
| 80 | + echo "⚠️ WARNING: $APP_DIR/api/.env not found!" |
| 81 | + echo " Copy api/.env.example → api/.env and fill in:" |
| 82 | + echo " GROQ_API_KEY" |
| 83 | + echo " AZURE_STORAGE_CONNECTION_STRING (if using Azure Blob)" |
| 84 | + echo " Then run: cd $APP_DIR && docker compose up -d --build" |
| 85 | + echo "" |
| 86 | +else |
| 87 | + cd "$APP_DIR" |
| 88 | + docker compose pull 2>/dev/null || true |
| 89 | + docker compose up -d --build |
| 90 | + echo "Container started. Check logs with: docker compose logs -f api" |
| 91 | +fi |
| 92 | + |
| 93 | +echo "" |
| 94 | +echo "════════════════════════════════════════" |
| 95 | +echo " Setup complete!" |
| 96 | +echo " API available at: http://$(curl -s ifconfig.me)/api/health" |
| 97 | +echo " API docs at: http://$(curl -s ifconfig.me)/docs" |
| 98 | +echo "" |
| 99 | +echo " Next steps:" |
| 100 | +echo " 1. Fill in $APP_DIR/api/.env with real keys" |
| 101 | +echo " 2. Open ports 80 and 443 in Azure Network Security Group" |
| 102 | +echo " 3. (Optional) Add SSL: sudo certbot --nginx -d yourdomain.com" |
| 103 | +echo "════════════════════════════════════════" |
0 commit comments