Production Deployment Guide
This document explains how to deploy the StarPay payment gateway in production. The production image compiles the React frontend during the build stage and embeds it into the Go executable via go:embed. The backend runs the API, the embedded frontend, PostgreSQL and Redis through Docker Compose; Nginx only needs to reverse proxy the same domain to the application port.
1. Server Preparation
Suggested configuration:
- A Linux server, starting from 2 vCPU / 4 GB RAM.
- Docker and Docker Compose.
- Nginx.
- One HTTPS domain, for example
pay.example.com. - Ports
80and443open.
Example dependency installation:
sudo apt update
sudo apt install -y nginx git curl openssl util-linux
curl -fsSL https://get.docker.com | sudo sh
sudo usermod -aG docker $USERAfter logging back in to the server, verify:
docker version
docker compose version
nginx -v2. Pulling the Code
mkdir -p /opt/starpay
cd /opt/starpay
git clone https://github.com/aurosk-star/starpay.git
cd starpayYou can also build and deploy a verified commit or Release from trusted CI/CD.
3. First Deployment
For manual deployment, starting the interactive wizard directly is recommended. The wizard detects whether this is a first deployment or an existing deployment, and guides you through setting the port, listen scope, image source and backup strategy; existing secrets are only reused and are never displayed in the terminal:
cd /opt/starpay/starpay
./scripts/deploy.shCI or unattended installations can still use the non-interactive command:
./scripts/deploy.sh installThe default image is:
ghcr.io/aurosk-star/starpay:latestOn the first run, when .env.production does not exist, the script generates configuration from a template and sets the file permissions to 600. Secrets are not printed to the terminal. After deployment, check:
docker compose --env-file .env.production -f docker-compose.prod.yml ps
curl http://127.0.0.1:8080/healthzTo specify another image or environment file:
./scripts/deploy.sh install \
--image ghcr.io/aurosk-star/starpay:v0.2.0 \
--env-file /etc/starpay/payment-gateway.envYou can also build from the currently checked-out source:
./scripts/deploy.sh install --local-build--local-build and an explicit --image cannot be used together. In production, using a Release version tag or image digest is recommended, to avoid latest pointing to different content at different times.
4. Manually Configuring Production Environment Variables
Normally you can use the .env.production generated by the deployment script directly. If you need to manage configuration manually, copy the production example file:
cp .env.production.example .env.productionEdit .env.production and change at least the following settings:
APP_ENV=production
HTTP_ADDR=:8080
HTTP_PORT=8080
POSTGRES_PORT=15434
REDIS_PORT=16380
POSTGRES_DB=payment_gateway
POSTGRES_USER=payment
POSTGRES_PASSWORD=replace-with-a-strong-password
JWT_SECRET=replace-with-a-long-random-secret
REFRESH_COOKIE_SECURE=true
REFRESH_COOKIE_SAME_SITE=lax
APP_SECRET_ENCRYPTION_KEY=replace-with-16/24/32-byte-random-value
ORDER_DEFAULT_TTL=15m
ORDER_EXPIRE_SCAN_INTERVAL=30s
ORDER_EXPIRE_SCAN_LIMIT=100
ORDER_EXPIRE_WORKER_CONCURRENCY=2Notes:
JWT_SECRETmust be a production random value.APP_SECRET_ENCRYPTION_KEYmust be 16, 24 or 32 bytes. Do not change it casually after going live, otherwise existing application secrets will need to be reset.- Do not use the default value for
POSTGRES_PASSWORD. - In production, do not expose the PostgreSQL and Redis ports to the public internet; allow access only from the local host or the internal network.
Prefer docker-compose.prod.yml in production. By default it binds only the API port to 127.0.0.1, and PostgreSQL and Redis do not map host ports, avoiding direct exposure to the public internet.
5. Starting the Backend Service Manually
The project ships with docker-compose.prod.yml, which builds the API image and starts PostgreSQL and Redis:
docker compose --env-file .env.production -f docker-compose.prod.yml up -d --buildpostgres:latest may currently be PostgreSQL 18+. The official image for that version requires the data volume to be mounted at /var/lib/postgresql, and the project's production Compose is already configured with that path. Do not change it back to the old path /var/lib/postgresql/data, otherwise the startup error in 18+, these Docker images are configured to store database data... will occur.
The project has decided to continue using postgres:latest and redis:latest in Compose. Before re-pulling or upgrading these two images, you must back up data, read the upstream release notes for PostgreSQL and Redis, and validate the upgrade and rollback procedure in a non-production environment first.
Check status:
docker compose --env-file .env.production -f docker-compose.prod.yml ps
docker compose --env-file .env.production -f docker-compose.prod.yml logs -f apiHealth check:
curl http://127.0.0.1:8080/healthz
curl http://127.0.0.1:8080/v1/pingExample normal response:
{"code":"ok","data":{"status":"ok"},"error":null,"message":"ok"}6. Frontend Build
The admin console is located in web-admin/ and uses Bun. When building the production image, the Dockerfile automatically installs the locked dependencies, builds web-admin/dist, and embeds the output into the Go binary, so there is no need to install Bun separately on the server or keep a static file directory:
docker build -t payment-gateway:latest .For local admin console development, use:
make web-dev7. Configuring Nginx
Same-domain deployment is recommended:
- Frontend pages:
https://pay.example.com/ - Backend API:
https://pay.example.com/v1/... - Health check:
https://pay.example.com/healthz - Payment platform asynchronous notifications:
https://pay.example.com/v1/channel/notify - Checkout:
https://pay.example.com/checkout/{gateway_order_no}
Create the Nginx configuration:
sudo tee /etc/nginx/sites-available/starpay.conf >/dev/null <<'EOF'
server {
listen 80;
server_name pay.example.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
server_name pay.example.com;
ssl_certificate /etc/letsencrypt/live/pay.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/pay.example.com/privkey.pem;
client_max_body_size 10m;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
EOFEnable the configuration:
sudo ln -sf /etc/nginx/sites-available/starpay.conf /etc/nginx/sites-enabled/starpay.conf
sudo nginx -t
sudo systemctl reload nginxCertificates can be obtained with Certbot:
sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d pay.example.com8. Initial Gateway Admin Configuration
After logging in to the admin console, go to "Gateway configuration" and set:
- Site name: for example
starpay-payment-gateway. - Gateway public address:
https://pay.example.com. - Unified asynchronous notification path:
/v1/channel/notify. - Default currency: set according to your business, for example
CNYorUSD. - Default language: for example
zh-CNoren.
The payment channel callback address is uniformly:
https://pay.example.com/v1/channel/notifyAfter PayPal, Alipay and other payments complete, they first return to the gateway checkout result page, and the checkout page then redirects to the merchant return address configured for the order.
9. Release Update Process
The update script first backs up PostgreSQL to backups/, verifies that the backup archive can be read by pg_restore, and then pulls only the new API image; it does not automatically upgrade the running PostgreSQL and Redis. By default it keeps the 7 most recent script backups:
cd /opt/starpay/starpay
git pull --ff-only
./scripts/deploy.sh update \
--image ghcr.io/aurosk-star/starpay:v0.2.0 \
--keep-backups 7To build an update from the current source:
./scripts/deploy.sh update --local-build --keep-backups 7In emergencies, the backup can be skipped, but this is not recommended as a routine release method:
./scripts/deploy.sh update --skip-backupThe frontend and backend are in the same image, so there is no need to publish static files separately or reload Nginx.
Before deployment, the current API image ID is recorded. If rebuilding the new container fails, or /healthz does not return a normal business status, the script rebuilds the API using only the old image and runs the health check again. Even if the application rollback succeeds, the original release command still returns failure, so that CI and operations systems can recognize that this release did not complete.
Non-sensitive metadata of the last successful deployment is recorded in .tmp/last-deployment, including the time, deployment source, image reference, actual image ID, Git commit and backup path; it does not contain passwords or application secrets.
If the Ent schema has changed, the backend automatically runs the migration logic built into the current project at startup. Automatic rollback only restores the API image and does not automatically restore the database, to avoid overwriting new data generated during the release. Production migrations must therefore remain backward compatible; incompatible migrations require a manual recovery plan based on the pre-release backup.
10. Data Backup
deploy.sh update creates a PostgreSQL custom-format archive:
backups/payment-gateway-YYYYMMDD-HHMMSS.dumpAfter the archive is generated, pg_restore --list is executed inside the PostgreSQL container to validate it; if validation fails, the new version is not started. --keep-backups N only cleans up old archives matching the naming above and does not delete other files in the directory. In production, you should still copy backups to off-site storage and rehearse recovery regularly.
To create a backup in the same format manually:
docker exec payment-gateway-postgres pg_dump -U payment -Fc payment_gateway > backup-$(date +%F).dumpBefore restoring, stop API writes and validate the archive against a non-production database first. Example:
docker exec -i payment-gateway-postgres pg_restore \
-U payment --clean --if-exists -d payment_gateway < backup-2026-07-02.dumpRedis is mainly used for queues, caching and idempotency control. In production, retaining the redis_data volume is recommended, along with additional backups configured according to business requirements.
If PostgreSQL fails to initialize on the first deployment because of an old volume path, and you have confirmed that there is no production data, you can clean up the volumes and restart:
docker compose --env-file .env.production -f docker-compose.prod.yml down -v
docker compose --env-file .env.production -f docker-compose.prod.yml up -d --buildIf production data already exists, do not run down -v. Back up the old database first, then migrate according to the official PostgreSQL upgrade procedure or use dump/restore.
11. Go-Live Checklist
curl https://pay.example.com/healthzreturns200.curl https://pay.example.com/v1/pingreturns200.- The admin console can be logged into.
- The public address in "Gateway configuration" is the official HTTPS domain.
- Payment channel keys, certificates and sandbox/production environment settings are correct.
- The payment platform asynchronous notification address is
https://pay.example.com/v1/channel/notify. - The checkout page opens after creating a test order.
- After a successful payment, the gateway result page is reached and redirects to the merchant return address.
- Business notification delivery records are visible in the webhook center.
- Tasks in
pending,processing,resolvedandmanual_requiredstates are visible on the payment compensation page. - Refunds can be created in the refund center, channel refund numbers can be viewed, and incomplete refunds can be retried.
- The
payment:reconciliationsandrefund:processingconsumer groups exist in Redis.
12. FAQ
Frontend refresh returns 404
Make sure Nginx proxies all paths to the application's port 8080. The Go service returns the embedded index.html for frontend navigation paths, but unknown /v1/* API paths and missing JS/CSS files still return 404.
API 404 or CORS issues
Same-domain deployment is recommended in production: the frontend requests /v1/..., and Nginx reverse proxies to 127.0.0.1:8080. Do not let the browser request the container's internal network address directly.
Callbacks not received
Check:
- Whether the notification address configured on the payment platform is a public HTTPS address.
- Whether Nginx correctly reverse proxies
/v1/to the backend. - Backend logs:
docker compose --env-file .env.production -f docker-compose.prod.yml logs -f api. - Whether the certificate, key and sandbox/production environment in the channel configuration match.
Title does not change after renaming the site
After saving in "Gateway configuration" in the admin console, newly opened pages read the public configuration endpoint:
GET /v1/public/site-configConfirm that the site_name returned by this endpoint has been updated.