Skip to content

Commit e6fc551

Browse files
committed
Embed Gate app into Thunder
1 parent 75e057a commit e6fc551

13 files changed

Lines changed: 4312 additions & 3317 deletions

File tree

.github/workflows/release.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,10 @@ jobs:
130130
OS="${platform%%:*}"
131131
ARCH="${platform#*:}"
132132
133-
echo "🔨 Building Thunder backend for $OS/$ARCH..."
133+
echo "🔨 Building Thunder backend & frontend for $OS/$ARCH..."
134134
make build_backend OS=$OS ARCH=$ARCH
135-
135+
make build_frontend OS=$OS ARCH=$ARCH
136+
136137
# Optional: Add a small delay to prevent resource contention
137138
sleep 1
138139
done

Dockerfile

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@
1717
# ----------------------------------------------------------------------------
1818

1919
# WSO2 Thunder Docker Image
20-
# Build stage - compile the Go binary for the target architecture
20+
# Build stage - compile the Go binary and build frontend for the target architecture
2121
FROM golang:1.25-alpine AS builder
2222

23-
# Install build dependencies
24-
RUN apk add --no-cache git make bash sqlite openssl zip
23+
# Install build dependencies including Node.js and npm
24+
RUN apk add --no-cache git make bash sqlite openssl zip nodejs npm
25+
26+
# Set environment variables for CI build
27+
ENV CI=true
2528

2629
# Set the working directory
2730
WORKDIR /app
@@ -53,12 +56,12 @@ RUN if [ -n "$CERT_FILE" ] && [ -n "$KEY_FILE" ] && [ -f "$CERT_FILE" ] && [ -f
5356
echo "✅ New certificates generated"; \
5457
fi
5558

56-
# Build the binary for the target architecture
59+
# Build both frontend and backend for the target architecture
5760
ARG TARGETARCH
5861
RUN if [ "$TARGETARCH" = "amd64" ]; then \
59-
./build.sh build_backend linux amd64; \
62+
./build.sh build linux amd64; \
6063
else \
61-
./build.sh build_backend linux arm64; \
64+
./build.sh build linux arm64; \
6265
fi
6366

6467
# List the contents of the dist directory to verify zip output
@@ -104,11 +107,15 @@ RUN chown -R thunder:thunder /opt/thunder && \
104107
# Expose the default port
105108
EXPOSE 8090
106109

110+
# Expose the Gate port
111+
EXPOSE 9090
112+
107113
# Switch to thunder user
108114
USER thunder
109115

110116
# Set environment variables
111117
ENV BACKEND_PORT=8090
118+
ENV FRONTEND_PORT=9090
112119

113120
# Start the application
114121
CMD ["./start.sh"]

Makefile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,14 @@ clean_all:
4444
clean:
4545
./build.sh clean $(OS) $(ARCH)
4646

47-
build: build_backend build_samples
47+
build: build_backend build_frontend build_samples
4848

4949
build_backend:
5050
./build.sh build_backend $(OS) $(ARCH)
5151

52+
build_frontend:
53+
./build.sh build_frontend
54+
5255
package_samples:
5356
./build.sh package_samples $(OS) $(ARCH)
5457

@@ -70,6 +73,7 @@ build_with_coverage:
7073
@echo "================================================================"
7174
./build.sh test_unit $(OS) $(ARCH)
7275
ENABLE_COVERAGE=true ./build.sh build_backend $(OS) $(ARCH)
76+
./build.sh build_frontend
7377
./build.sh test_integration $(OS) $(ARCH)
7478
./build.sh merge_coverage $(OS) $(ARCH)
7579
@echo "================================================================"
@@ -101,8 +105,9 @@ help:
101105
@echo " backend - Clean, build, and test only the backend."
102106
@echo " clean - Remove build artifacts."
103107
@echo " clean_all - Remove all build artifacts including distribution files."
104-
@echo " build - Build the Go project and frontend, then package."
108+
@echo " build - Build the complete Thunder application (backend + frontend + samples)."
105109
@echo " build_backend - Build the backend Go application."
110+
@echo " build_frontend - Build the Next.js frontend applications."
106111
@echo " package_samples - Package sample applications."
107112
@echo " build_samples - Build sample applications."
108113
@echo " test_unit - Run unit tests."
@@ -118,7 +123,7 @@ help:
118123
@echo " lint - Run golangci-lint on the project."
119124
@echo " help - Show this help message."
120125

121-
.PHONY: all prepare clean clean_all build build_samples package_samples run
126+
.PHONY: all prepare clean clean_all build build_backend build_frontend build_samples package_samples run
122127
.PHONY: docker-build docker-build-latest docker-build-multiarch
123128
.PHONY: docker-build-multiarch-latest docker-build-multiarch-push
124129
.PHONY: test_unit test_integration build_with_coverage test

build.ps1

Lines changed: 92 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ $SAMPLE_APP_VERSION = $packageJson.version
118118
$SAMPLE_APP_FOLDER = "${BINARY_NAME}-sample-app-${SAMPLE_APP_VERSION}-${SAMPLE_PACKAGE_OS}-${SAMPLE_PACKAGE_ARCH}"
119119

120120
# Server ports
121+
$FRONTEND_PORT = 9090
121122
$BACKEND_PORT = 8090
122123

123124
# Directories
@@ -133,6 +134,9 @@ $REPOSITORY_DB_DIR = Join-Path $REPOSITORY_DIR "database"
133134
$SERVER_SCRIPTS_DIR = Join-Path $BACKEND_BASE_DIR "scripts"
134135
$SERVER_DB_SCRIPTS_DIR = Join-Path $BACKEND_BASE_DIR "dbscripts"
135136
$SECURITY_DIR = "repository/resources/security"
137+
$FRONTEND_BASE_DIR = "frontend"
138+
$GATE_APP_DIR = "apps/gate"
139+
$FRONTEND_GATE_APP_DIR = Join-Path $FRONTEND_BASE_DIR $GATE_APP_DIR
136140
$SAMPLE_BASE_DIR = "samples"
137141
$SAMPLE_APP_DIR = Join-Path $SAMPLE_BASE_DIR "apps/oauth"
138142
$SAMPLE_APP_SERVER_DIR = Join-Path $SAMPLE_APP_DIR "server"
@@ -274,6 +278,32 @@ function Build-Backend {
274278
Write-Host "================================================================"
275279
}
276280

281+
function Build-Frontend {
282+
Write-Host "================================================================"
283+
Write-Host "Building Next.js frontend apps..."
284+
285+
# Check if pnpm is installed, if not install it
286+
if (-not (Get-Command pnpm -ErrorAction SilentlyContinue)) {
287+
Write-Host "pnpm not found, installing..."
288+
& npm install -g pnpm
289+
}
290+
291+
# Navigate to frontend directory and install dependencies
292+
Push-Location $FRONTEND_BASE_DIR
293+
try {
294+
Write-Host "Installing frontend dependencies..."
295+
& pnpm install
296+
297+
Write-Host "Building gate app..."
298+
& pnpm --filter gate build
299+
}
300+
finally {
301+
Pop-Location
302+
}
303+
304+
Write-Host "================================================================"
305+
}
306+
277307
function Initialize-Databases {
278308
param(
279309
[bool]$override = $false
@@ -362,13 +392,37 @@ function Prepare-Backend-For-Packaging {
362392
Write-Host "================================================================"
363393
}
364394

365-
function Package-Backend {
395+
function Prepare-Frontend-For-Packaging {
396+
Write-Host "================================================================"
397+
Write-Host "Copying frontend artifacts..."
398+
399+
$package_folder = Join-Path $DIST_DIR $PRODUCT_FOLDER
400+
$gate_app_folder = Join-Path $package_folder $GATE_APP_DIR
401+
New-Item -Path $gate_app_folder -ItemType Directory -Force | Out-Null
402+
403+
# Copy Next.js standalone output with all files including hidden ones
404+
$standalone_path = Join-Path $FRONTEND_GATE_APP_DIR "dist\.next\standalone"
405+
if (Test-Path $standalone_path) {
406+
Write-Host "Copying gate app build output..."
407+
# Copy all files including hidden ones from standalone directory
408+
Get-ChildItem -Path $standalone_path -Force | ForEach-Object {
409+
Copy-Item -Path $_.FullName -Destination $gate_app_folder -Recurse -Force
410+
}
411+
}
412+
else {
413+
Write-Host "Warning: Frontend build output not found at $standalone_path"
414+
}
415+
Write-Host "================================================================"
416+
}
417+
418+
function Package {
366419
Write-Host "================================================================"
367-
Write-Host "Packaging backend artifacts..."
420+
Write-Host "Packaging backend & frontend artifacts..."
368421

369422
$package_folder = Join-Path $DIST_DIR $PRODUCT_FOLDER
370423
New-Item -Path $package_folder -ItemType Directory -Force | Out-Null
371424

425+
Prepare-Frontend-For-Packaging
372426
Prepare-Backend-For-Packaging
373427

374428
# Copy the appropriate startup script based on the target OS
@@ -953,6 +1007,9 @@ function Run-Server {
9531007
Write-Host "=== Ensuring server certificates exist ==="
9541008
Ensure-Certificates -cert_dir (Join-Path $BACKEND_DIR $SECURITY_DIR)
9551009

1010+
Write-Host "=== Ensuring portal certificates exist ==="
1011+
Ensure-Certificates -cert_dir $FRONTEND_GATE_APP_DIR
1012+
9561013
Write-Host "=== Ensuring sample app certificates exist ==="
9571014
Ensure-Certificates -cert_dir $SAMPLE_APP_DIR
9581015

@@ -969,21 +1026,35 @@ function Run-Server {
9691026
}
9701027
}
9711028

1029+
Kill-Port $FRONTEND_PORT
9721030
Kill-Port $BACKEND_PORT
9731031

974-
Write-Host "=== Starting backend ==="
1032+
Write-Host "=== Starting frontend on https://localhost:$FRONTEND_PORT ==="
1033+
$env:FRONTEND_PORT = $FRONTEND_PORT
1034+
1035+
Push-Location $FRONTEND_BASE_DIR
1036+
try {
1037+
$frontendProcess = Start-Process -FilePath "pnpm" -ArgumentList "--filter", "gate", "start" -PassThru -NoNewWindow
1038+
}
1039+
finally {
1040+
Pop-Location
1041+
}
1042+
1043+
Write-Host "=== Starting backend on https://localhost:$BACKEND_PORT ==="
9751044
$env:BACKEND_PORT = $BACKEND_PORT
9761045

9771046
Push-Location $BACKEND_DIR
9781047
try {
979-
Start-Process -FilePath "go" -ArgumentList "run", "." -PassThru
1048+
$backendProcess = Start-Process -FilePath "go" -ArgumentList "run", "." -PassThru -NoNewWindow
9801049
}
9811050
finally {
9821051
Pop-Location
9831052
}
9841053

9851054
Write-Host ""
986-
Write-Host "⚡ Thunder Backend : https://localhost:$BACKEND_PORT"
1055+
Write-Host "🚀 Servers running:"
1056+
Write-Host "👉 Frontend: https://localhost:$FRONTEND_PORT"
1057+
Write-Host "👉 Backend : https://localhost:$BACKEND_PORT"
9871058
Write-Host "Press Ctrl+C to stop."
9881059

9891060
# Wait for user to press Ctrl+C
@@ -994,6 +1065,12 @@ function Run-Server {
9941065
}
9951066
catch [System.Management.Automation.PipelineStoppedException] {
9961067
Write-Host "Stopping servers..."
1068+
if ($frontendProcess -and -not $frontendProcess.HasExited) {
1069+
Stop-Process -Id $frontendProcess.Id -Force -ErrorAction SilentlyContinue
1070+
}
1071+
if ($backendProcess -and -not $backendProcess.HasExited) {
1072+
Stop-Process -Id $backendProcess.Id -Force -ErrorAction SilentlyContinue
1073+
}
9971074
}
9981075
}
9991076

@@ -1007,7 +1084,10 @@ switch ($Command) {
10071084
}
10081085
"build_backend" {
10091086
Build-Backend
1010-
Package-Backend
1087+
Package
1088+
}
1089+
"build_frontend" {
1090+
Build-Frontend
10111091
}
10121092
"build_samples" {
10131093
Build-Sample-App
@@ -1018,7 +1098,8 @@ switch ($Command) {
10181098
}
10191099
"build" {
10201100
Build-Backend
1021-
Package-Backend
1101+
Build-Frontend
1102+
Package
10221103
Build-Sample-App
10231104
Package-Sample-App
10241105
}
@@ -1039,12 +1120,13 @@ switch ($Command) {
10391120
Run-Server
10401121
}
10411122
default {
1042-
Write-Host "Usage: ./build.ps1 {clean|build|test|run} [OS] [ARCH]"
1123+
Write-Host "Usage: ./build.ps1 {clean|build|build_backend|build_frontend|test|run} [OS] [ARCH]"
10431124
Write-Host ""
10441125
Write-Host " clean - Clean build artifacts"
10451126
Write-Host " clean_all - Clean all build artifacts including distributions"
1046-
Write-Host " build - Build the Thunder server and sample applications"
1047-
Write-Host " build_backend - Build the Thunder backend server"
1127+
Write-Host " build - Build the complete Thunder application (backend + frontend + samples)"
1128+
Write-Host " build_backend - Build only the Thunder backend server"
1129+
Write-Host " build_frontend - Build only the Next.js frontend applications"
10481130
Write-Host " build_samples - Build the sample applications"
10491131
Write-Host " test_unit - Run unit tests with coverage"
10501132
Write-Host " test_integration - Run integration tests"

0 commit comments

Comments
 (0)