diff --git a/.devcontainer/README.md b/.devcontainer/README.md new file mode 100644 index 0000000..202e8b0 --- /dev/null +++ b/.devcontainer/README.md @@ -0,0 +1,319 @@ +# Development Container Configuration + +This directory contains the configuration for the VS Code Development Container (dev container) that provides a fully-configured development environment for the Unthread Webhook Server project. + +## 🚀 Quick Start + +### Prerequisites +1. [Docker Desktop](https://www.docker.com/products/docker-desktop) installed and running +2. [Visual Studio Code](https://code.visualstudio.com/) installed +3. [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) installed in VS Code + +### Starting the Dev Container + +1. **Open the project in VS Code** + ```bash + code /path/to/unthread-webhook-server + ``` + +2. **Reopen in container** + - VS Code should show a notification: "Folder contains a Dev Container configuration file" + - Click "Reopen in Container" + - OR use Command Palette (F1): "Dev Containers: Reopen in Container" + +3. **Wait for setup to complete** + - First-time setup takes 3-5 minutes (downloads images, installs dependencies) + - Subsequent startups are much faster (30-60 seconds) + +## đŸ“Ļ What's Included + +### Core Tools +- **Node.js 22.16 LTS** - Matching production environment +- **pnpm** - Primary package manager (installed globally) +- **npm** - For global package installations +- **yarn** - Legacy compatibility (pre-installed in base image) +- **TypeScript** - Via project dependencies +- **ts-node** - For running TypeScript directly +- **nodemon** - For development with auto-reload + +### GitHub Tools +- **GitHub CLI (gh)** - Latest version +- **GitHub Copilot CLI** - Installed via both methods: + - `gh extension install github/gh-copilot` (gh extension) + - `npm install -g @github/copilot` (npm package) +- **Copilot Aliases** (configured in shell): + - `ghcs` → `gh copilot suggest` + - `ghce` → `gh copilot explain` + +### Development Tools +- **Git** - Latest version with credential forwarding +- **curl & wget** - Network utilities +- **redis-cli** - For Redis debugging and testing +- **Zsh + Oh My Zsh** - Enhanced shell experience + +### VS Code Extensions + +#### GitHub & Copilot +- GitHub Copilot (`github.copilot`) +- GitHub Copilot Chat (`github.copilot-chat`) +- GitHub Pull Requests (`github.vscode-pull-request-github`) + +#### TypeScript & Node.js +- ESLint (`dbaeumer.vscode-eslint`) +- npm Intellisense (`christian-kohler.npm-intellisense`) +- Path Intellisense (`christian-kohler.path-intellisense`) + +#### Code Quality +- Error Lens (`usernamehw.errorlens`) +- Better Comments (`aaron-bond.better-comments`) +- Prettier (`esbenp.prettier-vscode`) +- EditorConfig (`editorconfig.editorconfig`) + +#### Docker & Git +- Docker (`ms-azuretools.vscode-docker`) +- GitLens (`eamodio.gitlens`) + +## 🔧 Configuration Files + +### `devcontainer.json` +Main configuration file that defines: +- Base image and features +- VS Code extensions and settings +- Port forwarding +- Post-creation commands + +### `docker-compose.override.yml` +Overrides for the main `docker-compose.yml`: +- Mounts workspace for live development +- Keeps container running with `sleep infinity` +- Sets appropriate environment variables + +## 🌐 Port Forwarding + +The dev container automatically forwards these ports: + +| Port | Service | Auto-Forward Behavior | +|------|---------|----------------------| +| 3000 | Webhook Server | Notify on forward | +| 6379 | Redis | Silent (background service) | + +Access forwarded ports: +- Webhook Server: `http://localhost:3000` +- Redis: `localhost:6379` (use redis-cli) + +## đŸ› ī¸ Development Workflow + +### Starting Development + +1. **Install dependencies** (automatic on first start) + ```bash + pnpm install + ``` + +2. **Copy environment file** (if not done) + ```bash + cp .env.example .env + # Edit .env with your configuration + ``` + +3. **Start development server** + ```bash + pnpm dev + ``` + +### Available Commands + +```bash +# Package management +pnpm install # Install dependencies +pnpm add # Add a package + +# Development +pnpm dev # Start with auto-reload +pnpm build # Build for production +pnpm start # Run production build +pnpm type-check # TypeScript type checking +pnpm clean # Clean build artifacts + +# Redis operations +redis-cli # Connect to Redis +redis-cli ping # Test Redis connection +redis-cli KEYS '*' # List all keys +redis-cli FLUSHALL # Clear all data (use with caution!) + +# GitHub Copilot +gh copilot suggest # Get command suggestions (or: ghcs) +gh copilot explain # Explain commands (or: ghce) +copilot # Alternative copilot command +``` + +### Working with Docker + +The dev container runs alongside Redis in a Docker Compose stack: + +```bash +# View running containers +docker ps + +# Check Redis logs +docker logs unthread-webhook-server-redis-webhook-1 + +# Execute commands in Redis container +docker exec -it unthread-webhook-server-redis-webhook-1 redis-cli + +# Restart Redis (from host machine, not in dev container) +docker-compose restart redis-webhook +``` + +## 🔐 Environment Variables + +The dev container uses the same `.env` file as local development: + +```bash +# Required variables +UNTHREAD_WEBHOOK_SECRET=your_secret_here +TARGET_PLATFORM=telegram +PORT=3000 +REDIS_URL=redis://redis-webhook:6379 # Use docker-compose service name +``` + +**Note:** The `REDIS_URL` should point to `redis-webhook` (the Docker Compose service name) instead of `localhost` when running in the dev container. + +## 🐛 Troubleshooting + +### Container won't start +```bash +# Rebuild the container +# In VS Code: F1 → "Dev Containers: Rebuild Container" +# OR from terminal: +docker-compose down +docker-compose up --build -d +``` + +### Dependencies not installing +```bash +# Manually install +pnpm install + +# Clear cache and reinstall +rm -rf node_modules pnpm-lock.yaml +pnpm install +``` + +### Redis connection issues +```bash +# Test Redis connectivity +redis-cli -h redis-webhook ping + +# Check if Redis is running +docker ps | grep redis + +# Check Redis logs +docker logs unthread-webhook-server-redis-webhook-1 +``` + +### GitHub Copilot not working +```bash +# Reinstall Copilot CLI +gh extension remove github/gh-copilot +gh extension install github/gh-copilot + +# OR reinstall npm package +npm uninstall -g @github/copilot +npm install -g @github/copilot + +# Authenticate with GitHub +gh auth login +``` + +### Port already in use +```bash +# Change port in .env +PORT=3001 # or any available port + +# Or stop conflicting services on host +lsof -ti:3000 | xargs kill -9 # macOS/Linux +``` + +## 🔄 Rebuilding the Container + +When you update dependencies or configuration: + +1. **Rebuild without cache** + - VS Code: F1 → "Dev Containers: Rebuild Container Without Cache" + +2. **Rebuild with cache** (faster) + - VS Code: F1 → "Dev Containers: Rebuild Container" + +3. **From command line** (on host machine) + ```bash + docker-compose down + docker-compose build --no-cache + docker-compose up -d + ``` + +## 📝 Customization + +### Adding VS Code Extensions + +Edit `devcontainer.json`: +```json +{ + "customizations": { + "vscode": { + "extensions": [ + "existing.extension", + "your.new-extension" + ] + } + } +} +``` + +### Adding System Packages + +Edit `devcontainer.json` to add features or use `postCreateCommand`: +```json +{ + "postCreateCommand": "sudo apt-get update && sudo apt-get install -y your-package" +} +``` + +### Changing Shell Configuration + +Oh My Zsh is installed by default. Customize in `~/.zshrc`: +```bash +# Edit your shell config +nano ~/.zshrc +``` + +## đŸŽ¯ Tips & Best Practices + +1. **Use pnpm for consistency** - The project is migrating from yarn to pnpm +2. **Keep .env updated** - Don't commit secrets to version control +3. **Leverage Copilot** - Use `ghcs` and `ghce` for CLI help +4. **Monitor Redis** - Use `redis-cli` to debug webhook processing +5. **Use Zsh features** - Tab completion, syntax highlighting, etc. +6. **Git credentials** - Forwarded from host, no need to reconfigure + +## 🔗 Resources + +- [VS Code Dev Containers Documentation](https://code.visualstudio.com/docs/devcontainers/containers) +- [Docker Documentation](https://docs.docker.com/) +- [pnpm Documentation](https://pnpm.io/) +- [GitHub Copilot CLI](https://githubnext.com/projects/copilot-cli) +- [Project README](../README.md) +- [Contributing Guide](../CONTRIBUTING.md) + +## 🆘 Getting Help + +If you encounter issues: + +1. Check this README for troubleshooting steps +2. Review the [main README](../README.md) +3. Check [CONTRIBUTING.md](../CONTRIBUTING.md) for development guidelines +4. Open an issue on GitHub with dev container logs + +--- + +**Happy coding! 🚀** diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..4e04754 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,66 @@ +{ + "name": "Unthread Webhook Server", + "dockerComposeFile": [ + "../docker-compose.yml", + "docker-compose.override.yml" + ], + "service": "server", + "workspaceFolder": "/workspaces/unthread-webhook-server", + + "features": { + "ghcr.io/devcontainers/features/node:1": { + "version": "22.16", + "nodeGypDependencies": true, + "installYarnUsingApt": false + }, + "ghcr.io/devcontainers/features/github-cli:1": { + "version": "latest" + }, + "ghcr.io/devcontainers/features/common-utils:2": { + "installZsh": true, + "configureZshAsDefaultShell": true, + "installOhMyZsh": true + } + }, + + "customizations": { + "vscode": { + "extensions": [ + "github.copilot", + "github.copilot-chat", + "github.vscode-pull-request-github", + "dbaeumer.vscode-eslint", + "ms-azuretools.vscode-docker", + "eamodio.gitlens", + "usernamehw.errorlens", + "aaron-bond.better-comments", + "esbenp.prettier-vscode", + "editorconfig.editorconfig", + "christian-kohler.npm-intellisense", + "christian-kohler.path-intellisense" + ], + "settings": { + "terminal.integrated.defaultProfile.linux": "zsh", + "editor.formatOnSave": true, + "editor.codeActionsOnSave": { + "source.fixAll.eslint": true + }, + "typescript.tsdk": "node_modules/typescript/lib" + } + } + }, + + "postCreateCommand": "bash .devcontainer/setup.sh", + + "forwardPorts": [3000, 6379], + "portsAttributes": { + "3000": { + "label": "Webhook Server", + "onAutoForward": "notify" + }, + "6379": { + "label": "Redis", + "onAutoForward": "silent" + } + } +} diff --git a/.devcontainer/docker-compose.override.yml b/.devcontainer/docker-compose.override.yml new file mode 100644 index 0000000..5a56cd3 --- /dev/null +++ b/.devcontainer/docker-compose.override.yml @@ -0,0 +1,15 @@ +# ============================================================================= +# DEV CONTAINER DOCKER COMPOSE OVERRIDE +# ============================================================================= +# This file is used by the dev container to override the default docker-compose +# configuration. It keeps the container running and sets the correct environment. +# The dev container features will be applied automatically to this service. +# ============================================================================= + +services: + server: + # Keep container running for dev container + command: sleep infinity + # Override environment for dev container + environment: + - REDIS_URL=redis://redis-webhook:6379 diff --git a/.devcontainer/setup.sh b/.devcontainer/setup.sh new file mode 100755 index 0000000..c43ae92 --- /dev/null +++ b/.devcontainer/setup.sh @@ -0,0 +1,124 @@ +#!/bin/bash +# ============================================================================= +# Dev Container Post-Create Setup Script +# ============================================================================= +# This script runs after the dev container is created to set up the development +# environment with all necessary tools and configurations. +# ============================================================================= + +set -e + +echo "🚀 Starting dev container setup..." + +# ============================================================================= +# 1. Install pnpm (Primary Package Manager) +# ============================================================================= +echo "đŸ“Ļ Installing pnpm..." +npm install -g pnpm + +# ============================================================================= +# 2. Install Project Dependencies +# ============================================================================= +echo "📚 Installing project dependencies with pnpm..." +pnpm install + +# ============================================================================= +# 3. Install GitHub Copilot CLI (Method 1: gh extension) +# ============================================================================= +echo "🤖 Installing GitHub Copilot CLI (gh extension)..." +gh extension install github/gh-copilot 2>/dev/null || echo " â„šī¸ GitHub Copilot extension already installed or failed to install" + +# ============================================================================= +# 4. Install GitHub Copilot CLI (Method 2: npm package) +# ============================================================================= +echo "🤖 Installing GitHub Copilot CLI (npm package)..." +npm install -g @github/copilot 2>/dev/null || echo " â„šī¸ GitHub Copilot npm package already installed or failed to install" + +# ============================================================================= +# 5. Set Up Shell Aliases for Copilot CLI +# ============================================================================= +echo "⚡ Setting up shell aliases for GitHub Copilot CLI..." + +# Add aliases to .zshrc if they don't exist +if ! grep -qF 'alias ghcs="gh copilot suggest"' ~/.zshrc 2>/dev/null; then + echo 'alias ghcs="gh copilot suggest"' >> ~/.zshrc + echo " ✓ Added ghcs alias" +fi + +if ! grep -qF 'alias ghce="gh copilot explain"' ~/.zshrc 2>/dev/null; then + echo 'alias ghce="gh copilot explain"' >> ~/.zshrc + echo " ✓ Added ghce alias" +fi + +# ============================================================================= +# 6. Install Redis CLI Tools +# ============================================================================= +echo "🔧 Checking for Redis CLI..." +if ! command -v redis-cli &> /dev/null; then + echo " Installing Redis CLI tools..." + sudo apt-get update -qq + sudo apt-get install -y redis-tools + echo " ✓ Redis CLI installed" +else + echo " ✓ Redis CLI already available" +fi + +# ============================================================================= +# 7. Verify Installation +# ============================================================================= +echo "" +echo "🔍 Verifying installations..." + +# Check Node.js +NODE_VERSION=$(node --version) +echo " ✓ Node.js: $NODE_VERSION" + +# Check pnpm +PNPM_VERSION=$(pnpm --version) +echo " ✓ pnpm: $PNPM_VERSION" + +# Check GitHub CLI +GH_VERSION=$(gh --version | head -1) +echo " ✓ GitHub CLI: $GH_VERSION" + +# Check Redis CLI +REDIS_CLI_VERSION=$(redis-cli --version) +echo " ✓ Redis CLI: $REDIS_CLI_VERSION" + +# Check if Copilot extension is installed +if gh extension list | grep -q copilot; then + echo " ✓ GitHub Copilot CLI extension: installed" +else + echo " âš ī¸ GitHub Copilot CLI extension: not installed (may require authentication)" +fi + +# ============================================================================= +# 8. Environment Setup +# ============================================================================= +echo "" +echo "🌍 Checking environment configuration..." + +if [ ! -f .env ]; then + echo " â„šī¸ Creating .env from .env.example..." + cp .env.example .env + echo " âš ī¸ Please update .env with your configuration values" +else + echo " ✓ .env file already exists" +fi + +# ============================================================================= +# Setup Complete +# ============================================================================= +echo "" +echo "✅ Dev container setup complete!" +echo "" +echo "📝 Next steps:" +echo " 1. Update .env with your configuration values" +echo " 2. Authenticate with GitHub: gh auth login" +echo " 3. Start development: pnpm dev" +echo "" +echo "💡 Helpful aliases:" +echo " ghcs - Get command suggestions from GitHub Copilot" +echo " ghce - Explain commands with GitHub Copilot" +echo "" +echo "🎉 Happy coding!" diff --git a/README.md b/README.md index cb748a5..4425b4b 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,35 @@ docker-compose down - `.env.example` - Template with default values - `.env.railway` - Railway deployment template +## đŸ—ī¸ Development Container + +This project includes a pre-configured development container with all necessary tools for an optimal development experience. + +### Quick Start +1. Install [Docker Desktop](https://www.docker.com/products/docker-desktop) +2. Install [VS Code](https://code.visualstudio.com/) with the [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) +3. Open project in VS Code +4. Click "Reopen in Container" when prompted (or use Command Palette: "Dev Containers: Reopen in Container") + +### Included Tools +- **Node.js 22.16 LTS** - Matching production environment +- **pnpm** - Primary package manager (latest stable) +- **GitHub Copilot CLI** - Both gh extension and npm package + - Use `ghcs` for command suggestions + - Use `ghce` for command explanations +- **TypeScript, ts-node, nodemon** - Development tools +- **Redis CLI** - For debugging Redis operations +- **Zsh + Oh My Zsh** - Enhanced shell experience +- **All essential VS Code extensions** - Copilot, ESLint, Docker, GitLens, and more + +### Benefits +- **Consistency**: Identical environment for all developers +- **Speed**: Pre-configured tools, start coding immediately +- **AI-Powered**: GitHub Copilot CLI ready out of the box +- **Isolated**: No conflicts with host machine setup + +For detailed documentation, see [`.devcontainer/README.md`](.devcontainer/README.md). + ## âš™ī¸ Configuration ### Environment Variables