feat: Add .env file support to Windows build scripts (#9214)

* 🔧 (build_and_run.bat): add support for loading environment variables from .env file
🔧 (build_and_run.ps1): add support for loading environment variables from .env file

* 🐛 (build_and_run.bat): fix path to .env file to correctly load environment variables
🐛 (build_and_run.ps1): fix path to .env file to correctly load environment variables

* 🔧 (build_and_run.bat): set env file parameter if .env file exists to pass to langflow run
🔧 (build_and_run.ps1): set env file parameter if .env file exists to pass to langflow run

* 📝 (build_and_run.bat): improve script to dynamically find and set .env file path for Langflow run
📝 (build_and_run.ps1): enhance script to dynamically locate and set .env file path for Langflow run

* Update scripts/windows/build_and_run.bat

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* 🔧 (build_and_run.ps1): refactor script to use a boolean flag 'useEnvFile' instead of a string variable 'envFileParam' to improve readability and maintainability
🔧 (build_and_run.ps1): update uvicorn command to use '--env-file' flag directly instead of building the command with a string variable

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
Cristhian Zanforlin Lousa 2025-07-28 18:11:49 -03:00 • committed by GitHub
commit 86c54de508
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 44 additions and 10 deletions

View file

@ -1,6 +1,19 @@
@echo off @echo off
echo Starting Langflow build and run process... echo Starting Langflow build and run process...
REM Check if .env file exists and set env file parameter
set "ENV_FILE_PARAM="
REM Get the script directory and resolve project root
for %%I in ("%~dp0..\..") do set "PROJECT_ROOT=%%~fI"
set "ENV_PATH=%PROJECT_ROOT%\.env"
if exist "%ENV_PATH%" (
echo Found .env file at: %ENV_PATH%
set "ENV_FILE_PARAM=--env-file \"%ENV_PATH%\""
) else (
echo .env file not found at: %ENV_PATH%
echo Langflow will use default configuration
)
echo. echo.
echo Step 1: Installing frontend dependencies... echo Step 1: Installing frontend dependencies...
cd ..\..\src\frontend cd ..\..\src\frontend
@ -72,7 +85,11 @@ echo Step 4: Running Langflow...
echo. echo.
echo Attention: Wait until uvicorn is running before opening the browser echo Attention: Wait until uvicorn is running before opening the browser
echo. echo.
if defined ENV_FILE_PARAM (
uv run langflow run %ENV_FILE_PARAM%
) else (
uv run langflow run uv run langflow run
)
if errorlevel 1 ( if errorlevel 1 (
echo Error: Failed to run langflow echo Error: Failed to run langflow
pause pause

View file

@ -2,6 +2,19 @@
Write-Host "Starting Langflow build and run process..." -ForegroundColor Green Write-Host "Starting Langflow build and run process..." -ForegroundColor Green
# Check if .env file exists and set env file parameter
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition
$projectRoot = Resolve-Path (Join-Path $scriptDir "..\..")
$envPath = Join-Path $projectRoot ".env"
$useEnvFile = $false
if (Test-Path $envPath) {
Write-Host "Found .env file at: $envPath" -ForegroundColor Cyan
$useEnvFile = $true
} else {
Write-Host ".env file not found at: $envPath" -ForegroundColor Yellow
Write-Host "Langflow will use default configuration" -ForegroundColor Yellow
}
# Step 1: Install frontend dependencies # Step 1: Install frontend dependencies
Write-Host "`nStep 1: Installing frontend dependencies..." -ForegroundColor Yellow Write-Host "`nStep 1: Installing frontend dependencies..." -ForegroundColor Yellow
try { try {
@ -73,7 +86,11 @@ try {
Write-Host "`nStep 4: Running Langflow..." -ForegroundColor Yellow Write-Host "`nStep 4: Running Langflow..." -ForegroundColor Yellow
Write-Host "`nAttention: Wait until uvicorn is running before opening the browser" -ForegroundColor Red Write-Host "`nAttention: Wait until uvicorn is running before opening the browser" -ForegroundColor Red
try { try {
uv run langflow run if ($useEnvFile) {
& uv run langflow run --env-file $envPath
} else {
& uv run langflow run
}
} catch { } catch {
Write-Host "Error running langflow: $_" -ForegroundColor Red Write-Host "Error running langflow: $_" -ForegroundColor Red
Read-Host "Press Enter to exit" Read-Host "Press Enter to exit"