forked from Azure-Samples/azure-search-openai-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.ps1
74 lines (62 loc) · 1.93 KB
/
start.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
Write-Host ""
Write-Host "Loading azd .env file from current environment"
Write-Host ""
foreach ($line in (& azd env get-values)) {
if ($line -match "([^=]+)=(.*)") {
$key = $matches[1]
$value = $matches[2] -replace '^"|"$'
Set-Item -Path "env:\$key" -Value $value
}
}
if ($LASTEXITCODE -ne 0) {
Write-Host "Failed to load environment variables from azd environment"
exit $LASTEXITCODE
}
Write-Host 'Creating python virtual environment "backend/backend_env"'
$pythonCmd = Get-Command python -ErrorAction SilentlyContinue
if (-not $pythonCmd) {
# fallback to python3 if python not found
$pythonCmd = Get-Command python3 -ErrorAction SilentlyContinue
}
Start-Process -FilePath ($pythonCmd).Source -ArgumentList "-m venv ./backend/backend_env" -Wait -NoNewWindow
Write-Host ""
Write-Host "Restoring backend python packages"
Write-Host ""
Set-Location backend
$venvPythonPath = "./backend_env/scripts/python.exe"
if (Test-Path -Path "/usr") {
# fallback to Linux venv path
$venvPythonPath = "./backend_env/bin/python"
}
Start-Process -FilePath $venvPythonPath -ArgumentList "-m pip install -r requirements.txt" -Wait -NoNewWindow
if ($LASTEXITCODE -ne 0) {
Write-Host "Failed to restore backend python packages"
exit $LASTEXITCODE
}
Write-Host ""
Write-Host "Restoring frontend npm packages"
Write-Host ""
Set-Location ../frontend
npm install
if ($LASTEXITCODE -ne 0) {
Write-Host "Failed to restore frontend npm packages"
exit $LASTEXITCODE
}
Write-Host ""
Write-Host "Building frontend"
Write-Host ""
npm run build
if ($LASTEXITCODE -ne 0) {
Write-Host "Failed to build frontend"
exit $LASTEXITCODE
}
Write-Host ""
Write-Host "Starting backend"
Write-Host ""
Set-Location ../backend
Start-Process http://127.0.0.1:5000
Start-Process -FilePath $venvPythonPath -ArgumentList "./app.py" -Wait -NoNewWindow
if ($LASTEXITCODE -ne 0) {
Write-Host "Failed to start backend"
exit $LASTEXITCODE
}