Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
b05e2a5
chore: update development script to set NODE_ENV for improved environ…
wiktoriavh Nov 4, 2025
48f31b9
feat: add development environment support for configuration management
wiktoriavh Nov 4, 2025
0e09848
feat: add environment configuration files for development and production
wiktoriavh Nov 4, 2025
4e7beee
chore: simplify development script by removing NODE_ENV setting
wiktoriavh Nov 4, 2025
d967a7a
feat: enhance environment loading by adding dynamic file selection an…
wiktoriavh Nov 4, 2025
d9aea1f
feat: add NODE_ENV settings and environment config files for producti…
wiktoriavh Nov 4, 2025
143162f
Merge branch 'main' into feat/use-env-in-dev
wiktoriavh Nov 4, 2025
3502031
refactor: remove unused development environment function and related …
wiktoriavh Nov 4, 2025
3b84703
chore: update docker-compose configuration
wiktoriavh Nov 4, 2025
384c452
chore: update production environment variables for development server
wiktoriavh Nov 4, 2025
fb04483
chore: update .gitignore to include .env.development.example and adju…
wiktoriavh Nov 4, 2025
b911e2a
chore: remove .env.development file
wiktoriavh Nov 4, 2025
8d620ff
chore: add example development environment configuration file
wiktoriavh Nov 4, 2025
85835e3
chore: standardize environment configuration by replacing .env.local …
wiktoriavh Nov 5, 2025
8292591
chore: consolidate environment configuration by removing .env.develop…
wiktoriavh Nov 5, 2025
0dbe7ca
chore: clean up environment configuration by removing commented-out s…
wiktoriavh Nov 5, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Development Environment Configuration
# Public values - safe to commit to repository
# These are Discord IDs for your development/test server

# Discord Server ID (your dev server)
SERVER_ID=1403539983821963274

# Channel IDs (from your dev server)
GUIDES_CHANNEL_ID=1426998962635804712
REPEL_LOG_CHANNEL_ID=1403540596035027045

# Role IDs (from your dev server)
REPEL_ROLE_ID=1403545113904414842
MODERATORS_ROLE_IDS=1428151937534005379

# Note: DISCORD_TOKEN & CLIENT_ID should be in .env.local (not committed)
19 changes: 12 additions & 7 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
DISCORD_TOKEN="" # Your bot token
CLIENT_ID="" # Your bot's application ID
# Local Environment Variables (Secrets)
# Copy this file to .env.local and fill in your actual values
# .env.local is gitignored and should NEVER be committed

SERVER_ID= # Discord Server ID where the bot will operate
MODERATORS_ROLE_IDS= # Comma separated list of role IDs that are Moderators(Mods, Admins, etc)
# Discord Bot Token & Application ID (REQUIRED)
# Get this from: https://discord.com/developers/applications
DISCORD_TOKEN=your-bot-token-here
CLIENT_ID=your-bot-application-id

REPEL_LOG_CHANNEL_ID= # Channel ID where the bot will log repel actions
REPEL_ROLE_ID= # Role ID assigned to users who can use the repel command
GUIDES_CHANNEL_ID="" # The ID of the channel where guides will be posted
# Optional: Override any public config values for local testing
# Uncomment and modify as needed:
# SERVER_ID=override-server-id
# CLIENT_ID=override-client-id
# GUIDES_CHANNEL_ID=override-channel-id
16 changes: 16 additions & 0 deletions .env.production
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Production Environment Configuration
# Public values - safe to commit to repository
# These are Discord IDs that are publicly visible anyway

# Discord Server ID
SERVER_ID=your-prod-server-id

# Channel IDs
GUIDES_CHANNEL_ID=your-prod-guides-channel-id
REPEL_LOG_CHANNEL_ID=your-prod-repel-log-channel-id

# Role IDs
REPEL_ROLE_ID=your-prod-repel-role-id
MODERATORS_ROLE_IDS=your-prod-moderator-role-id-1,your-prod-moderator-role-id-2

# Note: DISCORD_TOKEN & CLIENT_ID should be in .env.local (not committed)
10 changes: 4 additions & 6 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,19 @@ jobs:
export NODE_VERSION=$(cat .nvmrc | sed 's/v//')
echo "Using Node version: $NODE_VERSION"

# Create .env.local file with secrets
# Create .env.local file with secrets only
# Public config comes from .env.production (committed to repo)
# NODE_ENV=production is set in docker-compose.yml
cat > .env.local << EOF
DISCORD_TOKEN=${{ secrets.DISCORD_TOKEN }}
CLIENT_ID=${{ secrets.CLIENT_ID }}
GUIDES_CHANNEL_ID=${{ secrets.GUIDES_CHANNEL_ID }}
SERVER_ID=${{ secrets.SERVER_ID }}
REPEL_LOG_CHANNEL_ID=${{ secrets.REPEL_LOG_CHANNEL_ID }}
REPEL_ROLE_ID=${{ secrets.REPEL_ROLE_ID }}
MODERATORS_ROLE_IDS=${{ secrets.MODERATORS_ROLE_IDS }}
EOF

# Stop any existing containers
docker compose down || true

# Build and start production container with profile
# NODE_ENV=production is explicitly set in docker-compose.yml bot-prod service
docker compose --profile prod up -d --build

# Check status
Expand Down
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ yarn-debug.log*
yarn-error.log*

# Env files
!.env.example
.env
.env.local
.env.*.local
# Allow environment-specific configs (public, non-secret)
!.env.development
!.env.production
!.env.example

# guides tracker
guides-tracker.json
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ COPY --from=deps /app/node_modules ./node_modules
COPY --from=build /app/dist ./dist
COPY package.json ./

# Copy environment config files (public, non-secret)
COPY .env.production .env.development ./

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

Expand Down
5 changes: 5 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ services:
env_file:
- .env.local
environment:
- NODE_ENV=production
- GUIDES_TRACKER_PATH=/app/data/guides-tracker.json
volumes:
# Persist guides tracker data
Expand All @@ -30,6 +31,7 @@ services:
env_file:
- .env.local
environment:
- NODE_ENV=development
- GUIDES_TRACKER_PATH=/app/data/guides-tracker.json
volumes:
# Mount source code for hot reload
Expand All @@ -40,6 +42,9 @@ services:
# Mount package files (in case dependencies change)
- ./package.json:/app/package.json:ro
- ./pnpm-lock.yaml:/app/pnpm-lock.yaml:ro
# Mount environment config files
- ./.env.development:/app/.env.development:ro
- ./.env.production:/app/.env.production:ro
# Persist guides tracker data
- guides-data:/app/data
profiles:
Expand Down
17 changes: 14 additions & 3 deletions src/loadEnvFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { join } from 'node:path';
// Simple .env loader without external dependencies
function loadEnvFile(filePath: string) {
if (!existsSync(filePath)) {
console.warn(`Warning: File ${filePath} not found`);
return;
}

Expand All @@ -24,12 +25,22 @@ function loadEnvFile(filePath: string) {
}
}
}
console.log(`✅ Loaded: ${filePath}`);
} catch (error) {
console.warn(`Warning: Could not load ${filePath}`);
console.warn('Make sure a valid .env.local file exists.');
console.warn(error);
}
}

// Load local environment file if it exists
loadEnvFile(join(process.cwd(), '.env.local'));
// Determine environment (defaults to development)
const nodeEnv = process.env.NODE_ENV || 'development';
console.log(`🌍 Environment: ${nodeEnv}`);

// Load environment-specific config first (public values)
const envFile = join(process.cwd(), `.env.${nodeEnv}`);
loadEnvFile(envFile);

// Load local overrides and secrets second (overrides public config)
// Required in both dev and prod for DISCORD_TOKEN
const localEnvFile = join(process.cwd(), '.env.local');
loadEnvFile(localEnvFile);