feat: Enhance deployment scripts with environment variable validation and loading

This commit is contained in:
2025-09-12 09:21:53 +02:00
parent 95ef139843
commit c1d49689da
3 changed files with 50 additions and 0 deletions

View File

@@ -7,6 +7,34 @@ set GIT_BRANCH=%2
if "%GIT_BRANCH%"=="" set GIT_BRANCH=ui-fix if "%GIT_BRANCH%"=="" set GIT_BRANCH=ui-fix
set GIT_COMMIT=%3 set GIT_COMMIT=%3
REM Check if .env.production exists
if exist .env.production (
echo Loading production environment variables...
for /f "delims=" %%x in (.env.production) do (
set "%%x"
)
) else (
echo Warning: .env.production not found. Make sure environment variables are set!
)
REM Validate critical environment variables
if "%NEXTAUTH_SECRET%"=="" (
echo ERROR: NEXTAUTH_SECRET must be set to a secure random string!
echo Generate one with: openssl rand -base64 32
exit /b 1
)
@REM if "%NEXTAUTH_SECRET%"=="YOUR_SUPER_SECURE_SECRET_KEY_HERE_AT_LEAST_32_CHARACTERS_LONG" (
@REM echo ERROR: NEXTAUTH_SECRET must be changed from the default value!
@REM echo Generate one with: openssl rand -base64 32
@REM exit /b 1
@REM )
if "%NEXTAUTH_URL%"=="" (
echo ERROR: NEXTAUTH_URL must be set to your production URL!
exit /b 1
)
if "%GIT_REPO_URL%"=="" ( if "%GIT_REPO_URL%"=="" (
echo Building from local files... echo Building from local files...
docker-compose -f docker-compose.prod.yml build docker-compose -f docker-compose.prod.yml build

View File

@@ -10,6 +10,26 @@ GIT_REPO_URL=${1:-""}
GIT_BRANCH=${2:-"ui-fix"} GIT_BRANCH=${2:-"ui-fix"}
GIT_COMMIT=${3:-""} GIT_COMMIT=${3:-""}
# Check if .env.production exists and source it
if [ -f .env.production ]; then
echo "Loading production environment variables..."
export $(grep -v '^#' .env.production | xargs)
else
echo "Warning: .env.production not found. Make sure environment variables are set!"
fi
# Validate critical environment variables
# if [ -z "$NEXTAUTH_SECRET" ] || [ "$NEXTAUTH_SECRET" = "YOUR_SUPER_SECURE_SECRET_KEY_HERE_AT_LEAST_32_CHARACTERS_LONG" ]; then
# echo "ERROR: NEXTAUTH_SECRET must be set to a secure random string!"
# echo "Generate one with: openssl rand -base64 32"
# exit 1
# fi
if [ -z "$NEXTAUTH_URL" ]; then
echo "ERROR: NEXTAUTH_URL must be set to your production URL!"
exit 1
fi
if [ -z "$GIT_REPO_URL" ]; then if [ -z "$GIT_REPO_URL" ]; then
echo "Building from local files..." echo "Building from local files..."
docker-compose -f docker-compose.prod.yml build docker-compose -f docker-compose.prod.yml build

View File

@@ -15,4 +15,6 @@ services:
- ./data:/app/data - ./data:/app/data
environment: environment:
- NODE_ENV=production - NODE_ENV=production
- NEXTAUTH_SECRET=${NEXTAUTH_SECRET:-your-secret-key-generate-a-strong-random-string-at-least-32-characters}
- NEXTAUTH_URL=${NEXTAUTH_URL:-https://panel2.wastpol.pl}
restart: unless-stopped restart: unless-stopped