|
| 1 | +# Development Container Configuration |
| 2 | + |
| 3 | +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. |
| 4 | + |
| 5 | +## 🚀 Quick Start |
| 6 | + |
| 7 | +### Prerequisites |
| 8 | +1. [Docker Desktop](https://www.docker.com/products/docker-desktop) installed and running |
| 9 | +2. [Visual Studio Code](https://code.visualstudio.com/) installed |
| 10 | +3. [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) installed in VS Code |
| 11 | + |
| 12 | +### Starting the Dev Container |
| 13 | + |
| 14 | +1. **Open the project in VS Code** |
| 15 | + ```bash |
| 16 | + code /path/to/unthread-webhook-server |
| 17 | + ``` |
| 18 | + |
| 19 | +2. **Reopen in container** |
| 20 | + - VS Code should show a notification: "Folder contains a Dev Container configuration file" |
| 21 | + - Click "Reopen in Container" |
| 22 | + - OR use Command Palette (F1): "Dev Containers: Reopen in Container" |
| 23 | + |
| 24 | +3. **Wait for setup to complete** |
| 25 | + - First-time setup takes 3-5 minutes (downloads images, installs dependencies) |
| 26 | + - Subsequent startups are much faster (30-60 seconds) |
| 27 | + |
| 28 | +## 📦 What's Included |
| 29 | + |
| 30 | +### Core Tools |
| 31 | +- **Node.js 22.16 LTS** - Matching production environment |
| 32 | +- **pnpm** - Primary package manager (installed globally) |
| 33 | +- **npm** - For global package installations |
| 34 | +- **yarn** - Legacy compatibility (pre-installed in base image) |
| 35 | +- **TypeScript** - Via project dependencies |
| 36 | +- **ts-node** - For running TypeScript directly |
| 37 | +- **nodemon** - For development with auto-reload |
| 38 | + |
| 39 | +### GitHub Tools |
| 40 | +- **GitHub CLI (gh)** - Latest version |
| 41 | +- **GitHub Copilot CLI** - Installed via both methods: |
| 42 | + - `gh extension install github/gh-copilot` (gh extension) |
| 43 | + - `npm install -g @github/copilot` (npm package) |
| 44 | +- **Copilot Aliases** (configured in shell): |
| 45 | + - `ghcs` → `gh copilot suggest` |
| 46 | + - `ghce` → `gh copilot explain` |
| 47 | + |
| 48 | +### Development Tools |
| 49 | +- **Git** - Latest version with credential forwarding |
| 50 | +- **curl & wget** - Network utilities |
| 51 | +- **redis-cli** - For Redis debugging and testing |
| 52 | +- **Zsh + Oh My Zsh** - Enhanced shell experience |
| 53 | + |
| 54 | +### VS Code Extensions |
| 55 | + |
| 56 | +#### GitHub & Copilot |
| 57 | +- GitHub Copilot (`github.copilot`) |
| 58 | +- GitHub Copilot Chat (`github.copilot-chat`) |
| 59 | +- GitHub Pull Requests (`github.vscode-pull-request-github`) |
| 60 | + |
| 61 | +#### TypeScript & Node.js |
| 62 | +- ESLint (`dbaeumer.vscode-eslint`) |
| 63 | +- npm Intellisense (`christian-kohler.npm-intellisense`) |
| 64 | +- Path Intellisense (`christian-kohler.path-intellisense`) |
| 65 | + |
| 66 | +#### Code Quality |
| 67 | +- Error Lens (`usernamehw.errorlens`) |
| 68 | +- Better Comments (`aaron-bond.better-comments`) |
| 69 | +- Prettier (`esbenp.prettier-vscode`) |
| 70 | +- EditorConfig (`editorconfig.editorconfig`) |
| 71 | + |
| 72 | +#### Docker & Git |
| 73 | +- Docker (`ms-azuretools.vscode-docker`) |
| 74 | +- GitLens (`eamodio.gitlens`) |
| 75 | + |
| 76 | +## 🔧 Configuration Files |
| 77 | + |
| 78 | +### `devcontainer.json` |
| 79 | +Main configuration file that defines: |
| 80 | +- Base image and features |
| 81 | +- VS Code extensions and settings |
| 82 | +- Port forwarding |
| 83 | +- Post-creation commands |
| 84 | + |
| 85 | +### `docker-compose.override.yml` |
| 86 | +Overrides for the main `docker-compose.yml`: |
| 87 | +- Mounts workspace for live development |
| 88 | +- Keeps container running with `sleep infinity` |
| 89 | +- Sets appropriate environment variables |
| 90 | + |
| 91 | +## 🌐 Port Forwarding |
| 92 | + |
| 93 | +The dev container automatically forwards these ports: |
| 94 | + |
| 95 | +| Port | Service | Auto-Forward Behavior | |
| 96 | +|------|---------|----------------------| |
| 97 | +| 3000 | Webhook Server | Notify on forward | |
| 98 | +| 6379 | Redis | Silent (background service) | |
| 99 | + |
| 100 | +Access forwarded ports: |
| 101 | +- Webhook Server: `http://localhost:3000` |
| 102 | +- Redis: `localhost:6379` (use redis-cli) |
| 103 | + |
| 104 | +## 🛠️ Development Workflow |
| 105 | + |
| 106 | +### Starting Development |
| 107 | + |
| 108 | +1. **Install dependencies** (automatic on first start) |
| 109 | + ```bash |
| 110 | + pnpm install |
| 111 | + ``` |
| 112 | + |
| 113 | +2. **Copy environment file** (if not done) |
| 114 | + ```bash |
| 115 | + cp .env.example .env |
| 116 | + # Edit .env with your configuration |
| 117 | + ``` |
| 118 | + |
| 119 | +3. **Start development server** |
| 120 | + ```bash |
| 121 | + pnpm dev |
| 122 | + ``` |
| 123 | + |
| 124 | +### Available Commands |
| 125 | + |
| 126 | +```bash |
| 127 | +# Package management |
| 128 | +pnpm install # Install dependencies |
| 129 | +pnpm add <package> # Add a package |
| 130 | + |
| 131 | +# Development |
| 132 | +pnpm dev # Start with auto-reload |
| 133 | +pnpm build # Build for production |
| 134 | +pnpm start # Run production build |
| 135 | +pnpm type-check # TypeScript type checking |
| 136 | +pnpm clean # Clean build artifacts |
| 137 | + |
| 138 | +# Redis operations |
| 139 | +redis-cli # Connect to Redis |
| 140 | +redis-cli ping # Test Redis connection |
| 141 | +redis-cli KEYS '*' # List all keys |
| 142 | +redis-cli FLUSHALL # Clear all data (use with caution!) |
| 143 | + |
| 144 | +# GitHub Copilot |
| 145 | +gh copilot suggest # Get command suggestions (or: ghcs) |
| 146 | +gh copilot explain # Explain commands (or: ghce) |
| 147 | +copilot # Alternative copilot command |
| 148 | +``` |
| 149 | + |
| 150 | +### Working with Docker |
| 151 | + |
| 152 | +The dev container runs alongside Redis in a Docker Compose stack: |
| 153 | + |
| 154 | +```bash |
| 155 | +# View running containers |
| 156 | +docker ps |
| 157 | + |
| 158 | +# Check Redis logs |
| 159 | +docker logs unthread-webhook-server-redis-webhook-1 |
| 160 | + |
| 161 | +# Execute commands in Redis container |
| 162 | +docker exec -it unthread-webhook-server-redis-webhook-1 redis-cli |
| 163 | + |
| 164 | +# Restart Redis (from host machine, not in dev container) |
| 165 | +docker-compose restart redis-webhook |
| 166 | +``` |
| 167 | + |
| 168 | +## 🔐 Environment Variables |
| 169 | + |
| 170 | +The dev container uses the same `.env` file as local development: |
| 171 | + |
| 172 | +```bash |
| 173 | +# Required variables |
| 174 | +UNTHREAD_WEBHOOK_SECRET=your_secret_here |
| 175 | +TARGET_PLATFORM=telegram |
| 176 | +PORT=3000 |
| 177 | +REDIS_URL=redis://redis-webhook:6379 # Use docker-compose service name |
| 178 | +``` |
| 179 | + |
| 180 | +**Note:** The `REDIS_URL` should point to `redis-webhook` (the Docker Compose service name) instead of `localhost` when running in the dev container. |
| 181 | + |
| 182 | +## 🐛 Troubleshooting |
| 183 | + |
| 184 | +### Container won't start |
| 185 | +```bash |
| 186 | +# Rebuild the container |
| 187 | +# In VS Code: F1 → "Dev Containers: Rebuild Container" |
| 188 | +# OR from terminal: |
| 189 | +docker-compose down |
| 190 | +docker-compose up --build -d |
| 191 | +``` |
| 192 | + |
| 193 | +### Dependencies not installing |
| 194 | +```bash |
| 195 | +# Manually install |
| 196 | +pnpm install |
| 197 | + |
| 198 | +# Clear cache and reinstall |
| 199 | +rm -rf node_modules pnpm-lock.yaml |
| 200 | +pnpm install |
| 201 | +``` |
| 202 | + |
| 203 | +### Redis connection issues |
| 204 | +```bash |
| 205 | +# Test Redis connectivity |
| 206 | +redis-cli -h redis-webhook ping |
| 207 | + |
| 208 | +# Check if Redis is running |
| 209 | +docker ps | grep redis |
| 210 | + |
| 211 | +# Check Redis logs |
| 212 | +docker logs unthread-webhook-server-redis-webhook-1 |
| 213 | +``` |
| 214 | + |
| 215 | +### GitHub Copilot not working |
| 216 | +```bash |
| 217 | +# Reinstall Copilot CLI |
| 218 | +gh extension remove github/gh-copilot |
| 219 | +gh extension install github/gh-copilot |
| 220 | + |
| 221 | +# OR reinstall npm package |
| 222 | +npm uninstall -g @github/copilot |
| 223 | +npm install -g @github/copilot |
| 224 | + |
| 225 | +# Authenticate with GitHub |
| 226 | +gh auth login |
| 227 | +``` |
| 228 | + |
| 229 | +### Port already in use |
| 230 | +```bash |
| 231 | +# Change port in .env |
| 232 | +PORT=3001 # or any available port |
| 233 | + |
| 234 | +# Or stop conflicting services on host |
| 235 | +lsof -ti:3000 | xargs kill -9 # macOS/Linux |
| 236 | +``` |
| 237 | + |
| 238 | +## 🔄 Rebuilding the Container |
| 239 | + |
| 240 | +When you update dependencies or configuration: |
| 241 | + |
| 242 | +1. **Rebuild without cache** |
| 243 | + - VS Code: F1 → "Dev Containers: Rebuild Container Without Cache" |
| 244 | + |
| 245 | +2. **Rebuild with cache** (faster) |
| 246 | + - VS Code: F1 → "Dev Containers: Rebuild Container" |
| 247 | + |
| 248 | +3. **From command line** (on host machine) |
| 249 | + ```bash |
| 250 | + docker-compose down |
| 251 | + docker-compose build --no-cache |
| 252 | + docker-compose up -d |
| 253 | + ``` |
| 254 | + |
| 255 | +## 📝 Customization |
| 256 | + |
| 257 | +### Adding VS Code Extensions |
| 258 | + |
| 259 | +Edit `devcontainer.json`: |
| 260 | +```json |
| 261 | +{ |
| 262 | + "customizations": { |
| 263 | + "vscode": { |
| 264 | + "extensions": [ |
| 265 | + "existing.extension", |
| 266 | + "your.new-extension" |
| 267 | + ] |
| 268 | + } |
| 269 | + } |
| 270 | +} |
| 271 | +``` |
| 272 | + |
| 273 | +### Adding System Packages |
| 274 | + |
| 275 | +Edit `devcontainer.json` to add features or use `postCreateCommand`: |
| 276 | +```json |
| 277 | +{ |
| 278 | + "postCreateCommand": "sudo apt-get update && sudo apt-get install -y your-package" |
| 279 | +} |
| 280 | +``` |
| 281 | + |
| 282 | +### Changing Shell Configuration |
| 283 | + |
| 284 | +Oh My Zsh is installed by default. Customize in `~/.zshrc`: |
| 285 | +```bash |
| 286 | +# Edit your shell config |
| 287 | +nano ~/.zshrc |
| 288 | +``` |
| 289 | + |
| 290 | +## 🎯 Tips & Best Practices |
| 291 | + |
| 292 | +1. **Use pnpm for consistency** - The project is migrating from yarn to pnpm |
| 293 | +2. **Keep .env updated** - Don't commit secrets to version control |
| 294 | +3. **Leverage Copilot** - Use `ghcs` and `ghce` for CLI help |
| 295 | +4. **Monitor Redis** - Use `redis-cli` to debug webhook processing |
| 296 | +5. **Use Zsh features** - Tab completion, syntax highlighting, etc. |
| 297 | +6. **Git credentials** - Forwarded from host, no need to reconfigure |
| 298 | + |
| 299 | +## 🔗 Resources |
| 300 | + |
| 301 | +- [VS Code Dev Containers Documentation](https://code.visualstudio.com/docs/devcontainers/containers) |
| 302 | +- [Docker Documentation](https://docs.docker.com/) |
| 303 | +- [pnpm Documentation](https://pnpm.io/) |
| 304 | +- [GitHub Copilot CLI](https://githubnext.com/projects/copilot-cli) |
| 305 | +- [Project README](../README.md) |
| 306 | +- [Contributing Guide](../CONTRIBUTING.md) |
| 307 | + |
| 308 | +## 🆘 Getting Help |
| 309 | + |
| 310 | +If you encounter issues: |
| 311 | + |
| 312 | +1. Check this README for troubleshooting steps |
| 313 | +2. Review the [main README](../README.md) |
| 314 | +3. Check [CONTRIBUTING.md](../CONTRIBUTING.md) for development guidelines |
| 315 | +4. Open an issue on GitHub with dev container logs |
| 316 | + |
| 317 | +--- |
| 318 | + |
| 319 | +**Happy coding! 🚀** |
0 commit comments