Skip to content

Commit

Permalink
Merge pull request #14 from willroberts/local-development
Browse files Browse the repository at this point in the history
Improves local development
  • Loading branch information
marwanhilmi committed Aug 19, 2022
2 parents f1917a4 + caf9598 commit c4d3352
Show file tree
Hide file tree
Showing 11 changed files with 231 additions and 89 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
54 changes: 19 additions & 35 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,40 +1,24 @@
node_modules/*
desktop/app/node_modules/*
.tmp
.sass-cache
# Build artifacts
/app/data/packages.js
/app/localization/locales/en/index.json
/dist
node_modules

# Development artifacts
*.log
*.log.txt
dump.rdb
.env
.env_for_alpha
.foreman
.vagrant/
.idea/
.DS_Store
/app/data/packages.js
/matchmaker/*.log
/server/*.log
.env_for_alpha
/public
/dist
.node-version
.env_for_dev
dump.rdb
cli/config/*.temp
cli/config
.vscode
scripts/codex/images
npm-debug.log
scripts/**/*.log.txt
desktop/node_modules
desktop/src
scratch.txt
Procfile
/scratch
.sass-cache
.steamcache
/config/production_local.json
/scripts/aws-utility/node_modules
/scripts/codex/node_modules
/cli/codes
/app/localization/locales/en/index.json
/scripts/localization/localization_output/
/scripts/localization/node_modules/
/cli/*Snapshots/
yarn-error.log
.pgdata
.tmp
.vagrant/
.vscode
/.pgdata

# OSX-specific artifacts
.DS_Store
132 changes: 114 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,127 @@
# OPEN DUELYST
🚧 WIP 🚧
# Duelyst

## Requirements
This is the source code for Duelyst, a digital collectible card game and turn-based strategy hybrid developed by Counterplay Games and released in 2016.

### Client Architecture

The game client is a Backbone.js + Marionette application which runs in the browser. Code can be found in `app/`, and configuration can be found in `app/common/config.js`.

### Server Architecture

Duelyst's backend primarily consists of four CoffeeScript services:

API Server:

- The API server is an Express.js app which handles routes for game clients.
- The service stores user and game data in Postgres and Redis.
- The service listens on port 3000 by default, and it serves the browser client on the default route.
- Code can be found in `server/api.coffee`, and configuration can be found in `config/`.

Game Server:

- The Game server is a Socket.IO WebSocket server which handles multiplayer games.
- The service enqueues tasks in Redis to be picked up by the workers.
- The service listens on port 8000 by default.
- Code can be found in `server/game.coffee`, and configuration can be found in `config/`.

Single Player (SP) Server:

- The SP server is a Socket.IO WebSocket server which handles single-player games.
- The service enqueues tasks in Redis to be picked up by the workers.
- The service listens on port 8000 by default.
- Code can be found in `server/single_player.coffee`, and configuration can be found in `config/`.

Worker:

- The worker uses Kue to poll Redis-backed queues for tasks like game creation and matchmaking.
- Some matchmaking tasks also use Postgres, for server healthchecks and retrieving bot users.
- Code can be found in `worker/worker.coffee`, and configuration can be found in `config/`.
- A Kue GUI is available at `http://localhost:3000` via `docker compose up worker-ui`).

#### Other Dependencies

Postgres:

- Client code can be found in `server/lib/data_access/knex.coffee` and `server/knexfile.js`, and configuration can be found in `config/`
- Migrations can be run via `docker compose up migrate`
- An admin UI is available at `http://localhost:8080` via `docker compose up adminer`

Redis:

- Client code can be found in `server/redis/r-client.coffee`, and configuration can be found in `config/`

Consul:

- Not required in single-server deployments, but was historically used for service discovery, matchmaking, and spectating
- Client code can be found in `server/lib/consul.coffee`, and configuration can be found in `config/`

## Setting up a development environment

#### Requirements

- [Docker](https://www.docker.com/products/docker-desktop/)
- [Node.js](https://nodejs.org/en/download/)
- [Node.js](https://nodejs.org/en/download/) with NPM

## Setup
#### Building the code

- `npm install -g yarn`
- `yarn install --dev`
- `yarn build` to build client
- `yarn watch` to build client continuously
- Modify `development.json` with:
- Firebase Realtime endpoint and secret
- Redis connection string
- Postgres connection string
Install NPM tools:
```
npm install -g typescript yarn gulpjs/gulp-cli
```

## Quick Start
Compile TypeScript dependencies:
```
cd packages/chroma-js
tsc
```

- `docker compose up -d` to start all services locally
Build the game:
```
yarn install --dev
yarn build
```

The above build command builds the game and its required resources for the first time, which will take a few minutes. Use it when making changes to resources like cards, codex data, cosmetics, etc.

Once the initial build is done, you can save time by rebuilding only the app (takes about 50 seconds):
```
yarn build:app
```

Or rebuild only the HTML/CSS and localization files (takes about 5 seconds):
```
yarn build:web
```

When working in the `server` or `worker` directories, no rebuilds are needed. See below for instructions to test changes in Docker instead.

#### Starting a test environment in Docker

- Modify `development.json` with:
- Firebase Realtime endpoint and secret
- Redis connection string
- Postgres connection string
- Optionally enable debug logging for sockets by prepending `yarn $1` with `DEBUG=*` in `docker/start`
- Use `docker compose up` to start required services locally, or start individual services:
- `redis`
- `db` (Postgres)
- `adminer` (Postgres admin UI)
- `api` (HTTP server)
- `game` (Multi-player server)
- `sp` (Single-player server)
- `worker` (Game workers)
- `worker-ui` (Game worker UI)
- `migrate` (Postgres migrations)
- Run database migrations
- Use `npm install -g knex` to install the Postgres client
- In another terminal window, use `NODE_ENV=development yarn migrate:latest` to run database migrations
- On Windows: `$env:NODE_ENV = 'development'; yarn migrate:latest`
- Only need to run this once (unless you change Postgres schema)
- Open http://localhost:3000 in a browser to load the game client

## Scripts
#### Starting individual components

- `yarn api` to start api server
- `yarn game` to start game server
- `yarn sp` to start single player game server
- `yarn worker` to start worker
- `NODE_ENV=development yarn migrate:latest` to run database migrations
- `yarn worker` to start worker
19 changes: 16 additions & 3 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
version: "3.9"

x-base-service: &base
image: node:latest
image: node:lts
environment:
DEBUG: "*"
REDIS_IP: redis
POSTGRES_CONNECTION: "pg://duelyst:duelyst@db/duelyst"
depends_on:
Expand Down Expand Up @@ -33,6 +32,8 @@ services:
- ./.pgdata:/var/lib/postgresql/data
adminer:
image: adminer
profiles:
- donotstart
restart: always
ports:
- 8080:8080
Expand All @@ -45,10 +46,18 @@ services:

game:
<<: *base
profiles:
- donotstart
ports:
- 8000:8000
command: docker/start game

sp:
<<: *base
ports:
- 8000:8000
command: docker/start sp

worker:
<<: *base
ports:
Expand All @@ -57,12 +66,16 @@ services:

worker-ui:
<<: *base
profiles:
- donotstart
ports:
- 3001:3000
command: docker/start worker-ui

migrate:
image: node:latest
image: node:lts
profiles:
- donotstart
environment:
DEBUG: "*"
NODE_ENV: development
Expand Down
6 changes: 3 additions & 3 deletions docker/start
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash

yarn install --dev
# NODE_ENV=development yarn migrate:latest
DEBUG=* yarn $1

# To enable socket debug logs, prepend this command with DEBUG=*
yarn $1
20 changes: 19 additions & 1 deletion gulp/clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,25 @@ export function all() {
'desktop/src',
'desktop/node_modules'
])
return del('dist')
}

// Cleans out app code only
export function app() {
return del('dist/src/duelyst.js')
}

// Cleans out HTML/CSS only
export function web() {
return del([
'dist/src/duelyst.css',
'dist/src/index.html',
'dist/src/vendor.js'
])
}

// Cleans out localization files only
export function locales() {
return del('dist/src/resources/locales')
}

// Cleans out desktop specific parts output folders
Expand Down
Loading

0 comments on commit c4d3352

Please sign in to comment.