Skip to content

Commit 85835e3

Browse files
committed
chore: standardize environment configuration by replacing .env.local with .env
1 parent 8d620ff commit 85835e3

8 files changed

Lines changed: 24 additions & 23 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ jobs:
3838
export NODE_VERSION=$(cat .nvmrc | sed 's/v//')
3939
echo "Using Node version: $NODE_VERSION"
4040
41-
# Create .env.local file with secrets only
41+
# Create .env file with secrets
4242
# Public config comes from .env.production (committed to repo)
4343
# NODE_ENV=production is set in docker-compose.yml
44-
cat > .env.local << EOF
44+
cat > .env << EOF
4545
DISCORD_TOKEN=${{ secrets.DISCORD_TOKEN }}
4646
CLIENT_ID=${{ secrets.CLIENT_ID }}
4747
EOF

DOCKER.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ This document explains how to run the webdev-bot using Docker.
66

77
- Docker installed (version 20.10 or higher)
88
- Docker Compose installed (version 2.0 or higher)
9-
- `.env.local` file with required environment variables
9+
- `.env` file with required environment variables
1010

1111
## Node Version Management
1212

1313
The Docker setup uses `.nvmrc` as the single source of truth for the Node.js version. The Dockerfile automatically reads this version at build time via the `NODE_VERSION` build argument. No need to manually sync versions between `.nvmrc` and Docker files.
1414

1515
## Environment Variables
1616

17-
Before running the bot, create a `.env.local` file in the project root with the following variables:
17+
Before running the bot, create a `.env` file in the project root with the following variables:
1818

1919
```env
2020
DISCORD_TOKEN=your_discord_bot_token
@@ -104,7 +104,7 @@ Run the production container manually (after building with the NODE_VERSION arg)
104104
```bash
105105
docker run -d \
106106
--name webdev-bot \
107-
--env-file .env.local \
107+
--env-file .env \
108108
--restart unless-stopped \
109109
webdev-bot:latest
110110
```
@@ -114,7 +114,7 @@ Run the development container manually (after building with the NODE_VERSION arg
114114
```bash
115115
docker run -it \
116116
--name webdev-bot-dev \
117-
--env-file .env.local \
117+
--env-file .env \
118118
-v $(pwd)/src:/app/src:ro \
119119
webdev-bot:dev
120120
```
@@ -183,7 +183,7 @@ docker compose build --no-cache
183183

184184
## Best Practices
185185

186-
1. **Never commit `.env.local`** - Keep your secrets secure
186+
1. **Never commit `.env`** - Keep your secrets secure
187187
2. **Use production profile for deployment** - Smaller, more secure images
188188
3. **Keep development profile for local testing** - Faster iteration with hot reload
189189
4. **Node version is managed in `.nvmrc`** - Update `.nvmrc` to change Node version for Docker

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ COPY --from=deps /app/node_modules ./node_modules
4141
COPY --from=build /app/dist ./dist
4242
COPY package.json ./
4343

44-
# Copy environment config files (public, non-secret)
45-
COPY .env.production .env.development ./
44+
# Copy environment config file (public, non-secret)
45+
COPY .env.production ./
4646

4747
# Create data directory and set permissions for node user
4848
RUN mkdir -p /app/data && chown -R node:node /app/data

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ A comprehensive Discord bot designed specifically for the Web Dev Discord server
5252
pnpm install
5353
```
5454

55-
3. Create a `.env.local` file based on `.env.example` and fill in the required environment variables:
55+
3. Create a `.env` file based on `.env.example` and fill in the required environment variables:
5656
```bash
57-
cp .env.example .env.local
58-
# Edit .env.local to add your Discord bot token and other configurations
57+
cp .env.example .env
58+
# Edit .env to add your Discord bot token and other configurations
5959
```
6060

6161
4. Build and start the bot:

docker-compose.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ services:
99
container_name: webdev-bot-prod
1010
restart: unless-stopped
1111
env_file:
12-
- .env.local
12+
- .env
1313
environment:
1414
- NODE_ENV=production
1515
volumes:
@@ -30,7 +30,7 @@ services:
3030
container_name: webdev-bot-dev
3131
restart: unless-stopped
3232
env_file:
33-
- .env.local
33+
- .env
3434
environment:
3535
- NODE_ENV=development
3636
volumes:
@@ -43,7 +43,6 @@ services:
4343
- ./package.json:/app/package.json:ro
4444
- ./pnpm-lock.yaml:/app/pnpm-lock.yaml:ro
4545
# Mount environment config files
46-
- ./.env.development:/app/.env.development:ro
4746
- ./.env.production:/app/.env.production:ro
4847
# Persist guides tracker data
4948
- guides-data:/app/data

docs/GUIDE_SYNC.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The bot automatically synchronizes guide markdown files from `src/commands/guide
44

55
## Setup
66

7-
Add to your `.env.local` file:
7+
Add to your `.env` file:
88
```
99
GUIDES_CHANNEL_ID=1234567890123456789
1010
```

src/env.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function requireEnv(key: string): string {
88
const value = process.env[key];
99
if (!value) {
1010
console.error(`❌ Required environment variable ${key} is not set`);
11-
console.error('Please check your .env.local file or CI/CD configuration');
11+
console.error('Please check your .env file or CI/CD configuration');
1212
process.exit(1);
1313
}
1414
return value;

src/loadEnvFile.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@ function loadEnvFile(filePath: string) {
3636
const nodeEnv = process.env.NODE_ENV || 'development';
3737
console.log(`🌍 Environment: ${nodeEnv}`);
3838

39-
// Load environment-specific config first (public values)
40-
const envFile = join(process.cwd(), `.env.${nodeEnv}`);
41-
loadEnvFile(envFile);
39+
// Load environment-specific config first (public values, production only)
40+
if (nodeEnv === 'production') {
41+
const envFile = join(process.cwd(), '.env.production');
42+
loadEnvFile(envFile);
43+
}
4244

43-
// Load local overrides and secrets second (overrides public config)
44-
// Required in both dev and prod for DISCORD_TOKEN
45-
const localEnvFile = join(process.cwd(), '.env.local');
45+
// Load .env file with secrets and local config (overrides public config if any)
46+
// Required for DISCORD_TOKEN and other secrets
47+
const localEnvFile = join(process.cwd(), '.env');
4648
loadEnvFile(localEnvFile);

0 commit comments

Comments
 (0)