Skip to content

Commit fd27783

Browse files
Update bito-cra.ps1
new properties added output path, cli path and git domain
1 parent dd7e965 commit fd27783

File tree

1 file changed

+68
-4
lines changed

1 file changed

+68
-4
lines changed

cra-scripts/bito-cra.ps1

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,16 @@ function Validate-Mode {
8383
}
8484
}
8585

86+
# Function to validate an environment value i.e. prod or staging
87+
function Validate-Env {
88+
param($env_val)
89+
90+
if ($env_val -ne "prod" -and $env_val -ne "staging") {
91+
Write-Host "Invalid env value. Please enter either prod or staging."
92+
exit 1
93+
}
94+
}
95+
8696
# Function to display URL using IP address and port
8797
# Run docker ps -l command and store the output
8898
function Display-DockerUrl {
@@ -149,6 +159,37 @@ function Check-ActionDirectory {
149159
return $action_dir
150160
}
151161

162+
# Function to check if the CLI directory exists
163+
function Check-CliDirectory {
164+
param($cli_dir)
165+
166+
if (-not $cli_dir) {
167+
Write-Host "CLI directory not provided!"
168+
exit 1
169+
}
170+
171+
if (-not (Test-Path -Path $cli_dir -PathType Container)) {
172+
Write-Host "CLI directory not found!"
173+
exit 1
174+
}
175+
176+
#return valid cli directory
177+
return $cli_dir
178+
}
179+
180+
# Function to check if the output path directory exists
181+
function Check-OutputDirectory {
182+
param($output_path)
183+
184+
if (-not (Test-Path -Path $output_path -PathType Container)) {
185+
Write-Host "Output path directory not found!"
186+
exit 1
187+
}
188+
189+
#return valid cli directory
190+
return $output_path
191+
}
192+
152193
function Stop-CRA {
153194
if (Test-Path "$BITOCRALOCKFILE") {
154195
Write-Host "Stopping the CRA..."
@@ -294,7 +335,11 @@ $optional_params_cli = @(
294335
"static_analysis",
295336
"dependency_check",
296337
"dependency_check.snyk_auth_token",
297-
"cra_version"
338+
"cra_version",
339+
"env",
340+
"cli_path",
341+
"output_path"
342+
"git.domain"
298343
)
299344

300345
# Parameters that are required/optional in mode server
@@ -312,6 +357,9 @@ $optional_params_server = @(
312357
"dependency_check.snyk_auth_token",
313358
"server_port",
314359
"cra_version"
360+
"env"
361+
"cli_path"
362+
"git.domain"
315363
)
316364

317365
$bee_params = @(
@@ -337,9 +385,9 @@ if ($props[$param_cra_version] -ne '') {
337385
$docker_pull = "docker pull bitoai/cra:${cra_version}"
338386

339387
# Construct the docker run command
340-
$docker_cmd = "docker run --rm -it"
388+
$docker_init_cmd = "docker run --rm -it"
341389
if (-not([string]::IsNullOrEmpty($action_directory))) {
342-
$docker_cmd = "docker run --rm -it -v ${action_directory}:/action_dir"
390+
$docker_init_cmd = "docker run --rm -it -v ${action_directory}:/action_dir"
343391
}
344392

345393
$required_params = $required_params_cli
@@ -348,6 +396,7 @@ $mode = "cli"
348396
$param_mode = "mode"
349397
$server_port = "10051"
350398
$param_server_port = "server_port"
399+
$docker_cmd = ""
351400
# handle if CRA is starting in server mode using start command.
352401
if ($force_mode) {
353402
$props[$param_mode] = $force_mode
@@ -378,7 +427,7 @@ foreach ($param in $required_params) {
378427
foreach ($param in $optional_params) {
379428
if ($param -eq "dependency_check.snyk_auth_token" -and $props["dependency_check"] -eq "True") {
380429
Ask-For-Param $param $false
381-
} elseif ($param -ne "dependency_check.snyk_auth_token") {
430+
} elseif ($param -ne "dependency_check.snyk_auth_token" -and $param -ne "env" -and $param -ne "cli_path" -and $param -ne "output_path" -and $param -ne "git.domain") {
382431
Ask-For-Param $param $false
383432
}
384433
}
@@ -410,12 +459,27 @@ foreach ($param in $required_params + $bee_params + $optional_params) {
410459
} elseif ($param -eq "mode") {
411460
Validate-Mode $props[$param]
412461
$docker_cmd += " --$param=$($props[$param])"
462+
} elseif ($param -eq "env") {
463+
Validate-Env $props[$param]
464+
$docker_cmd += " --$param=$($props[$param])"
465+
} elseif ($param -eq "cli_path") {
466+
$cli_dir = Check-CliDirectory $($props[$param])
467+
$docker_init_cmd += " -v ${cli_dir}:/cli_dir"
468+
} elseif ($param -eq "output_path") {
469+
if ($($props[$param]) -ne $null -and $($props[$param]) -ne "") {
470+
$output_path = Check-OutputDirectory $($props[$param])
471+
if ($output_path -ne $null -and $output_path -ne "") {
472+
$docker_init_cmd += " -v '${output_path}:/output_path'"
473+
$docker_cmd += " --$param=/output_path"
474+
}
475+
}
413476
} else {
414477
$docker_cmd += " --$param=$($props[$param])"
415478
}
416479
}
417480
}
418481

482+
$docker_cmd = $docker_init_cmd + $docker_cmd
419483
$param_bito_access_key = "bito_cli.bito.access_key"
420484
$param_git_access_token = "git.access_token"
421485
if ($mode -eq "server") {

0 commit comments

Comments
 (0)