Skip to content

Commit

Permalink
refactor(yukon): new script version
Browse files Browse the repository at this point in the history
chore(yukon): update .gitignore
feat(yukon): add root compose override
refactor(yukon): run setup as node user
refactor(yukon): add assets branch
refactor(yukon): add phpmyadmin service
refactor(yukon): wip new scripts
  • Loading branch information
n0bodysec committed Jul 10, 2023
1 parent 62d0e87 commit e90c088
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 50 deletions.
9 changes: 8 additions & 1 deletion yukon/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ GAME_PREFERRED_SPAWN=0
# Current known branches: master, develop
# It is only used by the builder service.
#
# ASSETS_BRANCH
# -------------
# The git branch of the assets to be cloned.
# Current known branches: master
# It is only used by the builder service.
#
# DOCKERIZE_VERSION
# -----------------
# The dockerize version to download.
Expand All @@ -172,4 +178,5 @@ GAME_PREFERRED_SPAWN=0
ASSETS_REPOSITORY=https://gitea.com/USERNAME/REPOSITORY.git
CLIENT_BRANCH=main
SERVER_BRANCH=master
DOCKERIZE_VERSION=v0.6.1
ASSETS_BRANCH=master
DOCKERIZE_VERSION=v0.7.0
4 changes: 2 additions & 2 deletions yukon/.gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Private Data
.data/
.env
docker-compose.override.yml

# Yukon Sources
client/
server/

# Nginx root files (client container)
www/*
!www/.gitkeep
www/
11 changes: 11 additions & 0 deletions yukon/docker-compose.root.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: '3.9'

services:
client:
image: nginx:mainline-alpine

server:
user: root

mariadb:
user: root
74 changes: 29 additions & 45 deletions yukon/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,57 @@ version: '3.9'

services:
client:
image: nginx:alpine
image: nginxinc/nginx-unprivileged:mainline-alpine
restart: unless-stopped
ports: [ '${WEB_PORT}:80' ]
networks: [ 'default' ]
expose: [ '8080' ]
ports: [ '${WEB_PORT}:8080' ]
depends_on: [ 'server' ]
command:
- /bin/sh
- -c
- |
tar -C /usr/local/bin -xzvf /root/dockerize.tar.gz
dockerize -template /etc/nginx/conf.d/yukon.conf.template:/etc/nginx/conf.d/yukon.conf nginx "-g daemon off;"
environment:
WEB_HOSTNAME: ${WEB_HOSTNAME}
GAME_ADDRESS: ${GAME_ADDRESS}
GAME_LOGIN_PORT: ${GAME_LOGIN_PORT}
GAME_BLIZZARD_PORT: ${GAME_BLIZZARD_PORT}
volumes:
- ./.data/dockerize.tar.gz:/root/dockerize.tar.gz:ro
- ./.data/dockerize:/usr/local/bin/dockerize:ro
- /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:ro
command: dockerize -template /etc/nginx/conf.d/yukon.conf.template:/etc/nginx/conf.d/yukon.conf nginx "-g daemon off;"

server:
image: node:alpine
restart: unless-stopped
# ports: [ '${GAME_LOGIN_PORT}:${GAME_LOGIN_PORT}', '${GAME_BLIZZARD_PORT}:${GAME_BLIZZARD_PORT}' ]
user: node
expose: [ '${GAME_LOGIN_PORT}', '${GAME_BLIZZARD_PORT}' ]
networks: [ 'default', 'db' ]
depends_on: [ 'mariadb' ]
env_file: [ '.env' ]
working_dir: /srv/server
command:
- /bin/sh
- -c
- |
tar -C /usr/local/bin -xzvf /root/dockerize.tar.gz
dockerize -template /srv/templates/config.json.template:/srv/server/config/config.json \
-wait tcp://${MARIADB_HOST}:${MARIADB_PORT} -timeout 20s npx pm2-runtime start ecosystem.config.js
volumes:
- ./.data/dockerize.tar.gz:/root/dockerize.tar.gz:ro
- ./.data/dockerize:/usr/local/bin/dockerize:ro
- ./.data/ssl:/etc/ssl/yukon:ro
- ./server:/srv/server/
- ./server:/srv/server
- ./templates/config.json.template:/srv/templates/config.json.template:ro
command: dockerize -template /srv/templates/config.json.template:/srv/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' ]
user: mysql
expose: [ '3306' ]
networks: [ 'db' ]
env_file: [ '.env' ]
environment:
MARIADB_USER: ${MARIADB_USER}
MARIADB_PASSWORD: ${MARIADB_PASSWORD}
MARIADB_ROOT_PASSWORD: ${MARIADB_ROOT_PASSWORD}
MARIADB_DATABASE: ${MARIADB_DATABASE}
volumes:
- ./.data/mariadb:/var/lib/mysql
- ./server/yukon.sql:/docker-entrypoint-initdb.d/yukon.sql:ro

builder:
image: node:alpine
setup:
profiles: [ 'dev' ]
image: node:alpine
working_dir: /srv/yukon
env_file: [ '.env' ]
volumes:
Expand All @@ -66,28 +61,17 @@ services:
- /bin/sh
- -c
- |
apk add --no-cache git
mkdir -p www/assets/scripts/lib/ruffle .data/ssl
wget -qO .data/dockerize.tar.gz https://github.com/jwilder/dockerize/releases/download/$$DOCKERIZE_VERSION/dockerize-alpine-linux-amd64-$$DOCKERIZE_VERSION.tar.gz
git clone -b $$CLIENT_BRANCH https://github.com/wizguin/yukon.git client
git clone -b $$SERVER_BRANCH https://github.com/wizguin/yukon-server.git server
cd client && npm ci && npm run build
cd ../server && npm ci && npm run build
cd .. && cp -r client/assets www && cp -r client/dist/* www
wget -qO /tmp/res.json https://api.github.com/repos/ruffle-rs/ruffle/releases
node -p "require('/tmp/res.json').flatMap(x => x.assets).find(y => y.browser_download_url.includes('selfhosted')).browser_download_url;" | xargs -n1 wget -qO /tmp/ruffle.zip
unzip -d www/assets/scripts/lib/ruffle /tmp/ruffle.zip
git clone $$ASSETS_REPOSITORY /tmp/assets
mv /tmp/assets/* /tmp/assets/.[!.]* www/assets
apk add --no-cache git runuser
runuser -u node -- sh ./setup.sh
node:
image: node:alpine
profiles: [ 'dev' ]
working_dir: /srv/yukon
command: [ 'sh' ]
volumes:
- ./client:/srv/yukon/client
- ./server:/srv/yukon/server
phpmyadmin:
profiles: [ 'tools' ]
image: phpmyadmin
restart: unless-stopped
expose: [ '80' ]
networks: [ 'db' ]
environment:
- PMA_HOST=mariadb

networks:
db:
54 changes: 54 additions & 0 deletions yukon/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/sh

# Check if required commands are available
check_command()
{
local command=$1

if ! command -v "$command" &> /dev/null; then
echo "$command is not installed. Please install $command before continuing."
exit 1
fi
}

check_command "git"
check_command "node"
check_command "wget"
check_command "unzip"

########################################################################################################################################

# Setup
CURRENT_ARCH=$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/;s/i686/386/;s/armv[0-9]l/armel/;s/armv[0-9]hf/armhf/;s/ppc64le/ppc64le/')

# Clone required repositories
echo "TASK: Cloning required repositories..."
git clone -b $CLIENT_BRANCH --depth 1 https://github.com/wizguin/yukon.git client
git clone -b $SERVER_BRANCH --depth 1 https://github.com/wizguin/yukon-server.git server
git clone -b $ASSETS_BRANCH --depth 1 $ASSETS_REPOSITORY www/assets

# Download required files
echo "TASK: Downloading required files..."
wget -O /tmp/dockerize.tar.gz https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-alpine-linux-$CURRENT_ARCH-$DOCKERIZE_VERSION.tar.gz
wget -O /tmp/res.json https://api.github.com/repos/ruffle-rs/ruffle/releases
node -p "require('/tmp/res.json').flatMap(x => x.assets).find(y => y.browser_download_url.includes('selfhosted')).browser_download_url;" | xargs -n1 wget -O /tmp/ruffle.zip

# Build client
echo "TASK: Building client..."
cd client
npm ci
npm run build

# Build server
echo "TASK: Building server..."
cd ../server
npm ci
npm run build

# Move files
echo "TASK: Moving required files..."
cd .. && cp -r client/assets www && cp -r client/dist/* www
unzip -d www/assets/scripts/lib/ruffle /tmp/ruffle.zip
mkdir -p .data/ssl && tar -xzvf /tmp/dockerize.tar.gz -C .data/

echo "Done!"
3 changes: 1 addition & 2 deletions yukon/templates/yukon.conf.template
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
server {
listen 8080;
server_name {{ (parseUrl .Env.WEB_HOSTNAME).Host }};

root /usr/share/nginx/html;
Expand All @@ -23,8 +24,6 @@ server {
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 }};
Expand Down
Empty file removed yukon/www/.gitkeep
Empty file.

0 comments on commit e90c088

Please sign in to comment.