This guide explains how to build VPS Pilot as a single executable with the UI embedded.
# From project root
chmod +x build.sh
./build.sh
This will:
server/cmd/app/distserver/vps_pilot executable# 1. Build frontend
cd client
npm install
npm run build
# 2. Copy to server
cd ..
rm -rf server/cmd/app/dist
cp -r client/dist server/cmd/app/
# 3. Build Go binary
cd server
go build -o vps_pilot .
The React app is built using Vite, creating an optimized production bundle in client/dist/:
The Go application uses embed.FS to include the frontend files at compile time:
//go:embed dist
var staticFiles embed.FS
This means:
The server serves files with this priority:
/api/v1/*) - JSON responses/assets/*) - JS, CSS, images from embedded FSindex.html for client-side routingcd server
./vps_pilot
Access the application at: http://localhost:8000
# Terminal 1: Run backend
cd server
go run main.go
# Terminal 2: Run frontend dev server
cd client
npm run dev
Frontend: http://localhost:5173 (hot reload) API: http://localhost:8000/api/v1
./build.sh
cd server
./vps_pilot
Everything: http://localhost:8000
./build.sh
cd server
go build -ldflags "-s -w" -o vps_pilot .
-s: Strip debug symbols-w: Strip DWARF debug info# Linux AMD64
GOOS=linux GOARCH=amd64 go build -o vps_pilot-linux-amd64 .
# Linux ARM64
GOOS=linux GOARCH=arm64 go build -o vps_pilot-linux-arm64 .
# Windows
GOOS=windows GOARCH=amd64 go build -o vps_pilot.exe .
vps_pilot/
├── build.sh # Main build script
├── client/
│ ├── dist/ # Frontend build output (gitignored)
│ └── src/ # Frontend source
└── server/
├── cmd/
│ └── app/
│ ├── app.go # Server with embed directive
│ └── dist/ # Embedded UI (gitignored, copied during build)
├── main.go
└── vps_pilot # Final binary (gitignored)
The binary will still run but won’t serve the frontend. This means:
cmd/app/dist was missing during build./build.sh to rebuild with UICheck:
ls -la server/cmd/app/distapp.goThe embedded UI adds ~5-10MB. To reduce:
# Optimize React build
cd client
npm run build
# Strip Go binary
cd ../server
go build -ldflags "-s -w" -o vps_pilot .
# Optional: Compress with UPX
upx --best --lzma vps_pilot
name: Build Release
on:
push:
tags:
- 'v*'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.21'
- name: Build
run: ./build.sh
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: vps_pilot
path: server/vps_pilot
Create server/.env:
# Database
DB_PATH=./data
# JWT
TOKEN_LIFESPAN=60
TOKEN_SECRET=your-secret-key-min-32-chars
# TCP Server
TCP_SERVER_PORT=55001