This commit is contained in:
Andrey Kondratev
2025-08-29 12:32:37 +05:00
parent 5d6c4a8971
commit ec9c541675
4 changed files with 69 additions and 11 deletions

View File

@@ -105,6 +105,21 @@ jobs:
cd /opt/quixotic
git pull origin main
# Create production environment file from secrets
cat > .env.docker << EOF
NODE_ENV=production
PORT=3000
POSTGRES_DB=${{ secrets.POSTGRES_DB }}
POSTGRES_USER=${{ secrets.POSTGRES_USER }}
POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }}
DOMAIN=${{ secrets.DOMAIN }}
ACME_EMAIL=${{ secrets.ACME_EMAIL }}
TRAEFIK_AUTH=${{ secrets.TRAEFIK_AUTH }}
TELEGRAM_BOT_TOKEN=${{ secrets.TELEGRAM_BOT_TOKEN }}
WEB_APP_URL=https://${{ secrets.DOMAIN }}
DATABASE_URL=postgresql://${{ secrets.POSTGRES_USER }}:${{ secrets.POSTGRES_PASSWORD }}@postgres:5432/${{ secrets.POSTGRES_DB }}
EOF
# Login to GitHub Container Registry
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin

View File

@@ -0,0 +1,15 @@
# Docker Compose Cleanup
Removed duplicate environment variables from quixotic-app service in docker-compose.yml:
- TELEGRAM_BOT_TOKEN
- DOMAIN
- ACME_EMAIL
- POSTGRES_DB
- POSTGRES_USER
- POSTGRES_PASSWORD
These variables are already loaded via `env_file: .env.docker` so duplicating them in the environment section was unnecessary. Kept only the essential variables that need to be explicitly set:
- NODE_ENV: production
- PORT: 3000
- DATABASE_URL: constructed from postgres variables
- DATABASE_SSL: false

View File

@@ -0,0 +1,35 @@
# Docker Environment Variables Production Fix
## Problem Identified
Environment variables weren't loading properly in production for the `quixotic-app` service, despite `.env.docker` file containing correct values.
## Root Cause
The issue was in the Docker Compose environment variable syntax. Using array format (`- KEY=value`) instead of hash format (`KEY: value`) was causing variable precedence issues.
## Solution Applied
Changed the `environment` section in `docker-compose.yml` from:
```yaml
environment:
- NODE_ENV=production
- PORT=3000
- TELEGRAM_BOT_TOKEN=${TELEGRAM_BOT_TOKEN}
# ... etc
```
To:
```yaml
environment:
NODE_ENV: production
PORT: 3000
TELEGRAM_BOT_TOKEN: ${TELEGRAM_BOT_TOKEN}
# ... etc
```
## Environment Files Structure
- `.env.docker` - Production environment variables (referenced by env_file)
- `.env.docker.example` - Template with example values
- Both traefik and postgres services were loading env vars correctly
- Only quixotic-app service had the syntax issue
## Verification Command
Use `docker-compose config` to verify environment variables are properly loaded before deployment.

View File

@@ -66,17 +66,10 @@ services:
env_file:
- .env.docker
environment:
- NODE_ENV=production
- PORT=3000
- DATABASE_URL=postgresql://${POSTGRES_USER:-quixotic}:${POSTGRES_PASSWORD:-quixotic123}@postgres:5432/${POSTGRES_DB:-quixotic}
- DATABASE_SSL=false
- TELEGRAM_BOT_TOKEN=${TELEGRAM_BOT_TOKEN}
- TELEGRAM_CHAT_ID=${TELEGRAM_CHAT_ID}
- DOMAIN=${DOMAIN}
- ACME_EMAIL=${ACME_EMAIL}
- POSTGRES_DB=${POSTGRES_DB}
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
NODE_ENV: production
PORT: 3000
DATABASE_URL: postgresql://${POSTGRES_USER:-quixotic}:${POSTGRES_PASSWORD:-quixotic123}@postgres:5432/${POSTGRES_DB:-quixotic}
DATABASE_SSL: false
volumes:
- downloads:/app/downloads
labels: