From 0f3305688a44975a5ba7a3a57b982b782c2cc090 Mon Sep 17 00:00:00 2001 From: Renato Foot Date: Mon, 26 Dec 2022 18:30:56 +0000 Subject: [PATCH 1/8] Clean and Update Docker - Remove old docker-compose from the server - Add docker for arm and for x86 - Add GHA to build both docker (can't publish arm image as we build it for x86, GHA doesn't has ARM workers) - Update/Improve docker start script -- Check if DB exists and make a backup before make any change -- Automatic get public IP -- Check if schema.sql was already imported to the DB -- Set which data pack to use(if set to otbr it will download the map)a -- Create Test Accounts -- Fix signals to be sent to the server so it can save things before stopping Signed-off-by: Renato Foot --- .github/workflows/build-docker.yml | 54 ++++-- docker/.gitignore | 1 - docker/Dockerfile.arm | 49 +++++ docker/{server/Dockerfile => Dockerfile.x86} | 9 +- docker/data/download-myaac.sh | 13 -- docker/data/login.py | 183 ------------------- docker/data/start.sh | 178 ++++++++++++++++++ docker/data/web/.gitignore | 4 - docker/docker-compose.yml | 69 ------- docker/login/Dockerfile | 3 - docker/mysql/Dockerfile | 3 - docker/server/start.sh | 80 -------- docker/test-server.sh | 77 -------- 13 files changed, 276 insertions(+), 447 deletions(-) delete mode 100644 docker/.gitignore create mode 100644 docker/Dockerfile.arm rename docker/{server/Dockerfile => Dockerfile.x86} (78%) delete mode 100755 docker/data/download-myaac.sh delete mode 100755 docker/data/login.py create mode 100755 docker/data/start.sh delete mode 100644 docker/data/web/.gitignore delete mode 100644 docker/docker-compose.yml delete mode 100644 docker/login/Dockerfile delete mode 100644 docker/mysql/Dockerfile delete mode 100755 docker/server/start.sh delete mode 100755 docker/test-server.sh diff --git a/.github/workflows/build-docker.yml b/.github/workflows/build-docker.yml index 6e7432022ad..6ec924580ae 100644 --- a/.github/workflows/build-docker.yml +++ b/.github/workflows/build-docker.yml @@ -9,7 +9,7 @@ on: - main jobs: - docker: + docker-x86: runs-on: ubuntu-latest steps: - name: Checkout @@ -27,7 +27,7 @@ jobs: uses: gittools/actions/gitversion/execute@v0.9.15 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2.1.0 + uses: docker/setup-buildx-action@v2 with: install: true @@ -35,12 +35,12 @@ jobs: uses: actions/cache@main with: path: /tmp/.buildx-cache - key: ${{ runner.os }}-buildx-${{ github.sha }} + key: ${{ runner.os }}-x86-${{ github.sha }} restore-keys: | - ${{ runner.os }}-buildx- + ${{ runner.os }}-x86- - name: Login to GitHub Container Registry - uses: docker/login-action@v2.1.0 + uses: docker/login-action@v2 with: registry: ghcr.io username: ${{ github.repository_owner }} @@ -70,10 +70,40 @@ jobs: if: ${{ github.event_name == 'push' }} run: echo ${{ steps.docker_build.outputs.digest }} - # # Temp fix - # # https://github.com/docker/build-push-action/issues/252 - # # https://github.com/moby/buildkit/issues/1896 - # - name: Move cache - # run: | - # rm -rf /tmp/.buildx-cache - # mv /tmp/.buildx-cache-new /tmp/.buildx-cache + docker-arm: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@main + with: + fetch-depth: 0 + + - name: Install GitVersion + uses: gittools/actions/gitversion/setup@v0.9.15 + with: + versionSpec: '5.x' + + - name: Determine Version + id: gitversion + uses: gittools/actions/gitversion/execute@v0.9.15 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + with: + install: true + + - name: Cache Docker layers + uses: actions/cache@main + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-arm-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-arm- + + - name: Build + uses: docker/build-push-action@v3.2.0 + with: + file: docker/server/Dockerfile + tags: ghcr.io/${{ github.repository }}:${{ steps.gitversion.outputs.semVer }} + cache-from: type=gha, scope=${{ github.workflow }} + cache-to: type=gha, scope=${{ github.workflow }} diff --git a/docker/.gitignore b/docker/.gitignore deleted file mode 100644 index 71f67ff2df6..00000000000 --- a/docker/.gitignore +++ /dev/null @@ -1 +0,0 @@ -data/web/* diff --git a/docker/Dockerfile.arm b/docker/Dockerfile.arm new file mode 100644 index 00000000000..5f411154b86 --- /dev/null +++ b/docker/Dockerfile.arm @@ -0,0 +1,49 @@ +# Stage 1: Download all dependencies +FROM ubuntu:22.04 AS dependencies + +RUN apt-get update && apt-get install -y --no-install-recommends cmake git \ + unzip build-essential ca-certificates curl zip unzip tar \ + pkg-config ninja-build autoconf automake libtool libluajit-5.1-dev libluajit-5.1-common \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /opt +RUN git clone https://github.com/microsoft/vcpkg --depth=1 +RUN ./vcpkg/bootstrap-vcpkg.sh + +WORKDIR /opt/vcpkg +COPY vcpkg.json /opt/vcpkg/ +RUN VCPKG_FORCE_SYSTEM_BINARIES=1 /opt/vcpkg/vcpkg --feature-flags=binarycaching,manifests,versions install + +# Stage 2: create build +FROM dependencies AS build + +COPY . /srv/ +WORKDIR /srv + +RUN export VCPKG_ROOT=/opt/vcpkg/ && VCPKG_FORCE_SYSTEM_BINARIES=1 cmake --preset linux-release && cmake --build --preset linux-release + +# Stage 3: load data and execute +FROM ubuntu:22.04 + +VOLUME [ "/data" ] + +COPY --from=build /srv/build/linux-release/bin/canary /bin/canary +COPY LICENSE *.sql key.pem /canary/ +COPY data /canary/data +COPY data-canary /canary/data-canary +COPY data-otservbr-global /canary/data-otservbr-global +COPY config.lua.dist /canary/config.lua + +WORKDIR /canary + +RUN apt-get update && apt-get install -y --no-install-recommends \ + mariadb-client libluajit-5.1-dev libluajit-5.1-common wget curl \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +COPY docker/data/01-test_account.sql 01-test_account.sql +COPY docker/data/02-test_account_players.sql 02-test_account_players.sql +COPY docker/data/start.sh start.sh + +ENTRYPOINT ["/canary/start.sh"] diff --git a/docker/server/Dockerfile b/docker/Dockerfile.x86 similarity index 78% rename from docker/server/Dockerfile rename to docker/Dockerfile.x86 index 68a0725e029..43931cd7f03 100644 --- a/docker/server/Dockerfile +++ b/docker/Dockerfile.x86 @@ -25,19 +25,24 @@ RUN export VCPKG_ROOT=/opt/vcpkg/ && cmake --preset linux-release && cmake --bui # Stage 3: load data and execute FROM ubuntu:22.04 +VOLUME [ "/data" ] COPY --from=build /srv/build/linux-release/bin/canary /bin/canary COPY LICENSE *.sql key.pem /canary/ COPY data /canary/data +COPY data-canary /canary/data-canary +COPY data-otservbr-global /canary/data-otservbr-global COPY config.lua.dist /canary/config.lua WORKDIR /canary RUN apt-get update && apt-get install -y --no-install-recommends \ - mariadb-client \ + mariadb-client curl \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* -COPY docker/server/start.sh start.sh +COPY docker/data/01-test_account.sql 01-test_account.sql +COPY docker/data/02-test_account_players.sql 02-test_account_players.sql +COPY docker/data/start.sh start.sh ENTRYPOINT ["/canary/start.sh"] diff --git a/docker/data/download-myaac.sh b/docker/data/download-myaac.sh deleted file mode 100755 index e02b9588553..00000000000 --- a/docker/data/download-myaac.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash - -wget https://github.com/slawkens/myaac/archive/master.zip -O myaac.zip -unzip -o myaac.zip -d . - -mv myaac-master/* ./web -rm myaac.zip myaac-master -rf - -wget https://github.com/opentibiabr/myaac-tibia12-login/archive/refs/heads/develop.zip -O myaac-otbr-plugin.zip -unzip -o myaac-otbr-plugin.zip -d . - -cp -r myaac-tibia12-login-develop/* ./web -rm -rf myaac-otbr-plugin.zip myaac-tibia12-login-develop \ No newline at end of file diff --git a/docker/data/login.py b/docker/data/login.py deleted file mode 100755 index 5aaccb3f8db..00000000000 --- a/docker/data/login.py +++ /dev/null @@ -1,183 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- - -""" -This is python script to simulate the login functions used by the Tibia client +11! -""" - -from flask import Flask -from flask import jsonify -from flask import request -import mysql.connector as mariadb -from mysql.connector import Error -import time -import os - -app = Flask(__name__) - -def do_login(data): - - try: - connection = mariadb.connect(host=os.getenv('DB_IP', 'mysql'), - database=os.getenv('DB_DATABASE', 'canary'), - user=os.getenv('DB_USER', 'canary'), - password=os.getenv('DB_PASSWORD', 'canary')) - - sql_select_Query = "SELECT id, premdays, lastday FROM accounts WHERE name = '" + data['email'].replace('@','') + "'" - - print("Loading account information!") - cursor = connection.cursor() - cursor.execute(sql_select_Query) - records = cursor.fetchall() - for row in records: - print("Id = ", row[0]) - account_id = row[0] - account_premdays = row[1] - account_lastday = row[2] - - session = { - 'sessionkey': data['email'] + '\n' + data['password'], - 'lastlogintime': 0, - 'ispremium': True if account_premdays > 0 else False, - 'premiumuntil': 0 if account_premdays == 0 else int(time.time()) + (account_premdays * 86400), - 'status': 'active', - 'returnernotification': False, - 'showrewardnews': True, - 'isreturner': True, - 'fpstracking': False, - 'optiontracking': False, - 'tournamentticketpurchasestate': 0, - 'emailcoderequest': False - }; - print(session) - - sql_select_Query = "SELECT name, level, sex, vocation, looktype, lookhead, lookbody, looklegs, lookfeet, lookaddons, lastlogin from players where account_id = '" + str(account_id) + "'" - - cursor = connection.cursor() - cursor.execute(sql_select_Query) - records = cursor.fetchall() - print(records) - - players = [] - vocations = ['None', 'Sorcerer', 'Druid', 'Paladin', 'Knight', 'Master Sorcerer', 'Elder Druid', 'Royal Paladin', 'Elite Knight', 'Sorcerer Dawnport', 'Druid Dawnport', 'Paladin Dawnport', 'Knight Dawnport'] - print("Loading account players information!") - for (name, level, sex, vocation, looktype, lookhead, lookbody, looklegs, lookfeet, lookaddons, lastlogin) in records: - player = { - 'worldid': 0, - 'name': name, - 'level': level, - 'ismale': True if sex == 1 else False, - 'vocation': vocations[vocation], - 'outfitid': looktype, - 'headcolor': lookhead, - 'torsocolor': lookbody, - 'legscolor': looklegs, - 'detailcolor': lookfeet, - 'addonsflags': lookaddons, - 'tutorial': False, # True will make the client crash as it will try to auto connect - 'ishidden': False, - 'istournamentparticipant': False, - 'remainingdailytournamentplaytime': 0 - } - players.append(player) - print(players) - - playdata = { - 'worlds': [ - { - 'id': 0, - 'name': os.getenv('SERVER_NAME', 'Canary'), - 'externaladdressprotected': os.getenv('PROXY_IP', '127.0.0.1'), - 'externalportprotected': int(os.getenv('SERVER_GAME_PORT', 7172)), - 'externaladdressunprotected': os.getenv('PROXY_IP', '127.0.0.1'), - 'externalportunprotected': int(os.getenv('SERVER_GAME_PORT', 7172)), - 'previewstate': 0, - 'location': 'BRA', - 'anticheatprotection': False, - 'pvptype': 'pvp', - 'istournamentworld': False, - 'restrictedstore': False, - 'currenttournamentphase': 2 - } - ], - "characters": players - } - - answer = {'session': session, 'playdata': playdata} - print(answer) - return jsonify(answer) - - except Error as e: - print("Error reading data from MySQL table", e) - - finally: - if (connection.is_connected()): - connection.close() - cursor.close() - print("MySQL connection is closed") - - -def news(data): - - answer = [] - - return jsonify(answer) - - -@app.route('/login.php', methods=['GET', 'POST', 'PUT']) -def action(): - - data = request.get_json() - print(data) - - if(data['type'] == 'cacheinfo'): - return jsonify({ - 'playersonline': 5, - 'twitchstreams': 0, - 'twitchviewer': 0, - 'gamingyoutubestreams': 0, - 'gamingyoutubeviewer': 0 - }) - if(data['type'] == 'news'): - return jsonify({}) - - # The client has a cache of the events on it so it will ask for the events only when it see that last sync was made some time X ago - if(data['type'] == 'eventschedule'): - return jsonify({ - 'lastupdatetimestamp': time.time(), - 'eventlist': [ - { - 'startdate': int(time.time()), - 'enddate': int(time.time()) + 36600 * 20, - 'colorlight': '#64162b', - 'colordark': '#7a1b34', - 'name': 'First Event', - 'description': 'Canary Event 1', - 'isseasonal': False - }, - { - 'startdate': int(time.time()), - 'enddate': int(time.time()) + 36600 * 20, - 'colorlight': '#8B6D05', - 'colordark': '#735D10', - 'name': 'Second Event', - 'description': 'Canary Event 2', - 'isseasonal': False - } - ] - }) - - if(data['type'] == 'boostedcreature'): - return jsonify({ - 'boostedcreature': True, - 'raceid': 39 - }) - - if(data['type'] == 'login'): - return do_login(data) - - - if(data['type'] == 'news'): - return news(data) - -app.run(debug=True, host='0.0.0.0', port=8080) diff --git a/docker/data/start.sh b/docker/data/start.sh new file mode 100755 index 00000000000..e730a641a24 --- /dev/null +++ b/docker/data/start.sh @@ -0,0 +1,178 @@ +#!/bin/bash -e + +OT_DB_HOST="${OT_DB_HOST:-127.0.0.1}" +OT_DB_PORT="${OT_DB_PORT:-3306}" +OT_DB_USER="${OT_DB_USER:-canary}" +OT_DB_PASSWORD="${OT_DB_PASSWORD:-canary}" +OT_DB_DATABASE="${OT_DB_DATABASE:-canary}" +OT_SERVER_IP="${OT_SERVER_IP:-127.0.0.1}" +OT_SERVER_LOGIN_PORT="${OT_SERVER_LOGIN_PORT:-7171}" +OT_SERVER_GAME_PORT="${OT_SERVER_GAME_PORT:-7172}" +OT_SERVER_STATUS_PORT="${OT_SERVER_STATUS_PORT:-7171}" +OT_SERVER_TEST_ACCOUNTS="${OT_SERVER_TEST_ACCOUNTS:-false}" +OT_SERVER_DATA="${OT_SERVER_DATA:-data-canary}" +OT_SERVER_MAP="${OT_SERVER_MAP:-https://github.com/opentibiabr/otservbr-global/releases/download/v1.5.0/otservbr.otbm}" + +echo "" +echo "===== Print Variables =====" +echo "" + +echo "OT_DB_HOST:[$OT_DB_HOST]" +echo "OT_DB_PORT:[$OT_DB_PORT]" +echo "OT_DB_USER:[$OT_DB_USER]" +echo "OT_DB_PASSWORD:[$OT_DB_PASSWORD]" +echo "OT_DB_DATABASE:[$OT_DB_DATABASE]" +echo "OT_SERVER_IP:[$OT_SERVER_IP]" +echo "OT_SERVER_LOGIN_PORT:[$OT_SERVER_LOGIN_PORT]" +echo "OT_SERVER_GAME_PORT:[$OT_SERVER_GAME_PORT]" +echo "OT_SERVER_STATUS_PORT:[$OT_SERVER_STATUS_PORT]" +echo "OT_SERVER_TEST_ACCOUNTS:[$OT_SERVER_TEST_ACCOUNTS]" +echo "OT_SERVER_DATA:[$OT_SERVER_DATA]" +echo "OT_SERVER_MAP:[$OT_SERVER_MAP]" + +echo "" +echo "================================" +echo "" + +echo "" +echo "===== OTBR Global Data Pack =====" +echo "" + +if [ "$OT_SERVER_DATA" = "data-otservbr-global" ] && [ ! -f data-otservbr-global/world/otservbr.otbm ]; then + echo "YES" + + echo "Downloading OTBR Map..." + wget --no-check-certificate $OT_SERVER_MAP -O data-otservbr-global/world/otservbr.otbm + + echo "Done" + +else + echo "Not Using OTBR Data pack" +fi + +echo "" +echo "================================" +echo "" + +echo "" +echo "===== Wait For The DB To Be Up =====" +echo "" + +until mysql -u "$OT_DB_USER" -p"$OT_DB_PASSWORD" -h "$OT_DB_HOST" --port="$OT_DB_PORT" -e "SHOW DATABASES;"; do + echo "DB offline, trying again" + sleep 5s +done + +echo "" +echo "================================" +echo "" + +echo "" +echo "===== Check If DB Already Exists =====" +echo "" +if mysql -u "$OT_DB_USER" -p"$OT_DB_PASSWORD" -h "$OT_DB_HOST" --port="$OT_DB_PORT" -e "use $OT_DB_DATABASE"; then + echo "Creating Database Backup" + echo "Saving database to all_databases.sql" + mysqldump -u "$OT_DB_USER" -p"$OT_DB_PASSWORD" -h "$OT_DB_HOST" --port="$OT_DB_PORT" --all-databases >/data/all_databases.sql +else + echo "Creating Database" + mysql -u "$OT_DB_USER" -p"$OT_DB_PASSWORD" -h "$OT_DB_HOST" --port="$OT_DB_PORT" -e "CREATE DATABASE $OT_DB_DATABASE;" + mysql -u "$OT_DB_USER" -p"$OT_DB_PASSWORD" -h "$OT_DB_HOST" --port="$OT_DB_PORT" -e "SHOW DATABASES;" +fi +echo "" +echo "================================" +echo "" + +echo "" +echo "===== Check If We Need To Import Schema.sql =====" +echo "" + +if [[ $(mysql -u "$OT_DB_USER" -p"$OT_DB_PASSWORD" -h "$OT_DB_HOST" -e 'SHOW TABLES LIKE "server_config"' -D "$OT_DB_DATABASE") ]]; then + echo "Table server_config exists so we don't need to import" +else + echo "Create Database and Import Schema" + mysql -u "$OT_DB_USER" -p"$OT_DB_PASSWORD" -h "$OT_DB_HOST" --port="$OT_DB_PORT" -D "$OT_DB_DATABASE" /data/"$(date +'%Y'_'%m'_'%d')"_databases_bkp.sql + sleep 5 +done diff --git a/docker/data/web/.gitignore b/docker/data/web/.gitignore deleted file mode 100644 index 5e7d2734cfc..00000000000 --- a/docker/data/web/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -# Ignore everything in this directory -* -# Except this file -!.gitignore diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml deleted file mode 100644 index a096a424988..00000000000 --- a/docker/docker-compose.yml +++ /dev/null @@ -1,69 +0,0 @@ -version: "3.3" - -services: - server: - build: - context: ../ - dockerfile: docker/server/Dockerfile - ports: - - 7171:7171 - - 7172:7172 - volumes: - - ../data:/otbr/data - depends_on: - - mysql - - website - - login - links: - - mysql - environment: - - SERVER_DB_HOST=mysql - - mysql: - build: - context: ../ - dockerfile: docker/mysql/Dockerfile - restart: unless-stopped - environment: - - MYSQL_DATABASE=canary - - MYSQL_USER=canary - - MYSQL_PASSWORD=canary - - MYSQL_RANDOM_ROOT_PASSWORD=yes - ports: - - 3306:3306 - - website: - image: webdevops/php-nginx:alpine-php7 - restart: unless-stopped - environment: - - WEB_DOCUMENT_ROOT=/tmp/web/ - - WEB_DOCUMENT_INDEX=index.php - ports: - - 8080:80 - volumes: - - ./docker/data/web:/tmp/web - - ./:/tmp/otserver/ - depends_on: - - mysql - - login: - image: opentibiabr/login-server:latest - restart: unless-stopped - ports: - - 80:8080 - depends_on: - - mysql - environment: - - DB_DATABASE=canary - - DB_HOSTNAME=mysql - - DB_PORT=3306 - - DB_PASSWORD=canary - - DB_USERNAME=canary - - ENV_LOG_LEVEL=verbose - - ENV_TYPE=dev - - LOGIN_PORT=8080 - - SERVER_NAME=Canary - - SERVER_LOCATION=Bra - - SERVER_IP=127.0.0.1 - - SERVER_PORT=7172 -# - VOCATIONS -- map your custom vocations here, if needed, comma separated diff --git a/docker/login/Dockerfile b/docker/login/Dockerfile deleted file mode 100644 index 0f07cf93b9c..00000000000 --- a/docker/login/Dockerfile +++ /dev/null @@ -1,3 +0,0 @@ -FROM lucasggrossi/otbr_login:go-login1.0 - -ENTRYPOINT ["/login-server/loginserver-linux-x64"] diff --git a/docker/mysql/Dockerfile b/docker/mysql/Dockerfile deleted file mode 100644 index ba32145a1a1..00000000000 --- a/docker/mysql/Dockerfile +++ /dev/null @@ -1,3 +0,0 @@ -FROM mariadb:10 - -COPY schema.sql /docker-entrypoint-initdb.d/ diff --git a/docker/server/start.sh b/docker/server/start.sh deleted file mode 100755 index ce32e0c149b..00000000000 --- a/docker/server/start.sh +++ /dev/null @@ -1,80 +0,0 @@ -#!/bin/bash - -DB_HOST="${SERVER_DB_HOST:-127.0.0.1}" -DB_USER="${SERVER_DB_USER:-canary}" -DB_PASSWORD="${SERVER_DB_PASSWORD:-canary}" -DB_DATABASE="${SERVER_DB_DATABASE:-canary}" -OT_SERVER_IP="${SERVER_IP:-127.0.0.1}" -OT_SERVER_LOGIN_PORT="${SERVER_LOGIN_PORT:-7171}" -OT_SERVER_GAME_PORT="${SERVER_GAME_PORT:-7172}" -OT_SERVER_STATUS_PORT="${SERVER_STATUS_PORT:-7171}" - -echo "" -echo "===== Print Variables =====" -echo "" - -echo "DB_HOST:[$DB_HOST]" -echo "DB_USER:[$DB_USER]" -echo "DB_PASSWORD:[$DB_PASSWORD]" -echo "DB_DATABASE:[$DB_DATABASE]" -echo "OT_SERVER_IP:[$OT_SERVER_IP]" -echo "OT_SERVER_LOGIN_PORT:[$OT_SERVER_LOGIN_PORT]" -echo "OT_SERVER_GAME_PORT:[$OT_SERVER_GAME_PORT]" -echo "OT_SERVER_STATUS_PORT:[$OT_SERVER_STATUS_PORT]" - -echo "" -echo "================================" -echo "" - -echo "" -echo "===== Wait for the DB to be Up =====" -echo "" - -until mysql -u "$DB_USER" -p"$DB_PASSWORD" -h "$DB_HOST" --port="$DB_PORT" -e "SHOW DATABASES;" -do - echo "DB offline, trying again" - sleep 5s -done - -echo "" -echo "================================" -echo "" - -echo "" -echo "===== Create Database and Import schema =====" -echo "" - -mysql -u $DB_USER -p$DB_PASSWORD -h $DB_HOST -e "CREATE DATABASE $DB_DATABASE;" -mysql -u $DB_USER -p$DB_PASSWORD -h $DB_HOST -e "SHOW DATABASES;" -mysql -u $DB_USER -p$DB_PASSWORD -h $DB_HOST -D $DB_DATABASE < schema.sql - -echo "" -echo "================================" -echo "" - -sed -i '/mysqlHost = .*$/c\mysqlHost = "'$DB_HOST'"' config.lua -sed -i '/mysqlUser = .*$/c\mysqlUser = "'$DB_USER'"' config.lua -sed -i '/mysqlPass = .*$/c\mysqlPass = "'$DB_PASSWORD'"' config.lua -sed -i '/mysqlDatabase = .*$/c\mysqlDatabase = "'$DB_DATABASE'"' config.lua -sed -i '/ip = .*$/c\ip = "'$OT_SERVER_IP'"' config.lua -sed -i '/loginProtocolPort = .*$/c\loginProtocolPort = '$OT_SERVER_LOGIN_PORT'' config.lua -sed -i '/gameProtocolPort = .*$/c\gameProtocolPort = '$OT_SERVER_GAME_PORT'' config.lua -sed -i '/statusProtocolPort = .*$/c\statusProtocolPort = '$OT_SERVER_STATUS_PORT'' config.lua - -echo "" -echo "===== Server Configuration =====" -echo "" - -cat config.lua - -echo "" -echo "================================" -echo "" - -echo "" -echo "===== Start Server =====" -echo "" - -ulimit -c unlimited -canary - diff --git a/docker/test-server.sh b/docker/test-server.sh deleted file mode 100755 index 0f7d8aee84b..00000000000 --- a/docker/test-server.sh +++ /dev/null @@ -1,77 +0,0 @@ -#!/bin/bash - -# set -o xtrace -set -o errexit # abort on nonzero exitstatus -set -o nounset # abort on unbound variable - -export DEBIAN_FRONTEND=noninteractive - -ln -fs /usr/share/zoneinfo/America/Sao_Paulo /etc/localtime - -apt-get update -apt-get install -y \ - apache2 \ - build-essential \ - ca-certificates \ - ccache \ - cmake \ - curl \ - git \ - libapache2-mod-php \ - php \ - php-mysql \ - pkg-config \ - python3 \ - python3-pip \ - tar \ - unzip \ - zip - -dpkg-reconfigure --frontend noninteractive tzdata - -apt-get install -y mariadb-server mariadb-client -/etc/init.d/mysql start - -apt-get install -y phpmyadmin -ln -s /usr/share/phpmyadmin /var/www/html -/etc/init.d/apache2 start - -# Create database and import schema -mysql -u root -e "CREATE DATABASE $DB_DATABASE;" -mysql -u root -e "SHOW DATABASES;" -mysql -u root -D $DB_DATABASE < schema.sql -mysql -u root -D $DB_DATABASE < docker/data/01-test_account.sql -mysql -u root -D $DB_DATABASE < docker/data/02-test_account_players.sql - -# Create user -mysql -u root -e "CREATE USER '$DB_USER'@localhost IDENTIFIED BY '$DB_PASSWORD';" -mysql -u root -e "SELECT User FROM mysql.user;" -mysql -u root -e "GRANT ALL PRIVILEGES ON *.* TO '$DB_USER'@localhost IDENTIFIED BY '$DB_PASSWORD';" - -# Make our changes take effect -mysql -u root -e "FLUSH PRIVILEGES;" - -pip3 install --no-cache-dir Flask mysql-connector-python -python3 docker/data/login.py & - -git clone https://github.com/microsoft/vcpkg -cd vcpkg -./bootstrap-vcpkg.sh -cd .. - -mkdir -p build -cd build -cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=../vcpkg/scripts/buildsystems/vcpkg.cmake .. -make -j`nproc` -mv bin/canary ../ -cd .. - -cp config.lua.dist config.lua -sed -i '/ip = .*$/c\ip = "'"$PROXY_IP"'"' config.lua -sed -i '/motd = .*$/c\motd = "Test Server"' config.lua -sed -i '/mysqlHost = .*$/c\mysqlHost = "'"$DB_IP"'"' config.lua -sed -i '/mysqlUser = .*$/c\mysqlUser = "'"$DB_USER"'"' config.lua -sed -i '/mysqlPass = .*$/c\mysqlPass = "'"$DB_PASSWORD"'"' config.lua -sed -i '/mysqlDatabase = .*$/c\mysqlDatabase = "'"$DB_DATABASE"'"' config.lua -sed -i '/onePlayerOnlinePerAccount = .*$/c\onePlayerOnlinePerAccount = false' config.lua -sed -i '/serverSaveShutdown = .*$/c\serverSaveShutdown = false' config.lua From 896f8f97c289e32e78cf0fd80d1f2d0b95cb6f61 Mon Sep 17 00:00:00 2001 From: Renato Foot Date: Tue, 27 Dec 2022 17:52:19 +0000 Subject: [PATCH 2/8] Fix dockerfiles path Signed-off-by: Renato Foot --- .github/workflows/build-docker.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-docker.yml b/.github/workflows/build-docker.yml index 6ec924580ae..53d2387b06f 100644 --- a/.github/workflows/build-docker.yml +++ b/.github/workflows/build-docker.yml @@ -50,7 +50,7 @@ jobs: if: ${{ github.event_name == 'pull_request' }} uses: docker/build-push-action@v3.2.0 with: - file: docker/server/Dockerfile + file: docker/Dockerfile.x86 tags: ghcr.io/${{ github.repository }}:${{ steps.gitversion.outputs.semVer }} cache-from: type=gha, scope=${{ github.workflow }} cache-to: type=gha, scope=${{ github.workflow }} @@ -60,7 +60,7 @@ jobs: if: ${{ github.event_name == 'push' }} uses: docker/build-push-action@v3.2.0 with: - file: docker/server/Dockerfile + file: docker/Dockerfile.x86 push: true tags: ghcr.io/${{ github.repository }}:${{ steps.gitversion.outputs.semVer }} cache-from: type=gha, scope=${{ github.workflow }} @@ -103,7 +103,7 @@ jobs: - name: Build uses: docker/build-push-action@v3.2.0 with: - file: docker/server/Dockerfile + file: docker/Dockerfile.arm tags: ghcr.io/${{ github.repository }}:${{ steps.gitversion.outputs.semVer }} cache-from: type=gha, scope=${{ github.workflow }} cache-to: type=gha, scope=${{ github.workflow }} From 044208a25e6d2d8bc6953a7b83c3430da450e6cb Mon Sep 17 00:00:00 2001 From: Renato Foot Date: Tue, 27 Dec 2022 17:55:41 +0000 Subject: [PATCH 3/8] Improve Dockerfiles - Adjust two sequential RUN that can be merged into one Signed-off-by: Renato Foot --- docker/Dockerfile.arm | 4 ++-- docker/Dockerfile.x86 | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docker/Dockerfile.arm b/docker/Dockerfile.arm index 5f411154b86..f96c0ca0cff 100644 --- a/docker/Dockerfile.arm +++ b/docker/Dockerfile.arm @@ -8,8 +8,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends cmake git \ && rm -rf /var/lib/apt/lists/* WORKDIR /opt -RUN git clone https://github.com/microsoft/vcpkg --depth=1 -RUN ./vcpkg/bootstrap-vcpkg.sh +RUN git clone https://github.com/microsoft/vcpkg --depth=1 \ + && ./vcpkg/bootstrap-vcpkg.sh WORKDIR /opt/vcpkg COPY vcpkg.json /opt/vcpkg/ diff --git a/docker/Dockerfile.x86 b/docker/Dockerfile.x86 index 43931cd7f03..bc7835a313f 100644 --- a/docker/Dockerfile.x86 +++ b/docker/Dockerfile.x86 @@ -8,8 +8,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends cmake git \ && rm -rf /var/lib/apt/lists/* WORKDIR /opt -RUN git clone https://github.com/microsoft/vcpkg --depth=1 -RUN ./vcpkg/bootstrap-vcpkg.sh +RUN git clone https://github.com/microsoft/vcpkg --depth=1 \ + && ./vcpkg/bootstrap-vcpkg.sh WORKDIR /opt/vcpkg COPY vcpkg.json /opt/vcpkg/ From d099d3675005bd930974b4f44a6cfb809165c393 Mon Sep 17 00:00:00 2001 From: Renato Foot Date: Tue, 27 Dec 2022 20:00:42 +0000 Subject: [PATCH 4/8] Fix lint warnings Signed-off-by: Renato Foot --- docker/data/start.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/data/start.sh b/docker/data/start.sh index e730a641a24..fb1afc14b09 100755 --- a/docker/data/start.sh +++ b/docker/data/start.sh @@ -42,7 +42,7 @@ if [ "$OT_SERVER_DATA" = "data-otservbr-global" ] && [ ! -f data-otservbr-global echo "YES" echo "Downloading OTBR Map..." - wget --no-check-certificate $OT_SERVER_MAP -O data-otservbr-global/world/otservbr.otbm + wget --no-check-certificate "$OT_SERVER_MAP" -O data-otservbr-global/world/otservbr.otbm echo "Done" @@ -158,7 +158,7 @@ if [ -d "/data/server/" ]; then cp config.lua /data/server/ cp -r data/ /data/server/ - cp -r $OT_SERVER_DATA/ /data/server/ + cp -r "$OT_SERVER_DATA"/ /data/server/ echo "" echo "================================" From a6575dc265825d3e0ad973afdc657805e7f8e2a0 Mon Sep 17 00:00:00 2001 From: Renato Foot Date: Thu, 29 Dec 2022 21:06:16 +0000 Subject: [PATCH 5/8] Update Sonar GHA Signed-off-by: Renato Foot --- .github/workflows/analysis-sonarcloud.yml | 52 +++++------------------ 1 file changed, 10 insertions(+), 42 deletions(-) diff --git a/.github/workflows/analysis-sonarcloud.yml b/.github/workflows/analysis-sonarcloud.yml index 00391570dda..f39e201279c 100644 --- a/.github/workflows/analysis-sonarcloud.yml +++ b/.github/workflows/analysis-sonarcloud.yml @@ -13,24 +13,21 @@ env: CMAKE_BUILD_PARALLEL_LEVEL: 2 MAKEFLAGS: '-j 2' NUMBER_OF_PROCESSORS: 2 - SONAR_SCANNER_VERSION: 4.7.0.2747 - SONAR_SERVER_URL: "https://sonarcloud.io" - BUILD_WRAPPER_OUT_DIR: bw-output jobs: sonarcloud: name: SonarCloud - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@main + - uses: actions/checkout@v3 if: ${{ github.event_name == 'pull_request' || github.event_name == 'pull_request_target' }} with: fetch-depth: 0 ref: ${{github.event.pull_request.head.ref}} repository: ${{github.event.pull_request.head.repo.full_name}} - - uses: actions/checkout@main + - uses: actions/checkout@v3 if: ${{ github.event_name == 'push' }} with: fetch-depth: 0 @@ -79,34 +76,13 @@ jobs: vcpkgGitURL: "https://github.com/opentibiabr/vcpkg.git" vcpkgGitCommitId: 8974d642d47efd578e0da3223b4101c5d59aebcf - - name: Set up JDK 11 - uses: actions/setup-java@v3 - with: - distribution: 'temurin' - java-version: 11 - - - name: Download and set up sonar-scanner - env: - SONAR_SCANNER_DOWNLOAD_URL: https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${{ env.SONAR_SCANNER_VERSION }}-linux.zip - run: | - mkdir -p $HOME/.sonar - curl -sSLo $HOME/.sonar/sonar-scanner.zip ${{ env.SONAR_SCANNER_DOWNLOAD_URL }} - unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/ - echo "$HOME/.sonar/sonar-scanner-${{ env.SONAR_SCANNER_VERSION }}-linux/bin" >> $GITHUB_PATH + - name: Install sonar-scanner + uses: SonarSource/sonarcloud-github-c-cpp@v1 - - name: Download and set up build-wrapper - env: - BUILD_WRAPPER_DOWNLOAD_URL: ${{ env.SONAR_SERVER_URL }}/static/cpp/build-wrapper-linux-x86.zip - run: | - curl -sSLo $HOME/.sonar/build-wrapper-linux-x86.zip ${{ env.BUILD_WRAPPER_DOWNLOAD_URL }} - unzip -o $HOME/.sonar/build-wrapper-linux-x86.zip -d $HOME/.sonar/ - echo "$HOME/.sonar/build-wrapper-linux-x86" >> $GITHUB_PATH - - - name: Run build-wrapper + - name: Generate compilation database run: | mkdir -p build - cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake -DOPTIONS_ENABLE_CCACHE=ON -S . -B build - build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build build + cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake -DOPTIONS_ENABLE_CCACHE=ON -S . -B build - name: Run PR sonar-scanner if: ${{ github.event_name == 'pull_request' || github.event_name == 'pull_request_target' }} @@ -115,11 +91,10 @@ jobs: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} run: | sonar-scanner \ - --define sonar.host.url="${{ env.SONAR_SERVER_URL }}" \ - --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}" \ --define sonar.cfamily.threads="${{ env.NUMBER_OF_PROCESSORS }}" \ --define sonar.cfamily.cache.enabled=true \ --define sonar.cfamily.cache.path=$HOME/.cfamily \ + --define sonar.cfamily.compile-commands=build/compile_commands.json \ --define sonar.pullrequest.key=${{ github.event.pull_request.number }} \ --define sonar.pullrequest.branch=${{ github.head_ref }} \ --define sonar.pullrequest.base=${{ github.base_ref }} @@ -131,14 +106,7 @@ jobs: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} run: | sonar-scanner \ - --define sonar.host.url="${{ env.SONAR_SERVER_URL }}" \ - --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}" \ --define sonar.cfamily.threads="${{ env.NUMBER_OF_PROCESSORS }}" \ --define sonar.cfamily.cache.enabled=true \ - --define sonar.cfamily.cache.path=$HOME/.cfamily - - - name: SonarQube Quality Gate check - uses: sonarsource/sonarqube-quality-gate-action@master - timeout-minutes: 5 - env: - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + --define sonar.cfamily.cache.path=$HOME/.cfamily \ + --define sonar.cfamily.compile-commands=build/compile_commands.json From c79e16b471a79e0fb6e34405545a83f3aef46d74 Mon Sep 17 00:00:00 2001 From: Renato Foot Date: Fri, 30 Dec 2022 21:07:35 +0000 Subject: [PATCH 6/8] Adjust jobs names Signed-off-by: Renato Foot --- .github/workflows/build-docker.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-docker.yml b/.github/workflows/build-docker.yml index 53d2387b06f..559deab9321 100644 --- a/.github/workflows/build-docker.yml +++ b/.github/workflows/build-docker.yml @@ -9,7 +9,7 @@ on: - main jobs: - docker-x86: + build_docker_x86: runs-on: ubuntu-latest steps: - name: Checkout @@ -70,7 +70,7 @@ jobs: if: ${{ github.event_name == 'push' }} run: echo ${{ steps.docker_build.outputs.digest }} - docker-arm: + build_docker_arm: runs-on: ubuntu-latest steps: - name: Checkout From d706487d9ea5fd7a24df55fa7ed1d180335784b5 Mon Sep 17 00:00:00 2001 From: Renato Foot Date: Fri, 30 Dec 2022 21:39:39 +0000 Subject: [PATCH 7/8] Fix message Signed-off-by: Renato Foot --- docker/data/start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/data/start.sh b/docker/data/start.sh index fb1afc14b09..b5b2efe6034 100755 --- a/docker/data/start.sh +++ b/docker/data/start.sh @@ -90,7 +90,7 @@ echo "" if [[ $(mysql -u "$OT_DB_USER" -p"$OT_DB_PASSWORD" -h "$OT_DB_HOST" -e 'SHOW TABLES LIKE "server_config"' -D "$OT_DB_DATABASE") ]]; then echo "Table server_config exists so we don't need to import" else - echo "Create Database and Import Schema" + echo "Import Canary-Server Schema" mysql -u "$OT_DB_USER" -p"$OT_DB_PASSWORD" -h "$OT_DB_HOST" --port="$OT_DB_PORT" -D "$OT_DB_DATABASE" Date: Wed, 4 Jan 2023 21:24:59 +0000 Subject: [PATCH 8/8] Script will not continue after exec Signed-off-by: Renato Foot --- docker/data/start.sh | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/docker/data/start.sh b/docker/data/start.sh index b5b2efe6034..db688b488d0 100755 --- a/docker/data/start.sh +++ b/docker/data/start.sh @@ -170,9 +170,4 @@ echo "===== Start Server =====" echo "" ulimit -c unlimited -while true; do - exec canary - sleep 5 - mysqldump -u "$OT_DB_USER" -p"$OT_DB_PASSWORD" -h "$OT_DB_HOST" --port="$OT_DB_PORT" --all-databases >/data/"$(date +'%Y'_'%m'_'%d')"_databases_bkp.sql - sleep 5 -done +exec canary