Skip to content

Commit be514b2

Browse files
fix parameter issue in docker-build.sh
1 parent 439e381 commit be514b2

File tree

3 files changed

+45
-20
lines changed

3 files changed

+45
-20
lines changed

.devcontainer/setup_env.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ git pull
66
# provide execute permission to quotacheck script
77
sudo chmod +x ./infra/scripts/checkquota_km.sh
88
sudo chmod +x ./infra/scripts/quota_check_params.sh
9-
sudo chmod +x ./infra/scripts/run_process_data_scripts.sh
9+
sudo chmod +x ./infra/scripts/run_process_data_scripts.sh
10+
sudo chmod +x ./infra/scripts/docker-build.sh
11+
sudo chmod +x ./infra/scripts/docker-build.ps1

infra/scripts/docker-build.ps1

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,42 +24,55 @@ if ($USE_LOCAL_BUILD -eq $false) {
2424

2525
Write-Output "Local Build enabled. Starting build process."
2626

27-
# STEP 1: Set Azure subscription
27+
# STEP 1: Ensure user is logged into Azure
28+
Write-Host "Checking Azure login status..."
29+
$account = az account show 2>$null | ConvertFrom-Json
30+
31+
if (-not $account) {
32+
Write-Host "Not logged in. Attempting az login..."
33+
az login | Out-Null
34+
if ($LASTEXITCODE -ne 0) {
35+
Write-Error "Azure login failed."
36+
exit 1
37+
}
38+
} else {
39+
Write-Host "Already logged in to Azure as: $($account.user.name)"
40+
}
41+
42+
# STEP 2: Set Azure subscription
2843
az account set --subscription "$AZURE_SUBSCRIPTION_ID"
2944
if ($LASTEXITCODE -ne 0) {
3045
Write-Error "Failed to set Azure subscription."
3146
exit 1
3247
}
3348

34-
# STEP 2: Deploy container registry
49+
# STEP 3: Deploy container registry
3550
Write-Host "Deploying container registry in location: $AZURE_LOCATION"
3651
$OUTPUTS = az deployment group create --resource-group $AZURE_RESOURCE_GROUP --template-file "./infra/deploy_container_registry.bicep" --parameters environmentName=$ENV_NAME --query "properties.outputs" --output json | ConvertFrom-Json
3752

3853
# Extract ACR name and endpoint
3954
$ACR_NAME = $OUTPUTS.createdAcrName.value
40-
$ACR_ENDPOINT = $OUTPUTS.acrEndpoint.value
4155

4256
Write-Host "Extracted ACR Name: $ACR_NAME"
43-
Write-Host "Extracted ACR Endpoint: $ACR_ENDPOINT"
4457

45-
# STEP 3: Login to Azure Container Registry
58+
# STEP 4: Login to Azure Container Registry
4659
Write-Host "Logging into Azure Container Registry: $ACR_NAME"
4760
az acr login -n $ACR_NAME
4861
if ($LASTEXITCODE -ne 0) {
4962
Write-Error "Failed to log in to ACR"
5063
exit 1
5164
}
5265

53-
# STEP 4: Get current script directory
66+
# STEP 5: Get current script directory
5467
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
5568

56-
# STEP 5: Resolve full paths to Dockerfiles and build contexts
69+
# STEP 6: Resolve full paths to Dockerfiles and build contexts
5770
$WebAppDockerfilePath = Join-Path $ScriptDir "..\..\src\App\WebApp.Dockerfile" | Resolve-Path
5871
$WebAppContextPath = Join-Path $ScriptDir "..\..\src\App" | Resolve-Path
5972
$ApiAppDockerfilePath = Join-Path $ScriptDir "..\..\src\api\ApiApp.Dockerfile" | Resolve-Path
6073
$ApiAppContextPath = Join-Path $ScriptDir "..\..\src\api" | Resolve-Path
6174

62-
# STEP 6: Define function to build and push Docker images
75+
# STEP 7: Define function to build and push Docker images
6376
function Build-And-Push-Image {
6477
param (
6578
[string]$IMAGE_NAME,
@@ -88,7 +101,7 @@ function Build-And-Push-Image {
88101
Write-Host "--- Docker image pushed successfully: $IMAGE_URI ---`n"
89102
}
90103

91-
# STEP 7: Build and push images with provided tag
104+
# STEP 8: Build and push images with provided tag
92105
$ACR_IMAGE_TAG = "latest"
93106
Build-And-Push-Image "km-api" $ApiAppDockerfilePath $ApiAppContextPath $ACR_IMAGE_TAG
94107
Build-And-Push-Image "km-app" $WebAppDockerfilePath $WebAppContextPath $ACR_IMAGE_TAG

infra/scripts/docker-build.sh

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,33 @@ fi
1818
which jq || { echo "jq is not installed"; exit 1; }
1919

2020
# Exit early if local build is not requested
21-
if [[ "$USE_LOCAL_BUILD" != "true" ]]; then
21+
if [[ "${USE_LOCAL_BUILD,,}" != "true" ]]; then
2222
echo "Local Build not enabled. Using prebuilt image."
2323
exit 0
2424
fi
2525

2626
echo "Local Build enabled. Starting build process."
2727

28-
# STEP 1: Set Azure subscription
28+
# STEP 1: Ensure user is logged into Azure
29+
if ! az account show > /dev/null 2>&1; then
30+
echo "Not logged in to Azure. Attempting az login..."
31+
az login
32+
if [[ $? -ne 0 ]]; then
33+
echo "Azure login failed."
34+
exit 1
35+
fi
36+
else
37+
echo "Already logged in to Azure."
38+
fi
39+
40+
# STEP 2: Set Azure subscription
2941
az account set --subscription "$AZURE_SUBSCRIPTION_ID"
3042
if [[ $? -ne 0 ]]; then
3143
echo "Failed to set Azure subscription."
3244
exit 1
3345
fi
3446

35-
# STEP 2: Deploy container registry
47+
# STEP 3: Deploy container registry
3648
echo "Deploying container registry in location: $AZURE_LOCATION"
3749
OUTPUTS=$(az deployment group create \
3850
--resource-group "$AZURE_RESOURCE_GROUP" \
@@ -42,29 +54,27 @@ OUTPUTS=$(az deployment group create \
4254
--output json)
4355

4456
ACR_NAME=$(echo "$OUTPUTS" | jq -r '.createdAcrName.value')
45-
ACR_ENDPOINT=$(echo "$OUTPUTS" | jq -r '.acrEndpoint.value')
4657

4758
echo "Extracted ACR Name: $ACR_NAME"
48-
echo "Extracted ACR Endpoint: $ACR_ENDPOINT"
4959

50-
# STEP 3: Login to Azure Container Registry
60+
# STEP 4: Login to Azure Container Registry
5161
echo "Logging into Azure Container Registry: $ACR_NAME"
5262
az acr login -n "$ACR_NAME"
5363
if [[ $? -ne 0 ]]; then
5464
echo "Failed to log in to ACR"
5565
exit 1
5666
fi
5767

58-
# STEP 4: Get current script directory
68+
# STEP 5: Get current script directory
5969
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6070

61-
# STEP 5: Resolve full paths to Dockerfiles and build contexts
71+
# STEP 6: Resolve full paths to Dockerfiles and build contexts
6272
WEBAPP_DOCKERFILE_PATH="$SCRIPT_DIR/../../src/App/WebApp.Dockerfile"
6373
WEBAPP_CONTEXT_PATH="$SCRIPT_DIR/../../src/App"
6474
APIAPP_DOCKERFILE_PATH="$SCRIPT_DIR/../../src/api/ApiApp.Dockerfile"
6575
APIAPP_CONTEXT_PATH="$SCRIPT_DIR/../../src/api"
6676

67-
# STEP 6: Define function to build and push Docker images
77+
# STEP 7: Define function to build and push Docker images
6878
build_and_push_image() {
6979
IMAGE_NAME="$1"
7080
BUILD_PATH="$2"
@@ -90,7 +100,7 @@ build_and_push_image() {
90100
echo "--- Docker image pushed successfully: $IMAGE_URI ---"
91101
}
92102

93-
# STEP 7: Build and push images with provided tag
103+
# STEP 8: Build and push images with provided tag
94104
ACR_IMAGE_TAG="latest"
95105
build_and_push_image "km-api" "$APIAPP_DOCKERFILE_PATH" "$APIAPP_CONTEXT_PATH" "$ACR_IMAGE_TAG"
96106
build_and_push_image "km-app" "$WEBAPP_DOCKERFILE_PATH" "$WEBAPP_CONTEXT_PATH" "$ACR_IMAGE_TAG"

0 commit comments

Comments
 (0)