Skip to content

Commit

Permalink
remove symlinks and update scripts with paths relative to its own fol…
Browse files Browse the repository at this point in the history
…der instead of cwd
  • Loading branch information
1yefuwang1 committed Sep 6, 2024
1 parent 625866f commit 40287f2
Show file tree
Hide file tree
Showing 18 changed files with 75 additions and 39 deletions.
1 change: 0 additions & 1 deletion aca-host/app

This file was deleted.

8 changes: 4 additions & 4 deletions aca-host/azure.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,22 @@ hooks:
preprovision:
windows:
shell: pwsh
run: ./scripts/auth_init.ps1
run: ../scripts/auth_init.ps1
interactive: true
continueOnError: false
posix:
shell: sh
run: ./scripts/auth_init.sh
run: ../scripts/auth_init.sh
interactive: true
continueOnError: false
postprovision:
windows:
shell: pwsh
run: ./scripts/auth_update.ps1;./scripts/prepdocs.ps1
run: ../scripts/auth_update.ps1; ../scripts/prepdocs.ps1
interactive: true
continueOnError: false
posix:
shell: sh
run: ./scripts/auth_update.sh;./scripts/prepdocs.sh
run: ../scripts/auth_update.sh; ../scripts/prepdocs.sh
interactive: true
continueOnError: false
1 change: 0 additions & 1 deletion aca-host/data

This file was deleted.

1 change: 0 additions & 1 deletion aca-host/scripts

This file was deleted.

4 changes: 2 additions & 2 deletions scripts/adlsgen2setup.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Set the preference to stop on the first error
$ErrorActionPreference = "Stop"

$projectRoot = Split-Path -Parent $PSScriptRoot
& $PSScriptRoot\loadenv.ps1

$venvPythonPath = "./.venv/scripts/python.exe"
Expand All @@ -15,5 +16,4 @@ if ([string]::IsNullOrEmpty($env:AZURE_ADLS_GEN2_STORAGE_ACCOUNT)) {
}

Write-Host 'Running "adlsgen2setup.py"'
$cwd = (Get-Location)
Start-Process -FilePath $venvPythonPath -ArgumentList "./scripts/adlsgen2setup.py `"$cwd/data`" --data-access-control ./scripts/sampleacls.json --storage-account $env:AZURE_ADLS_GEN2_STORAGE_ACCOUNT -v" -Wait -NoNewWindow
Start-Process -FilePath $venvPythonPath -ArgumentList "$projectRoot/scripts/adlsgen2setup.py `"$projectRoot/data`" --data-access-control $projectRoot/scripts/sampleacls.json --storage-account $env:AZURE_ADLS_GEN2_STORAGE_ACCOUNT -v" -Wait -NoNewWindow
9 changes: 7 additions & 2 deletions scripts/adlsgen2setup.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#!/bin/sh

. ./scripts/loadenv.sh
# Get the project root of the current script
project_root="$(cd "$(dirname $(dirname $0))" && pwd)"
script_dir="$project_root/scripts"
data_dir="$project_root/data"

. $script_dir/loadenv.sh

if [ -n "$AZURE_ADLS_GEN2_STORAGE_ACCOUNT" ]; then
echo 'AZURE_ADLS_GEN2_STORAGE_ACCOUNT must be set to continue'
Expand All @@ -9,4 +14,4 @@ fi

echo 'Running "adlsgen2setup.py"'

./.venv/bin/python ./scripts/adlsgen2setup.py './data/*' --data-access-control './scripts/sampleacls.json' --storage-account "$AZURE_ADLS_GEN2_STORAGE_ACCOUNT" -v
./.venv/bin/python $script_dir/adlsgen2setup.py "$data_dir/*" --data-access-control "$script_dir/sampleacls.json" --storage-account "$AZURE_ADLS_GEN2_STORAGE_ACCOUNT" -v
7 changes: 4 additions & 3 deletions scripts/auth_init.ps1
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
. ./scripts/load_azd_env.ps1
$projectRoot = Split-Path -Parent $PSScriptRoot
. $projectRoot/scripts/load_azd_env.ps1

if (-not $env:AZURE_USE_AUTHENTICATION) {
Exit 0
}

. ./scripts/load_python_env.ps1
. $projectRoot/scripts/load_python_env.ps1

$venvPythonPath = "./.venv/scripts/python.exe"
if (Test-Path -Path "/usr") {
# fallback to Linux venv path
$venvPythonPath = "./.venv/bin/python"
}

Start-Process -FilePath $venvPythonPath -ArgumentList "./scripts/auth_init.py" -Wait -NoNewWindow
Start-Process -FilePath $venvPythonPath -ArgumentList "$projectRoot/scripts/auth_init.py" -Wait -NoNewWindow
11 changes: 8 additions & 3 deletions scripts/auth_init.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
#!/bin/sh

# Get the project root of the current script
project_root="$(cd "$(dirname $(dirname $0))" && pwd)"
script_dir="$project_root/scripts"
data_dir="$project_root/data"

echo "Checking if authentication should be setup..."

. ./scripts/load_azd_env.sh
. $script_dir/load_azd_env.sh

if [ -z "$AZURE_USE_AUTHENTICATION" ]; then
echo "AZURE_USE_AUTHENTICATION is not set, skipping authentication setup."
Expand All @@ -11,6 +16,6 @@ fi

echo "AZURE_USE_AUTHENTICATION is set, proceeding with authentication setup..."

. ./scripts/load_python_env.sh
. $script_dir/load_python_env.sh

./.venv/bin/python ./scripts/auth_init.py
./.venv/bin/python $script_dir/auth_init.py
7 changes: 4 additions & 3 deletions scripts/auth_update.ps1
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
. ./scripts/load_azd_env.ps1
$projectRoot = Split-Path -Parent $PSScriptRoot
. $projectRoot/scripts/load_azd_env.ps1

if (-not $env:AZURE_USE_AUTHENTICATION) {
Exit 0
}

. ./scripts/load_python_env.ps1
. $projectRoot/scripts/load_python_env.ps1

$venvPythonPath = "./.venv/scripts/python.exe"
if (Test-Path -Path "/usr") {
# fallback to Linux venv path
$venvPythonPath = "./.venv/bin/python"
}

Start-Process -FilePath $venvPythonPath -ArgumentList "./scripts/auth_update.py" -Wait -NoNewWindow
Start-Process -FilePath $venvPythonPath -ArgumentList "$projectRoot/scripts/auth_update.py" -Wait -NoNewWindow
10 changes: 7 additions & 3 deletions scripts/auth_update.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
#!/bin/sh

. ./scripts/load_azd_env.sh
# Get the project root of the current script
project_root="$(cd "$(dirname $(dirname $0))" && pwd)"
script_dir="$project_root/scripts"

. $script_dir/load_azd_env.sh

if [ -z "$AZURE_USE_AUTHENTICATION" ]; then
exit 0
fi

. ./scripts/load_python_env.sh
. $script_dir/load_python_env.sh

./.venv/bin/python ./scripts/auth_update.py
./.venv/bin/python $script_dir/auth_update.py
3 changes: 2 additions & 1 deletion scripts/load_python_env.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
$projectRoot = Split-Path -Parent $PSScriptRoot
$pythonCmd = Get-Command python -ErrorAction SilentlyContinue
if (-not $pythonCmd) {
# fallback to python3 if python not found
Expand All @@ -14,4 +15,4 @@ if (Test-Path -Path "/usr") {
}

Write-Host 'Installing dependencies from "requirements.txt" into virtual environment'
Start-Process -FilePath $venvPythonPath -ArgumentList "-m pip install -r app/backend/requirements.txt" -Wait -NoNewWindow
Start-Process -FilePath $venvPythonPath -ArgumentList "-m pip install -r $projectRoot/app/backend/requirements.txt" -Wait -NoNewWindow
8 changes: 6 additions & 2 deletions scripts/load_python_env.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#!/bin/sh
#!/bin/sh

# Get the project root of the current script
project_root="$(cd "$(dirname $(dirname $0))" && pwd)"
app_dir="$project_root/app"

echo 'Creating Python virtual environment "app/backend/.venv"...'
python3 -m venv .venv

echo 'Installing dependencies from "requirements.txt" into virtual environment (in quiet mode)...'
.venv/bin/python -m pip --quiet --disable-pip-version-check install -r app/backend/requirements.txt
.venv/bin/python -m pip --quiet --disable-pip-version-check install -r $app_dir/backend/requirements.txt
6 changes: 4 additions & 2 deletions scripts/loadenv.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
./scripts/load_azd_env.ps1
$projectRoot = Split-Path -Parent $PSScriptRoot

./scripts/load_python_env.ps1
& $projectRoot/scripts/load_azd_env.ps1

& $projectRoot/scripts/load_python_env.ps1
8 changes: 6 additions & 2 deletions scripts/loadenv.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/bin/sh

. ./scripts/load_azd_env.sh
# Get the project root of the current script
project_root="$(cd "$(dirname $(dirname $0))" && pwd)"
script_dir="$project_root/scripts"

. ./scripts/load_python_env.sh
. $script_dir/load_azd_env.sh

. $script_dir/load_python_env.sh
4 changes: 3 additions & 1 deletion scripts/manageacl.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ if (Test-Path -Path "/usr") {
$venvPythonPath = "./.venv/bin/python"
}

$projectRoot = Split-Path -Parent $PSScriptRoot

Write-Host "Running manageacl.py. Arguments to script: $args"
Start-Process -FilePath $venvPythonPath -ArgumentList "./scripts/manageacl.py --search-service $env:AZURE_SEARCH_SERVICE --index $env:AZURE_SEARCH_INDEX $args" -Wait -NoNewWindow
Start-Process -FilePath $venvPythonPath -ArgumentList "$projectRoot/scripts/manageacl.py --search-service $env:AZURE_SEARCH_SERVICE --index $env:AZURE_SEARCH_INDEX $args" -Wait -NoNewWindow
8 changes: 6 additions & 2 deletions scripts/manageacl.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#!/bin/sh

. ./scripts/loadenv.sh
# Get the project root of the current script
project_root="$(cd "$(dirname $(dirname $0))" && pwd)"
script_dir="$project_root/scripts"

. $script_dir/loadenv.sh

echo "Running manageacl.py. Arguments to script: $@"
./.venv/bin/python ./scripts/manageacl.py --search-service "$AZURE_SEARCH_SERVICE" --index "$AZURE_SEARCH_INDEX" $@
./.venv/bin/python $script_dir/manageacl.py --search-service "$AZURE_SEARCH_SERVICE" --index "$AZURE_SEARCH_INDEX" $@
8 changes: 4 additions & 4 deletions scripts/prepdocs.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
./scripts/loadenv.ps1
$projectRoot = Split-Path -Parent $PSScriptRoot
& $projectRoot/scripts/loadenv.ps1

$venvPythonPath = "./.venv/scripts/python.exe"
if (Test-Path -Path "/usr") {
Expand Down Expand Up @@ -71,14 +72,13 @@ if ($env:AZURE_OPENAI_API_KEY_OVERRIDE) {
$openaiApiKeyArg = "--openaikey $env:OPENAI_API_KEY"
}

$cwd = (Get-Location)
$dataArg = "`"$cwd/data/*`""
$dataArg = "`"$projectRoot/data/*`""
$additionalArgs = ""
if ($args) {
$additionalArgs = "$args"
}

$argumentList = "./app/backend/prepdocs.py $dataArg --verbose " + `
$argumentList = "$projectRoot/app/backend/prepdocs.py $dataArg --verbose " + `
"--subscriptionid $env:AZURE_SUBSCRIPTION_ID " + `
"--storageaccount $env:AZURE_STORAGE_ACCOUNT --container $env:AZURE_STORAGE_CONTAINER --storageresourcegroup $env:AZURE_STORAGE_RESOURCE_GROUP " + `
"--searchservice $env:AZURE_SEARCH_SERVICE --index $env:AZURE_SEARCH_INDEX " + `
Expand Down
10 changes: 8 additions & 2 deletions scripts/prepdocs.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#!/bin/sh

. ./scripts/loadenv.sh
# Get the project root of the current script
project_root="$(cd "$(dirname $(dirname $0))" && pwd)"
script_dir="$project_root/scripts"
data_dir="$project_root/data"

. $script_dir/loadenv.sh

echo 'Running "prepdocs.py"'

Expand Down Expand Up @@ -74,7 +79,8 @@ if [ $# -gt 0 ]; then
additionalArgs="$@"
fi

./.venv/bin/python ./app/backend/prepdocs.py './data/*' --verbose \

./.venv/bin/python $app_dir/backend/prepdocs.py "$data_dir/*" --verbose \
--subscriptionid $AZURE_SUBSCRIPTION_ID \
--storageaccount "$AZURE_STORAGE_ACCOUNT" --container "$AZURE_STORAGE_CONTAINER" --storageresourcegroup $AZURE_STORAGE_RESOURCE_GROUP \
--searchservice "$AZURE_SEARCH_SERVICE" --index "$AZURE_SEARCH_INDEX" \
Expand Down

0 comments on commit 40287f2

Please sign in to comment.