Dev Container Integration Summary
What Was Updated
Updated the VS Code Dev Container configuration to use our new environment merge system for consistent, maintainable environment setup.
Changes Made
1. Updated .devcontainer/devcontainer.json
Before:
"initializeCommand": [
"bash", "-c",
"cd ${localWorkspaceFolder} && cp .env.example .env"
]
After:
"initializeCommand": [
"bash", "-c",
"cd ${localWorkspaceFolder} && chmod +x bin/setup_env.sh bin/merge_env.sh && ./bin/setup_env.sh local"
]
2. Updated .devcontainer/install.sh
Before:
cp .env.example .env
cp config/database.example.yml config/database.yml
# ... other configs
After:
# Setup environment configuration using our merge system
# Note: ./bin/setup_env.sh local already ran in initializeCommand
# Just copy the other config files
cp config/database.example.yml config/database.yml
# ... other configs
3. Updated README.md
Added comprehensive Quick Start section with:
- Option 1: VS Code Dev Container (Recommended)
- Option 2: Manual Setup
Benefits for Developers
✅ Instant Development Environment
What happens when you open in dev container:
- Host machine:
./bin/setup_env.sh localsets up.envwith Docker service names - Container starts: All services (MySQL, Redis, Memcached, MongoDB) start automatically
- Dependencies installed: Ruby gems and npm packages installed
- Database ready: Schema loaded and ready to use
- Ready to code:
bundle exec rails serverworks immediately
✅ Consistent Environment
- No local dependencies: No need to install Ruby, Node.js, MySQL, Redis locally
- Same for everyone: All developers get identical environment
- Isolated: Won’t conflict with other projects
- Pre-configured: All services and configurations ready
✅ Smart Environment Configuration
The dev container automatically gets the correct configuration:
| Service | Dev Container Value | Why |
|---|---|---|
| MySQL | MYSQL_SERVER_HOST=db | Docker Compose service name |
| Redis | redis://valkey-lru:6382/2 | Docker Compose service name |
| Memcached | MEMCACHED_HOST=memcached | Docker Compose service name |
No manual configuration needed!
Developer Workflow
First Time Setup
# 1. Clone repository
git clone https://github.com/hungryhub-team/hh-server.git
cd hh-server
# 2. Open in VS Code
code .
# 3. Click "Reopen in Container" when prompted
# OR press Ctrl/Cmd+Shift+P → "Dev Containers: Reopen in Container"
# 4. Wait for automatic setup (2-3 minutes)
# 5. Start developing!
bundle exec rails server
Daily Development
# Container automatically starts all services
# Just run your Rails server and start coding!
bundle exec rails server
Comparison: Manual vs Dev Container
| Aspect | Manual Setup | Dev Container |
|---|---|---|
| Setup Time | 15-30 minutes | 2-3 minutes |
| Dependencies | Install Ruby, Node.js, MySQL, Redis locally | Nothing needed locally |
| Configuration | Multiple manual steps | Fully automatic |
| Consistency | Varies by developer machine | Identical for everyone |
| Isolation | May conflict with other projects | Completely isolated |
| Maintenance | Update dependencies manually | Container updates automatically |
Technical Details
Environment Configuration Flow
graph LR
A[Open in VS Code] --> B[initializeCommand runs]
B --> C[./bin/setup_env.sh local]
C --> D[Merges .env.example → .env]
D --> E[Container starts]
E --> F[Services start with Docker networking]
F --> G[install.sh runs]
G --> H[Dependencies installed]
H --> I[Database setup]
I --> J[Ready to develop!]
Docker Compose Integration
The dev container uses the same docker-compose.yml services as manual development:
- MySQL:
db:3306 - Redis LRU:
valkey-lru:6382 - Redis Persistence:
valkey-persistence:6380 - Redis Inventory:
valkey-inventory:6381 - Memcached:
memcached:11211 - MongoDB:
mongodb:27017
Our ./bin/setup_env.sh local automatically configures .env with these service names.
Troubleshooting
Common Issues
Issue: “Service connection failed” Solution:
# Check if services are running
docker-compose ps
# Verify environment configuration
grep "MYSQL_SERVER_HOST" .env # Should be "db"
Issue: “Scripts not executable”
Solution:
chmod +x bin/setup_env.sh bin/merge_env.sh
Issue: “Environment variables not set” Solution:
# Reset environment
./bin/setup_env.sh local
Future Enhancements
Potential improvements for the dev container setup:
- Pre-built images: Create pre-built Docker images for faster startup
- Environment variants: Support for
./bin/setup_env.sh stagingin dev container - Health checks: Add service health checks before starting Rails
- Auto-reload: Automatic restart when configuration changes
The current setup provides an excellent developer experience while maintaining flexibility and consistency across environments.