Deployment
Choose the deployment method that best fits your infrastructure and requirements.
Single-file Executable
Section titled “Single-file Executable”Bun can compile the server into a standalone, portable executable with zero dependencies. This is the easiest way to deploy the signing server.
Build the Executable
Section titled “Build the Executable”From the polys/apps/server directory:
bun build --compile --minify --sourcemap ./src/app.ts --outfile serverWhat this does:
--compile: Creates a standalone executable with embedded Bun runtime--minify: Reduces file size by minifying the code--sourcemap: Generates source maps for debugging--outfile server: Names the output fileserver
Run the Executable
Section titled “Run the Executable”./serverMake sure your environment variables are set (either through a .env file in the same directory or exported in your shell).
Benefits
Section titled “Benefits”- Zero Dependencies: No need to install Bun on the server
- Portable: Copy the single file to any Linux/macOS machine and run it
- Fast Startup: Compiled executables start faster than interpreted code
- Small Size: Typically ~50MB including the runtime
VPS Deployment with systemd
Section titled “VPS Deployment with systemd”Deploy to a Linux VPS with automatic restarts:
# Build locallybun build --compile --minify --sourcemap ./src/app.ts --outfile server
# Copy to your serverrsync -avz server user@your-server.com:/opt/polys-server/
# SSH into serverssh user@your-server.comcd /opt/polys-serverchmod +x server
# Create systemd servicesudo tee /etc/systemd/system/polys-server.service > /dev/null << 'EOF'[Unit]Description=Polys Signing ServerAfter=network.target
[Service]Type=simpleUser=polysWorkingDirectory=/opt/polys-serverEnvironmentFile=/opt/polys-server/.envExecStart=/opt/polys-server/serverRestart=on-failureRestartSec=10
[Install]WantedBy=multi-user.targetEOF
# Create .env file on server with your configuration# Add: POLYS_POLYMARKET_API_KEY, POLYS_POLYMARKET_SECRET,# POLYS_POLYMARKET_PASSPHRASE, POLYS_API_TOKENSsudo nano /opt/polys-server/.env
# Start the servicesudo systemctl daemon-reloadsudo systemctl enable polys-serversudo systemctl start polys-server
# Check statussudo systemctl status polys-serverDocker
Section titled “Docker”Basic Docker Setup
Section titled “Basic Docker Setup”Create a Dockerfile in polys/apps/server:
FROM oven/bun:1
WORKDIR /app
COPY package.json bun.lockb ./RUN bun install --frozen-lockfile
COPY . .
ENV NODE_ENV=productionEXPOSE 8080
CMD ["bun", "run", "start"]Build and run:
# Build the imagedocker build -t polys-server .
# Run with environment variables from filedocker run -p 8080:8080 --env-file .env polys-server
# Or with inline environment variablesdocker run -p 8080:8080 \ -e POLYS_POLYMARKET_API_KEY=your_key \ -e POLYS_POLYMARKET_SECRET=your_secret \ -e POLYS_POLYMARKET_PASSPHRASE=your_passphrase \ -e POLYS_API_TOKENS=token1,token2,token3 \ polys-serverDocker Compose
Section titled “Docker Compose”Create docker-compose.yml:
version: '3.8'
services: polys-server: build: . ports: - "8080:8080" environment: - POLYS_POLYMARKET_API_KEY=${POLYS_POLYMARKET_API_KEY} - POLYS_POLYMARKET_SECRET=${POLYS_POLYMARKET_SECRET} - POLYS_POLYMARKET_PASSPHRASE=${POLYS_POLYMARKET_PASSPHRASE} - POLYS_API_TOKENS=${POLYS_API_TOKENS} - POLYS_SERVER_HOSTNAME=0.0.0.0 - POLYS_SERVER_PORT=8080 restart: unless-stopped healthcheck: test: ["CMD", "curl", "-f", "http://localhost:8080/health"] interval: 30s timeout: 10s retries: 3 start_period: 40sDeploy:
docker-compose up -dCloud Platforms
Section titled “Cloud Platforms”EC2 with Single-file Executable
Section titled “EC2 with Single-file Executable”- Launch an EC2 instance (Amazon Linux 2 or Ubuntu)
- Copy the executable:
rsync -avz server ec2-user@your-instance:/home/ec2-user/ - Set up systemd service as shown in the VPS section
- Configure security groups to allow inbound traffic on port 8080
ECS/Fargate
Section titled “ECS/Fargate”-
Push Docker image to ECR:
Terminal window aws ecr create-repository --repository-name polys-serverdocker tag polys-server:latest <account-id>.dkr.ecr.<region>.amazonaws.com/polys-server:latestdocker push <account-id>.dkr.ecr.<region>.amazonaws.com/polys-server:latest -
Create task definition with environment variables from Secrets Manager
-
Create ECS service
-
Set up Application Load Balancer with SSL certificate
Google Cloud
Section titled “Google Cloud”Cloud Run
Section titled “Cloud Run”# Build and push to Artifact Registrygcloud builds submit --tag gcr.io/<project-id>/polys-server
# Deploy to Cloud Rungcloud run deploy polys-server \ --image gcr.io/<project-id>/polys-server \ --platform managed \ --region us-central1 \ --allow-unauthenticated \ --set-env-vars POLYS_POLYMARKET_API_KEY=your_key \ --set-secrets POLYS_POLYMARKET_SECRET=secret-name:latest \ --port 8080GCE with Docker
Section titled “GCE with Docker”- Create a Compute Engine instance
- Install Docker
- Pull and run your Docker image
- Use Cloud Load Balancing for SSL termination
Digital Ocean
Section titled “Digital Ocean”App Platform
Section titled “App Platform”- Connect your GitHub repository
- Select the
apps/serverdirectory - Configure environment variables in the dashboard
- Deploy automatically on git push
Droplet with Docker
Section titled “Droplet with Docker”- Create a Droplet with Docker pre-installed
- Copy
docker-compose.ymland.env - Run
docker-compose up -d - Use a firewall to restrict access
Railway
Section titled “Railway”# Install Railway CLInpm install -g @railway/cli
# Loginrailway login
# Initialize projectrailway init
# Set environment variablesrailway variables set POLYS_POLYMARKET_API_KEY=your_keyrailway variables set POLYS_POLYMARKET_SECRET=your_secretrailway variables set POLYS_POLYMARKET_PASSPHRASE=your_passphraserailway variables set POLYS_API_TOKENS=token1,token2,token3
# Deployrailway upTroubleshooting
Section titled “Troubleshooting”Server Won’t Start
Section titled “Server Won’t Start”# Check logssudo journalctl -u polys-server -f # systemddocker logs polys-server # Dockerpm2 logs polys-server # PM2Port Conflicts
Section titled “Port Conflicts”# Check what's using the portsudo lsof -i :8080sudo netstat -tulpn | grep 8080
# Use a different portPOLYS_SERVER_PORT=3000 ./serverNext Steps
Section titled “Next Steps”- Client Usage - Integrate with your application
- Troubleshooting - Solve common issues
- Monitoring Guide - Set up monitoring
See Also
Section titled “See Also”- Setup Guide - Initial configuration
- Overview - Understanding order attribution
- Security Best Practices - Production security