Skip to content

Commit

Permalink
feat(yukon): add yukon cpps scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
n0bodysec committed Sep 15, 2022
1 parent f097876 commit 3ef3c02
Show file tree
Hide file tree
Showing 10 changed files with 365 additions and 0 deletions.
143 changes: 143 additions & 0 deletions yukon/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
##############################################
# Database
##############################################
#
# MARIADB_HOST
# ------------
# The hostname of the mariadb installation.
# It is fine to leave this if you are using
# the included docker service.
#
# MARIADB_PORT
# ------------
# The port of the mariadb installation.
# It is fine to leave this if you are using
# the included docker service.
#
# MARIADB_USER
# ------------
# The name for the new mariadb user.
#
# MARIADB_PASSWORD
# ----------------
# The password for the mariadb user. It
# is recommended that you change this to
# something secure!
#
# MARIADB_ROOT_PASSWORD
# ---------------------
# The password for the mariadb root user.
# It is recommended that you change this
# to something secure!
#
# MARIADB_DATABASE
# ----------------
# The name for the new mariadb database.
##############################################

MARIADB_HOST=mariadb
MARIADB_PORT=3306
MARIADB_USER=user
MARIADB_PASSWORD=password
MARIADB_ROOT_PASSWORD=s0m3s3cr3tp4ssw0rd
MARIADB_DATABASE=yukon

##############################################
# Web
##############################################
#
# WEB_PORT
# --------
# The port that the nginx container will
# listen on. It is fine to leave this so long
# as you do not have a web server running
# already.
#
# WEB_HOSTNAME
# ------------
# The hostname you intend to serve web traffic
# through. For example `clubpenguin.com`.
# Also include the protocol. (e.g https://).
#
##############################################

WEB_PORT=80
WEB_HOSTNAME=http://localhost
# WEB_CREATE_DOMAIN=http://localhost
# WEB_CREATE_PORT=8080

##############################################
# Game
##############################################
#
# GAME_ADDRESS
# ------------
# Where the Yukon Client will connect to the
# game server. It is fine to leave this if
# you are using the included docker service.
#
# GAME_SOCKETIO_SSL
# -----------------
# Enable or disable the use of SSL for ws.
# If you are using some proxy service like
# Cloudflare, then it is not needed.
#
# GAME_CRYPTO_SECRET
# ------------------
# A secure 32 byte hex string. Please do not
# include spaces. You can use Node.js'
# crypto module to generate this.
# crypto.randomBytes(32).toString('hex');
# https://browserling.com/tools/random-bytes
#
# GAME_LOGIN_HOST
# ---------------
# The login server hostname. Usually fine to
# leave this. Intended for external
# game servers.
#
# GAME_LOGIN_PORT
# ---------------
# The login server port. Usually fine to leave
# this.
#
# GAME_BLIZZARD_HOST
# ------------------
# The blizzard server hostname. Usually fine
# to leave this. Intended for external
# game servers.
#
# GAME_BLIZZARD_PORT
# ------------------
# The blizzard server port. Usually fine to leave
# this.
##############################################

GAME_ADDRESS=http://server
GAME_SOCKETIO_SSL=false
GAME_CRYPTO_SECRET=ecbb874f28ae93e84ec54b08fd9810bce265452d9e6125a2b91a21de5bfc3415
GAME_LOGIN_HOST=localhost
GAME_LOGIN_PORT=6111
GAME_BLIZZARD_HOST=localhost
GAME_BLIZZARD_PORT=6112

##############################################
# Docker
##############################################
#
# PUID
# ----
# The UID of the user who will run the server
# Docker container. This is not needed for
# Windows users.
#
# PGID
# ----
# The GID of the user who will run the server
# Docker container. This is not needed for
# Windows users.
#
##############################################

PUID=1000
PGID=1000
13 changes: 13 additions & 0 deletions yukon/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# private data
.data/
.env
yukon-server/ssl/*
!yukon-server/ssl/.gitkeep

# yukon sources
yukon/src/
yukon-server/src/

# nginx files
www/*
!www/.gitkeep
44 changes: 44 additions & 0 deletions yukon/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Yukon

Yukon CPPS Emulator Docker Image

## 🃏 Features

- Almost Plug N' Play!
- Develop without installing node or dependencies.
- Run isolated instances (and multiple instances too!).
- Secured environment.

## 🚀 Deploy

1. Create a `docker-compose.override.yml` file and edit it to suit your needs (***optional***).
2. Copy `.env.example` to `.env` and edit it accordingly.
3. Clone `yukon` and `yukon-server` to `yukon/src` and `yukon-server/src`, respectively.
4. Build `yukon` and copy the contents of the `yukon/src/dist` folder into `www` folder.
5. Copy the contents of the `yukon/src/assets` folder into `www` folder.
6. Copy the contents of the `assets` **repository** into `www` folder.
7. Download a copy of [ruffle self-hosted](https://ruffle.rs/#downloads) and put it into `www/assets/scripts/lib/ruffle` folder.
8. Build `yukon-server`.
9. Run `docker compose up -d`.

```sh
git clone https://github.com/wizguin/yukon.git yukon/src
git clone https://github.com/wizguin/yukon-server.git yukon-server/src
docker compose run node sh -c "cd client && npm i && npm run build && cd ../server && npm i && npm run build"
git clone <assets-repo-url> www/data/assets
cp -r yukon/src/assets/ www
cp -r yukon/src/dist/* www
mkdir -p www/assets/scripts/lib/ruffle
wget -O - https://github.com/ruffle-rs/ruffle/releases/download/nightly-2022-09-14/ruffle-nightly-2022_09_14-web-selfhosted.zip | (cd www/assets/scripts/lib/ruffle && unzip -)
docker compose up -d
```

## 👍 Acknowledgements

- [wizguin](https://github.com/wizguin/) - Yukon Developer.
- [Solero Team](https://github.com/solero/) - For their [.env syntax](https://github.com/solero/wand/blob/master/.env).

## 📜 Notes

- Remember to update your .env file.
- The PHP docker image is not included. If you want to use the default register script (**not recommended**), add the image yourself and update the `templates/yukon.conf.template` file as well.
66 changes: 66 additions & 0 deletions yukon/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
version: '3.9'

services:
client:
image: yukon/client
build: ./yukon
restart: unless-stopped
ports: [ '${WEB_PORT}:80' ]
networks: [ 'default' ]
depends_on: [ 'server' ]
env_file: [ '.env' ]
volumes:
- /dev/null:/etc/nginx/conf.d/default.conf:ro
- ./www:/usr/share/nginx/html:ro
- ./templates/yukon.conf.template:/etc/nginx/conf.d/yukon.conf.template
command: [
"dockerize",
"-template", "/etc/nginx/conf.d/yukon.conf.template:/etc/nginx/conf.d/yukon.conf",
"nginx", "-g", "daemon off;"
]

server:
image: yukon/server
build:
context: ./yukon-server
args:
PUID: ${PUID:-1000}
PGID: ${PGID:-1000}
restart: unless-stopped
# ports: [ '${GAME_LOGIN_PORT}:${GAME_LOGIN_PORT}', '${GAME_BLIZZARD_PORT}:${GAME_BLIZZARD_PORT}' ]
networks: [ 'default', 'db' ]
depends_on: [ 'mariadb' ]
env_file: [ '.env' ]
volumes:
- ./yukon-server/ssl:/etc/ssl/yukon:ro
- ./yukon-server/src:/srv/yukon-server/
- ./templates/config.json.template:/srv/templates/config.json.template
command: [
"dockerize",
"-template", "/srv/templates/config.json.template:/srv/yukon-server/config/config.json",
"-wait", "tcp://${MARIADB_HOST}:${MARIADB_PORT}", "-timeout", "20s",
"npx", "pm2-runtime", "start", "ecosystem.config.js"
]

mariadb:
image: mariadb:latest
restart: unless-stopped
# ports: [ '${MARIADB_PORT}:3306' ]
networks: [ 'db' ]
env_file: [ '.env' ]
volumes:
- ./.data:/var/lib/mysql
- ./yukon-server/src/yukon.sql:/docker-entrypoint-initdb.d/yukon.sql:ro

node:
image: node:alpine
profiles: [ 'dev' ]
working_dir: /srv/yukon
command: [ 'sh' ]
volumes:
- ./yukon/src:/srv/yukon/client
- ./yukon-server/src:/srv/yukon/server

networks:
db:
external: false
45 changes: 45 additions & 0 deletions yukon/templates/config.json.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"crypto": {
"secret": "{{ .Env.GAME_CRYPTO_SECRET }}",
"rounds": 10,
"loginKeyExpiry": 300
},
"database": {
"host": "{{ .Env.MARIADB_HOST }}",
"user": "{{ .Env.MARIADB_USER }}",
"password": "{{ .Env.MARIADB_PASSWORD }}",
"database": "{{ .Env.MARIADB_DATABASE }}",
"dialect": "mysql",
"debug": false
},
"socketio": {
"https": {{ .Env.GAME_SOCKETIO_SSL }},
"ssl": {
"cert": "/etc/ssl/yukon/cert.crt",
"ca": "/etc/ssl/yukon/ca.ca-bundle",
"key": "/etc/ssl/yukon/key.key"
}
},
"cors": {
"origin": "{{ .Env.WEB_HOSTNAME }}:{{ .Env.WEB_PORT }}"
},
"worlds": {
"Login": {
"host": "{{ .Env.GAME_LOGIN_HOST }}",
"port": {{ .Env.GAME_LOGIN_PORT }}
},
"Blizzard": {
"host": "{{ .Env.GAME_BLIZZARD_HOST }}",
"port": {{ .Env.GAME_BLIZZARD_PORT }},
"maxUsers": 300
}
},
"rateLimit": {
"addressEventsPerSecond": 50,
"userEventsPerSecond": 10,
"ipAddressHeader": false
},
"game": {
"iglooIdOffset": 2000
}
}
27 changes: 27 additions & 0 deletions yukon/templates/yukon.conf.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
server {
server_name {{ (parseUrl .Env.WEB_HOSTNAME).Host }};

root /usr/share/nginx/html;
index index.html index.htm index.php;

location /world/login {
proxy_pass {{ .Env.GAME_ADDRESS }}:{{ .Env.GAME_LOGIN_PORT }};
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
}

location /world/blizzard {
proxy_pass {{ .Env.GAME_ADDRESS }}:{{ .Env.GAME_BLIZZARD_PORT }};
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
}

# add more worlds if you want to

# example config for a php container
# location /create {
# proxy_pass {{ .Env.WEB_CREATE_DOMAIN }}:{{ .Env.WEB_CREATE_PORT }};
# }
}
Empty file added yukon/www/.gitkeep
Empty file.
21 changes: 21 additions & 0 deletions yukon/yukon-server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM node:alpine

# args & env
ARG WAIT_FOR_VERSION=4df3f9262d84cab0039c07bf861045fbb3c20ab7
ARG PUID=1000
ARG PGID=1000
ENV DOCKERIZE_VERSION=v0.6.1

# setup non-root user
RUN deluser --remove-home node && addgroup -S node -g ${PGID} && adduser -S -G node -u ${PUID} node

# install dockerize
RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& tar -C /usr/local/bin -xzvf dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& rm dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz

# run as non-root user
USER node

WORKDIR /srv/yukon-server
CMD ["npm", "run", "start"]
Empty file added yukon/yukon-server/ssl/.gitkeep
Empty file.
6 changes: 6 additions & 0 deletions yukon/yukon/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM nginx:alpine

ENV DOCKERIZE_VERSION=v0.6.1
RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& tar -C /usr/local/bin -xzvf dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& rm dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz

0 comments on commit 3ef3c02

Please sign in to comment.