@@ -6,25 +6,31 @@ REM Set root and config paths
66set ROOT_DIR = %cd% \..
77set AZURE_FOLDER = %ROOT_DIR% \.azure
88set CONFIG_FILE = %AZURE_FOLDER% \config.json
9+ set API_ENV_FILE = %ROOT_DIR% \src\api\.env
10+ set WORKSHOP_ENV_FILE = %ROOT_DIR% \docs\workshop\docs\workshop\.env
911
10- REM Validate config.json
12+ REM Check if .azure folder exists first
13+ if not exist " %AZURE_FOLDER% " (
14+ echo .azure folder not found. This is normal if Azure deployment hasn't been run yet.
15+ goto :check_local_env
16+ )
17+
18+ REM Check if config.json exists
1119if not exist " %CONFIG_FILE% " (
12- echo config.json not found at %CONFIG_FILE%
13- exit /b 1
20+ echo config.json not found in .azure folder. This is normal if Azure deployment hasn't been run yet.
21+ goto : check_local_env
1422)
1523
1624REM Extract default environment name
17- for /f " delims=" %%i in ('powershell -command " (Get-Content '%CONFIG_FILE% ' | ConvertFrom-Json).defaultEnvironment" ') do set DEFAULT_ENV = %%i
25+ for /f " delims=" %%i in ('powershell -command " try { (Get-Content '%CONFIG_FILE% ' | ConvertFrom-Json).defaultEnvironment } catch { '' } " ') do set DEFAULT_ENV = %%i
1826
1927if not defined DEFAULT_ENV (
20- echo Failed to extract defaultEnvironment from config.json
21- exit /b 1
28+ echo Failed to extract defaultEnvironment from config.json or config.json is invalid.
29+ goto : check_local_env
2230)
2331
24- REM Load .env file
32+ REM Load .env file from Azure deployment
2533set ENV_FILE = %AZURE_FOLDER% \%DEFAULT_ENV% \.env
26- set API_ENV_FILE = %ROOT_DIR% \src\api\.env
27- set WORKSHOP_ENV_FILE = %ROOT_DIR% \docs\workshop\docs\workshop\.env
2834
2935REM Check if .env file exists in .azure folder
3036if exist " %ENV_FILE% " (
@@ -59,37 +65,53 @@ if exist "%ENV_FILE%" (
5965 set ENV_FILE_FOR_ROLES = %ENV_FILE%
6066 )
6167
62- REM Copy to workshop directory
6368 copy /Y " %ENV_FILE% " " %WORKSHOP_ENV_FILE% "
6469 if errorlevel 1 (
65- echo Failed to copy .env to workshop directory
66- exit /b 1
70+ echo Warning: Failed to copy .env to workshop directory
71+ ) else (
72+ echo Azure deployment .env copied to workshop/docs/workshop
6773 )
68- echo Azure deployment .env copied to workshop/docs/workshop
6974
70- ) else (
71- echo .env file not found in Azure deployment folder: %ENV_FILE%
75+ goto :setup_environment
76+ )
77+
78+ :check_local_env
79+ echo Checking for local .env file in src/api...
80+
81+ REM Try to use src/api .env file as fallback
82+ if exist " %API_ENV_FILE% " (
83+ echo Using existing .env file from src/api for configuration...
84+ set ENV_FILE_FOR_ROLES = %API_ENV_FILE%
85+ echo Warning: No Azure deployment found, using local src/api/.env
7286
73- REM Try to use src/api .env file as fallback
74- if exist " %API_ENV_FILE% " (
75- echo Using existing .env file from src/api for configuration...
76- set ENV_FILE_FOR_ROLES = %API_ENV_FILE%
77- echo Warning: No Azure deployment .env found, using local src/api/.env
87+ copy /Y " %API_ENV_FILE% " " %WORKSHOP_ENV_FILE% "
88+ if errorlevel 1 (
89+ echo Warning: Failed to copy .env to workshop directory
7890 ) else (
79- echo ERROR: No .env files found in either location:
80- echo - Azure deployment: %ENV_FILE%
81- echo - API folder: %API_ENV_FILE%
82- echo .
83- echo Please choose one of the following options:
84- echo 1. Run 'azd up' to deploy Azure resources and generate .env files
85- echo 2. Manually create %API_ENV_FILE% with required environment variables
86- echo 3. Copy an existing .env file to one of the above locations
87- echo .
88- echo For more information, see: documents/LocalDebuggingSetup.md
89- exit /b 1
91+ echo Local .env copied to workshop/docs/workshop
9092 )
93+
94+ goto :setup_environment
95+ ) else (
96+ echo ERROR: No .env files found in any location.
97+ echo .
98+ echo The following files/folders are missing:
99+ if not exist " %AZURE_FOLDER% " echo - .azure folder (created by 'azd up')
100+ if exist " %AZURE_FOLDER% " if not exist " %CONFIG_FILE% " echo - .azure/config.json (created by 'azd up')
101+ if exist " %CONFIG_FILE% " if not defined DEFAULT_ENV echo - Valid defaultEnvironment in config.json
102+ if defined DEFAULT_ENV if not exist " %ENV_FILE% " echo - .env file in Azure deployment folder: %ENV_FILE%
103+ echo - Local .env file: %API_ENV_FILE%
104+ echo .
105+ echo Please choose one of the following options:
106+ echo 1. Run 'azd up' to deploy Azure resources and generate .env files
107+ echo 2. Manually create %API_ENV_FILE% with required environment variables
108+ echo 3. Copy an existing .env file to %API_ENV_FILE%
109+ echo .
110+ echo For more information, see: documents/LocalDebuggingSetup.md
111+ exit /b 1
91112)
92113
114+ :setup_environment
93115REM Parse required variables for role assignments from the appropriate env file
94116echo Reading environment variables for role assignments from: %ENV_FILE_FOR_ROLES%
95117for /f " tokens=1,* delims==" %%A in ('type " %ENV_FILE_FOR_ROLES% " ') do (
0 commit comments