Skip to content

Commit e5752ce

Browse files
updatedApproch
1 parent 084d488 commit e5752ce

File tree

4 files changed

+164
-6
lines changed

4 files changed

+164
-6
lines changed

azure_custom.yaml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,17 @@ hooks:
2323
azd env set AZURE_CONTAINER_REGISTRY_ENDPOINT "$acrName.azurecr.io"
2424
azd env set CONTAINER_REGISTRY_HOSTNAME "$acrName.azurecr.io"
2525
}
26+
27+
# Build frontend
28+
Write-Host "`nBuilding frontend..."
29+
& ".\infra\scripts\package_frontend.ps1"
30+
31+
if ($LASTEXITCODE -ne 0) {
32+
Write-Host "❌ Failed to build frontend"
33+
exit 1
34+
}
2635
shell: pwsh
27-
continueOnError: true
36+
continueOnError: false
2837
posix:
2938
run: |
3039
echo "Setting up container registry variables..."
@@ -37,8 +46,18 @@ hooks:
3746
azd env set AZURE_CONTAINER_REGISTRY_ENDPOINT "$ACR_NAME.azurecr.io"
3847
azd env set CONTAINER_REGISTRY_HOSTNAME "$ACR_NAME.azurecr.io"
3948
fi
49+
50+
# Build frontend
51+
echo ""
52+
echo "Building frontend..."
53+
bash ./infra/scripts/package_frontend.sh
54+
55+
if [ $? -ne 0 ]; then
56+
echo "❌ Failed to build frontend"
57+
exit 1
58+
fi
4059
shell: sh
41-
continueOnError: true
60+
continueOnError: false
4261

4362
# Pre-deploy hook to build and push containers
4463
predeploy:

infra/scripts/package_frontend.ps1

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env pwsh
2+
3+
Write-Host "`n========================================"
4+
Write-Host " Frontend Build Script (PowerShell)"
5+
Write-Host " Time: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')"
6+
Write-Host "========================================`n"
7+
8+
# Get the script directory and navigate to frontend
9+
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
10+
$frontendDir = Join-Path $scriptDir "..\..\src\frontend"
11+
$distDir = Join-Path $scriptDir "..\..\dist"
12+
13+
Write-Host "📂 Frontend directory: $frontendDir"
14+
Write-Host "📂 Output directory: $distDir`n"
15+
16+
# Check if frontend directory exists
17+
if (-not (Test-Path $frontendDir)) {
18+
Write-Host "❌ Frontend directory not found: $frontendDir"
19+
exit 1
20+
}
21+
22+
# Navigate to frontend directory
23+
Push-Location $frontendDir
24+
25+
try {
26+
# Install dependencies
27+
Write-Host "📦 Installing frontend dependencies..."
28+
npm ci
29+
30+
if ($LASTEXITCODE -ne 0) {
31+
Write-Host "❌ Failed to install dependencies"
32+
exit 1
33+
}
34+
35+
# Build the frontend
36+
Write-Host "`n🏗️ Building frontend application..."
37+
npm run build
38+
39+
if ($LASTEXITCODE -ne 0) {
40+
Write-Host "❌ Failed to build frontend"
41+
exit 1
42+
}
43+
44+
# Create dist directory if it doesn't exist
45+
if (-not (Test-Path $distDir)) {
46+
New-Item -ItemType Directory -Path $distDir -Force | Out-Null
47+
}
48+
49+
# Copy build output to dist directory
50+
Write-Host "`n📋 Copying build output to dist directory..."
51+
# Vite outputs to ../static from frontend directory, which is src/static
52+
$buildOutput = Join-Path $scriptDir "..\..\src\static"
53+
54+
if (Test-Path $buildOutput) {
55+
Copy-Item -Path "$buildOutput\*" -Destination $distDir -Recurse -Force
56+
Write-Host "✅ Frontend build completed successfully!"
57+
Write-Host " Build output copied from: $buildOutput"
58+
} else {
59+
Write-Host "❌ Build output directory not found: $buildOutput"
60+
exit 1
61+
}
62+
63+
} finally {
64+
# Return to original directory
65+
Pop-Location
66+
}
67+
68+
Write-Host "`n========================================"
69+
Write-Host "✅ Frontend packaging completed!"
70+
Write-Host "========================================`n"

infra/scripts/package_frontend.sh

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/bin/bash
2+
3+
echo ""
4+
echo "========================================"
5+
echo " Frontend Build Script (Bash)"
6+
echo " Time: $(date '+%Y-%m-%d %H:%M:%S')"
7+
echo "========================================"
8+
echo ""
9+
10+
# Get the script directory and navigate to frontend
11+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
12+
FRONTEND_DIR="$SCRIPT_DIR/../../src/frontend"
13+
DIST_DIR="$SCRIPT_DIR/../../dist"
14+
15+
echo "📂 Frontend directory: $FRONTEND_DIR"
16+
echo "📂 Output directory: $DIST_DIR"
17+
echo ""
18+
19+
# Check if frontend directory exists
20+
if [ ! -d "$FRONTEND_DIR" ]; then
21+
echo "❌ Frontend directory not found: $FRONTEND_DIR"
22+
exit 1
23+
fi
24+
25+
# Navigate to frontend directory
26+
cd "$FRONTEND_DIR" || exit 1
27+
28+
# Install dependencies
29+
echo "📦 Installing frontend dependencies..."
30+
npm ci
31+
32+
if [ $? -ne 0 ]; then
33+
echo "❌ Failed to install dependencies"
34+
exit 1
35+
fi
36+
37+
# Build the frontend
38+
echo ""
39+
echo "🏗️ Building frontend application..."
40+
npm run build
41+
42+
if [ $? -ne 0 ]; then
43+
echo "❌ Failed to build frontend"
44+
exit 1
45+
fi
46+
47+
# Create dist directory if it doesn't exist
48+
mkdir -p "$DIST_DIR"
49+
50+
# Copy build output to dist directory
51+
echo ""
52+
echo "📋 Copying build output to dist directory..."
53+
# Vite outputs to ../static from frontend directory, which is src/static
54+
BUILD_OUTPUT="$SCRIPT_DIR/../../src/static"
55+
56+
if [ -d "$BUILD_OUTPUT" ]; then
57+
cp -r "$BUILD_OUTPUT"/* "$DIST_DIR/"
58+
echo "✅ Frontend build completed successfully!"
59+
echo " Build output copied from: $BUILD_OUTPUT"
60+
else
61+
echo "❌ Build output directory not found: $BUILD_OUTPUT"
62+
exit 1
63+
fi
64+
65+
echo ""
66+
echo "========================================"
67+
echo "✅ Frontend packaging completed!"
68+
echo "========================================"
69+
echo ""

src/WebApp.Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ FROM node:20-alpine AS frontend
22
RUN mkdir -p /home/node/app/node_modules && chown -R node:node /home/node/app
33

44
WORKDIR /home/node/app
5-
COPY ./src/frontend/package*.json ./
5+
COPY ./frontend/package*.json ./
66
USER node
77
RUN npm ci
8-
COPY --chown=node:node ./src/frontend/ ./frontend
8+
COPY --chown=node:node ./frontend/ ./frontend
99
# COPY --chown=node:node ./static/ ./static
1010
WORKDIR /home/node/app/frontend
1111
RUN npm run build
@@ -19,13 +19,13 @@ RUN apk add --no-cache --virtual .build-deps \
1919
&& apk add --no-cache \
2020
libpq
2121

22-
COPY ./src/requirements.txt /usr/src/app/
22+
COPY ./requirements.txt /usr/src/app/
2323
RUN pip install --upgrade pip setuptools wheel \
2424
&& pip install --no-cache-dir -r /usr/src/app/requirements.txt \
2525
&& pip install --no-cache-dir uwsgi \
2626
&& rm -rf /root/.cache
2727

28-
COPY ./src/ /usr/src/app/
28+
COPY ./ /usr/src/app/
2929
COPY --from=frontend /home/node/app/static /usr/src/app/static/
3030
WORKDIR /usr/src/app
3131
EXPOSE 80

0 commit comments

Comments
 (0)