# Great Lakes Ice Report - Deployment Guide This guide covers both automated and manual deployment options for the Great Lakes Ice Report application. ## Prerequisites - **Server**: Debian 12 ARM64 (or compatible Linux distribution) - **Node.js**: Version 18 or higher - **Domain**: DNS pointing to your server - **Ports**: 80 and 443 open for web traffic ## Automated Deployment (Recommended) ### Quick Start 1. **Run the deployment script on your server:** ```bash curl -sSL https://ice-puremichigan-lol.s3.amazonaws.com/scripts/deploy.sh | bash ``` 2. **Clone and setup the application:** ```bash sudo git clone https://git.deco.sh/deco/ice.git /opt/icewatch cd /opt/icewatch sudo chown -R $USER:$USER /opt/icewatch npm install # This automatically builds CSS via postinstall npm run build:ts # Compile TypeScript to JavaScript ``` 3. **Configure environment variables:** ```bash cp .env.example .env nano .env # Add your API keys ``` 4. **Start services:** ```bash sudo systemctl enable icewatch sudo systemctl start icewatch sudo systemctl enable caddy sudo systemctl start caddy ``` ### What the Automated Script Does The deployment script automatically: 1. **System Updates**: Updates package repositories and system packages 2. **Node.js Installation**: Installs Node.js 20.x with build tools 3. **Go Installation**: Installs Go (required for building Caddy with plugins) 4. **Custom Caddy Build**: Builds Caddy with rate limiting plugin using xcaddy 5. **Service Configuration**: Creates systemd services for both the app and Caddy 6. **Security Setup**: Configures users, permissions, and security settings ## Manual Deployment ### 1. System Preparation ```bash # Update system sudo apt update && sudo apt upgrade -y # Install Node.js 20.x curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - sudo apt install -y nodejs build-essential # Install Git (if not already installed) sudo apt install -y git # Verify Node.js version (should be 18+ for TypeScript) node --version ``` ### 2. Install Go (for Custom Caddy) ```bash # Download and install Go wget -q https://go.dev/dl/go1.21.5.linux-arm64.tar.gz sudo rm -rf /usr/local/go sudo tar -C /usr/local -xzf go1.21.5.linux-arm64.tar.gz # Add to PATH export PATH=$PATH:/usr/local/go/bin echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc source ~/.bashrc ``` ### 3. Build Custom Caddy with Rate Limiting ```bash # Install xcaddy go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest export PATH=$PATH:$(go env GOPATH)/bin # Build Caddy with rate limiting plugin xcaddy build --with github.com/mholt/caddy-ratelimit # Install Caddy sudo mv caddy /usr/local/bin/caddy sudo chmod +x /usr/local/bin/caddy ``` ### 4. Create Users and Directories ```bash # Create Caddy user sudo groupadd --system caddy sudo useradd --system --gid caddy --create-home --home-dir /var/lib/caddy --shell /usr/sbin/nologin caddy # Create directories sudo mkdir -p /etc/caddy /var/log/caddy sudo chown -R caddy:caddy /var/log/caddy # Create app user sudo groupadd --system icewatch sudo useradd --system --gid icewatch --create-home --home-dir /opt/icewatch --shell /usr/sbin/nologin icewatch ``` ### 5. Deploy Application ```bash # Clone repository sudo git clone https://git.deco.sh/deco/ice.git /opt/icewatch cd /opt/icewatch # Set temporary ownership for installation sudo chown -R $USER:$USER /opt/icewatch # Install dependencies and build npm install # This automatically builds CSS npm run build:ts # Compile TypeScript to JavaScript # Create databases touch icewatch.db profanity.db # Set final ownership sudo chown -R icewatch:icewatch /opt/icewatch ``` ### 6. Configure Environment ```bash # Copy environment template sudo cp .env.example .env # Edit environment file sudo nano .env ``` **Required environment variables:** ```bash # MapBox API token (get free token at https://account.mapbox.com/access-tokens/) MAPBOX_ACCESS_TOKEN=pk.your_mapbox_token_here # Admin panel password ADMIN_PASSWORD=your_secure_password # Server port (default: 3000) PORT=3000 # Node environment NODE_ENV=production ``` ### 7. Configure Systemd Services **Create app service:** ```bash sudo cp scripts/icewatch.service /etc/systemd/system/ # Ensure the service file has the correct ExecStart: # ExecStart=/usr/bin/node dist/server.js ``` **Create Caddy service:** ```bash sudo tee /etc/systemd/system/caddy.service > /dev/null <