fix: resolve .env.local not loading in docker compose
Fixes issue #1827 where Docker Compose wasn't properly loading .env.local file. Problem: - Docker Compose expects .env file for variable substitution but docs say to use .env.local - This caused environment variables to not be loaded in Docker containers Solution: - Updated docker-compose.yaml to load both .env and .env.local files - Created setup-env.sh script to help users sync .env.local to .env - Updated documentation with clear instructions for Docker users - Maintains backward compatibility with existing setups Changes: - Modified docker-compose.yaml to use array syntax for env_file - Added scripts/setup-env.sh helper script - Updated CONTRIBUTING.md and index.md documentation This ensures environment variables work correctly in Docker while maintaining the security best practice of using .env.local for sensitive data. Contributed by: Keoma Wright
This commit is contained in:
@@ -7,7 +7,9 @@ services:
|
||||
target: bolt-ai-production
|
||||
ports:
|
||||
- '5173:5173'
|
||||
env_file: '.env.local'
|
||||
env_file:
|
||||
- '.env'
|
||||
- '.env.local'
|
||||
environment:
|
||||
- NODE_ENV=production
|
||||
- COMPOSE_PROFILES=production
|
||||
@@ -37,7 +39,9 @@ services:
|
||||
image: bolt-ai:development
|
||||
build:
|
||||
target: bolt-ai-development
|
||||
env_file: '.env.local'
|
||||
env_file:
|
||||
- '.env'
|
||||
- '.env.local'
|
||||
environment:
|
||||
- NODE_ENV=development
|
||||
- VITE_HMR_PROTOCOL=ws
|
||||
|
||||
@@ -95,11 +95,20 @@ Interested in maintaining and growing the project? Fill out our [Contributor App
|
||||
OPENAI_API_KEY=XXX
|
||||
...
|
||||
```
|
||||
3. Optionally set:
|
||||
3. **For Docker users**: Run the setup script or manually copy `.env.local` to `.env`:
|
||||
```bash
|
||||
# Option 1: Use the setup script
|
||||
./scripts/setup-env.sh
|
||||
|
||||
# Option 2: Manual copy
|
||||
cp .env.local .env
|
||||
```
|
||||
Docker Compose requires `.env` for variable substitution.
|
||||
4. Optionally set:
|
||||
- Debug level: `VITE_LOG_LEVEL=debug`
|
||||
- Context size: `DEFAULT_NUM_CTX=32768`
|
||||
|
||||
**Note**: Never commit your `.env.local` file to version control. It’s already in `.gitignore`.
|
||||
**Note**: Never commit your `.env.local` or `.env` files to version control. They're already in `.gitignore`.
|
||||
|
||||
### 2️⃣ Run Development Server
|
||||
|
||||
|
||||
@@ -99,7 +99,11 @@ ANTHROPIC_API_KEY=XXX
|
||||
|
||||
Once you've set your keys, you can proceed with running the app. You will set these keys up during the initial setup, and you can revisit and update them later after the app is running.
|
||||
|
||||
**Note**: Never commit your `.env.local` file to version control. It’s already included in the `.gitignore`.
|
||||
**Important for Docker users**: Docker Compose needs a `.env` file for variable substitution. After creating `.env.local`:
|
||||
- Run `./scripts/setup-env.sh` to automatically sync the files, or
|
||||
- Manually copy: `cp .env.local .env`
|
||||
|
||||
**Note**: Never commit your `.env.local` or `.env` files to version control. They're already included in the `.gitignore`.
|
||||
|
||||
#### 2. Configure API Keys Directly in the Application
|
||||
|
||||
|
||||
41
scripts/setup-env.sh
Executable file
41
scripts/setup-env.sh
Executable file
@@ -0,0 +1,41 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Setup script for Docker environment variables
|
||||
# This script helps resolve the issue where .env.local is not being loaded in Docker
|
||||
|
||||
echo "🔧 Setting up environment files for Docker..."
|
||||
|
||||
# Check if .env.local exists
|
||||
if [ -f ".env.local" ]; then
|
||||
echo "✅ Found .env.local file"
|
||||
|
||||
# Create symlink or copy to .env for Docker Compose
|
||||
if [ ! -f ".env" ] || [ ".env" -ot ".env.local" ]; then
|
||||
echo "📋 Copying .env.local to .env for Docker Compose compatibility..."
|
||||
cp .env.local .env
|
||||
echo "✅ Environment file synced"
|
||||
else
|
||||
echo "ℹ️ .env file already up to date"
|
||||
fi
|
||||
else
|
||||
echo "⚠️ No .env.local file found"
|
||||
|
||||
# Check if .env.example exists and offer to copy it
|
||||
if [ -f ".env.example" ]; then
|
||||
echo "📋 Found .env.example file"
|
||||
read -p "Would you like to create .env.local from .env.example? (y/n) " -n 1 -r
|
||||
echo
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
cp .env.example .env.local
|
||||
cp .env.example .env
|
||||
echo "✅ Created .env.local and .env from .env.example"
|
||||
echo "📝 Please edit .env.local with your API keys"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "✨ Environment setup complete!"
|
||||
echo ""
|
||||
echo "📚 Note: Docker Compose reads both .env and .env.local files"
|
||||
echo " - .env is used for variable substitution in docker-compose.yaml"
|
||||
echo " - .env.local is passed to the container for runtime variables"
|
||||
Reference in New Issue
Block a user