docker-compose file is located in the root directory of the project.
To run the database, run: docker-compose up
It will start the database on localhost:5432 with the following environment variables:
POSTGRES_USER: userPOSTGRES_PASSWORD: pwdPOSTGRES_DB: game
It will also start the adminer web interface on localhost:8081.
Server expects environment variables as show in ./server/example.env
To run the server
# in the server directory
go run ./srcServer supports these flags:
-port: port to listen on (default:8080)-profile: enable profiling (profiler will be started onlocalhost:6060)-lobbies: number of lobbies to run (default:50)-logfile: log file to write to (if provided, logs will be written to this file, otherwise to the console)
The app will start on localhost:8080 and the server will be running on localhost:8080/api/game.
Client expects enviroment variables as shown in ./client/example.env
pnpm install
pnpm devIntegration tests for lifecycle of a connection. For these tests to run, the server must be running on localhost:8080.
go test -count=1 ./testing/lifecycleStress tests for the server. These tests also expect the server to be running and the runner supports these flags:
-url: websocket url to connect to (default:ws://localhost:8080/api/game)-duration: duration of the test (default:2m)-clients: number of clients to run (default:10)-ramp: ramp up time for clients to connect (default:20s)
go run ./testing/perfWhile running the stress test and if the server was started with the -profile flag,
script profile.sh can be run in the project root directory. This script will start the
go profiler and open the pprof web interface in the browser.
bash ./profile.sh- Create a deploy user
sudo useradd -m -s /bin/bash deploy
# copy ssh keys
rsync --archive --chown=deploy:deploy ~/.ssh /home/deploy/.ssh- Install docker
- Install nginx
- Run
deploy-setup.sh <domain>on the server to setup the deploy user and nginx
What the script does:
- Creates app directory (/opt/paddle-game)
- Sets up database
- Creates docker-compose.yml
- Starts postgres
- Creates systemd services
- paddle-game.server.service for the go server
- paddle-game.client.service for the client
- Creates nginx config (/etc/nginx/sites-available/)
- Enables services
- Creates sudoers file (/etc/sudoers.d/deploy) to allow restarting services
What needs to be done manually:
-
Create an origin server certificate on cloudflare and create these files:
- /etc/ssl/cloudflare/paddle.crt - contains the certificate
- /etc/ssl/cloudflare/paddle.key - contains the private key
-
Place env variables in:
- /opt/paddle-game/shared/server.env
- /opt/paddle-game/shared/client.env
- Run
deploy.sh <server_ip>locally to deploy the project
What the script does:
- Builds the server and client locally
- Copies the server binary to the deploy user
- Copies the client build to the deploy user
- Swaps the current release with the new one
- Migrates the database using the src/db/migrator.bin
- Cleans up old releases (keeps the last 6)