diff --git a/yukon/.env.example b/yukon/.env.example index 42f2054..7af7842 100644 --- a/yukon/.env.example +++ b/yukon/.env.example @@ -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. @@ -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 diff --git a/yukon/.gitignore b/yukon/.gitignore index 3cbf795..161988f 100644 --- a/yukon/.gitignore +++ b/yukon/.gitignore @@ -1,11 +1,11 @@ # Private Data .data/ .env +docker-compose.override.yml # Yukon Sources client/ server/ # Nginx root files (client container) -www/* -!www/.gitkeep \ No newline at end of file +www/ diff --git a/yukon/docker-compose.root.yml b/yukon/docker-compose.root.yml new file mode 100644 index 0000000..71ec971 --- /dev/null +++ b/yukon/docker-compose.root.yml @@ -0,0 +1,11 @@ +version: '3.9' + +services: + client: + image: nginx:mainline-alpine + + server: + user: root + + mariadb: + user: root diff --git a/yukon/docker-compose.yml b/yukon/docker-compose.yml index 21a76c6..4a0aa8f 100644 --- a/yukon/docker-compose.yml +++ b/yukon/docker-compose.yml @@ -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: @@ -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: diff --git a/yukon/setup.sh b/yukon/setup.sh new file mode 100644 index 0000000..0d7ed81 --- /dev/null +++ b/yukon/setup.sh @@ -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!" \ No newline at end of file diff --git a/yukon/templates/yukon.conf.template b/yukon/templates/yukon.conf.template index 0e2f545..845272f 100644 --- a/yukon/templates/yukon.conf.template +++ b/yukon/templates/yukon.conf.template @@ -1,4 +1,5 @@ server { + listen 8080; server_name {{ (parseUrl .Env.WEB_HOSTNAME).Host }}; root /usr/share/nginx/html; @@ -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 }}; diff --git a/yukon/www/.gitkeep b/yukon/www/.gitkeep deleted file mode 100644 index e69de29..0000000