Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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:

  1. Host machine: ./bin/setup_env.sh local sets up .env with Docker service names
  2. Container starts: All services (MySQL, Redis, Memcached, MongoDB) start automatically
  3. Dependencies installed: Ruby gems and npm packages installed
  4. Database ready: Schema loaded and ready to use
  5. Ready to code: bundle exec rails server works 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:

ServiceDev Container ValueWhy
MySQLMYSQL_SERVER_HOST=dbDocker Compose service name
Redisredis://valkey-lru:6382/2Docker Compose service name
MemcachedMEMCACHED_HOST=memcachedDocker 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

AspectManual SetupDev Container
Setup Time15-30 minutes2-3 minutes
DependenciesInstall Ruby, Node.js, MySQL, Redis locallyNothing needed locally
ConfigurationMultiple manual stepsFully automatic
ConsistencyVaries by developer machineIdentical for everyone
IsolationMay conflict with other projectsCompletely isolated
MaintenanceUpdate dependencies manuallyContainer 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:

  1. Pre-built images: Create pre-built Docker images for faster startup
  2. Environment variants: Support for ./bin/setup_env.sh staging in dev container
  3. Health checks: Add service health checks before starting Rails
  4. Auto-reload: Automatic restart when configuration changes

The current setup provides an excellent developer experience while maintaining flexibility and consistency across environments.