Skip to content

Commit

Permalink
Merge pull request #350 from vincent4vx/chore-docker
Browse files Browse the repository at this point in the history
chore: setup docker
  • Loading branch information
vincent4vx authored Jun 15, 2024
2 parents c00947d + 1ae29bc commit f0cc510
Show file tree
Hide file tree
Showing 11 changed files with 290 additions and 66 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
mysql password: 'araknemu'
mysql root password: 'root'

- name: Reset mysql password
- name: Create MySQL user
run: |
while :
do
Expand All @@ -29,9 +29,8 @@ jobs:
done
cat <<EOF | mysql -h 127.0.0.1 -u root --password=root
CREATE USER 'araknemu'@'%';
CREATE USER 'araknemu'@'%' IDENTIFIED BY 'araknemu';
GRANT ALL PRIVILEGES ON *.* TO 'araknemu'@'%';
UPDATE mysql.user SET authentication_string = null WHERE user = 'araknemu';
FLUSH PRIVILEGES;
EOF
Expand Down Expand Up @@ -71,7 +70,7 @@ jobs:
mysql password: 'araknemu'
mysql root password: 'root'

- name: Reset mysql password
- name: Create MySQL user
run: |
while :
do
Expand All @@ -80,9 +79,8 @@ jobs:
done
cat <<EOF | mysql -h 127.0.0.1 -u root --password=root
CREATE USER 'araknemu'@'%';
CREATE USER 'araknemu'@'%' IDENTIFIED BY 'araknemu';
GRANT ALL PRIVILEGES ON *.* TO 'araknemu'@'%';
UPDATE mysql.user SET authentication_string = null WHERE user = 'araknemu';
FLUSH PRIVILEGES;
EOF
Expand Down
36 changes: 0 additions & 36 deletions .scrutinizer.yml

This file was deleted.

44 changes: 44 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
ARG MAVEN_VERSION=3.8
ARG JAVA_VERSION=17

# First stage: compile the application
FROM maven:${MAVEN_VERSION}-openjdk-${JAVA_VERSION} AS development

WORKDIR srv

COPY src src
COPY pom.xml .
COPY config.ini.dist config.ini.dist
COPY scripts scripts

# Ignore tests and checkerframework
RUN mvn package -DskipTests -P!checkerframework

# Copy the compiled jar to /srv/araknemu.jar
RUN cp target/araknemu-*-with-dependencies.jar araknemu.jar

# Second stage: contains only runtime dependencies
FROM openjdk:${JAVA_VERSION}-jdk-slim AS production

ENV AUTH_PORT=4444
ENV GAME_PORT=5555

WORKDIR srv

COPY --from=development /srv/araknemu.jar araknemu.jar
COPY config.ini.dist config.ini.dist
COPY scripts scripts
COPY start.sh start.sh

# Install netcat, used in start.sh to wait for mariadb to be ready
RUN apt-get update && apt-get install -y netcat-openbsd

RUN mkdir -p logs
RUN chmod +x start.sh

VOLUME /srv/logs

EXPOSE ${AUTH_PORT}
EXPOSE ${GAME_PORT}

ENTRYPOINT ["./start.sh"]
148 changes: 132 additions & 16 deletions README.md

Large diffs are not rendered by default.

16 changes: 9 additions & 7 deletions config.ini.dist
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ client.version = ${CLIENT_VERSION:-1.29.1}
; > Available algorithms : argon2, plain
; > The first value will be the default hash algorithm
; > Default value: "argon2, plain"
;password.defaultHash = argon2
password.defaultHash = "${PASSWORD_HASH:-argon2, plain}"
; > The number of iterations. Default: 4
;password.argon2.iterations = 4
; > The memory, in kilobits. Default: 65536 (64Mo)
Expand Down Expand Up @@ -89,13 +89,15 @@ realm.user = ${DB_USER:-araknemu}
realm.password = $DB_PASSWORD
realm.dbname = ${DB_NAME:-araknemu}
realm.path = ${DB_NAME:-araknemu.db}
realm.poolSize = ${DB_POOL_SIZE:-8}

; Configure database for game server
game.type = ${DB_TYPE:-mysql}
game.host = ${DB_HOST:-127.0.0.1}
game.user = ${DB_USER:-araknemu}
game.password = $DB_PASSWORD
game.dbname = ${DB_NAME:-araknemu}
game.poolSize = ${DB_POOL_SIZE:-8}

[game]
; Section for configure the game server
Expand All @@ -113,7 +115,7 @@ server.timezone = ${TIMEZONE:-Europe/Paris}
; Antispam & other
; ----------------
; > The server ID. By default 1
;id = 1
id = ${GAME_SERVER_ID:-1}
; > The maximum inactivity time, as duration
; > By default, 15min ("PT15M" or "15m")
;inactivityTime = 15m
Expand Down Expand Up @@ -184,7 +186,7 @@ server.timezone = ${TIMEZONE:-Europe/Paris}
; Activity
; --------
; > Number of threads to use for the activity service
;activity.threadsCount = 1
activity.threadsCount = ${ACTIVITY_THREADS:-1}
; > Number of seconds for move monster groups
; > By default 120s = 2min
;activity.monsters.moveInterval = 120
Expand All @@ -198,7 +200,7 @@ server.timezone = ${TIMEZONE:-Europe/Paris}
; > The delay divisor for respawn a monster group
; > With a factor of 2, the respawn will be 2 times faster
; > By default 1
;activity.monsters.respawnSpeedFactor = 1
activity.monsters.respawnSpeedFactor = ${RESPAWN_SPEED_FACTOR:-1}

; Economy
; -------
Expand All @@ -217,7 +219,7 @@ server.timezone = ${TIMEZONE:-Europe/Paris}
; > The threads count for run fight actions and AI
; > This value should be greater than 2. A good value may be around 1 thread per 100 fights
; > By default, 4
;fight.threadsCount = 4
fight.threadsCount = ${FIGHT_THREADS:-4}
; > The fight turn duration
; > The value should be a duration string like 30s, 1m10s
; > Default value : 30s
Expand All @@ -229,13 +231,13 @@ server.timezone = ${TIMEZONE:-Europe/Paris}
; > Get the XP multiplier
; > The value should be a positive decimal number.
; > Default value : 1.0
fight.rate.xp = ${XP_RATE:-1.0}
fight.rate.xp = ${RATE_XP:-1.0}
; > Get the drop rate multiplier
; > The value should be a positive decimal number.
; > This value will modify the object drop chance, but not the maximum dropped items per monster
; > nor minimal discernment requirement.
; > Default value : 1.0
fight.rate.drop = ${DROP_RATE:-1.0}
fight.rate.drop = ${RATE_DROP:-1.0}
; > Get the initial erosion rate for fighters
; > This value is a percentage, representing the percent of damage that will be transformed to permanent life loss
; > It must be between 0 and 100, where 0 means no erosion and 100 means all damage are permanent
Expand Down
30 changes: 30 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
services:
araknemu:
build:
context: .
dockerfile: Dockerfile
target: production
env_file:
- .env
restart: on-failure # Database may not be ready when the app starts
ports:
- "4444:4444"
- "5555:5555"
volumes:
- ./logs:/srv/logs
- ./scripts:/srv/scripts
#- ./araknemu.db:/srv/araknemu.db
#- ./config.ini:/srv/config.ini
depends_on:
- db

db:
image: mariadb:11.3
environment:
MARIADB_RANDOM_ROOT_PASSWORD: 1
MARIADB_DATABASE: araknemu
MARIADB_USER: araknemu
MARIADB_PASSWORD: araknemu
volumes:
- ./db:/var/lib/mysql
- ./resources/db:/docker-entrypoint-initdb.d
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ public final class SQLiteDriver implements Driver {
private final DatabaseConfiguration.Connection configuration;

public SQLiteDriver(DatabaseConfiguration.Connection configuration) {
try {
Class.forName("org.sqlite.JDBC");
} catch (ClassNotFoundException e) {
throw new IllegalStateException("SQLite JDBC driver not found", e);
}

this.configuration = configuration;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void test_mysql() {
assertEquals("mysql", config.type());
assertEquals("araknemu", config.dbname());
assertEquals("araknemu", config.user());
assertEquals("", config.password());
assertEquals("araknemu", config.password());
assertEquals(16, config.maxPoolSize());
}

Expand Down
1 change: 1 addition & 0 deletions src/test/test_config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ test_sqlite.path = test.db

test_mysql.host = localhost
test_mysql.user = araknemu
test_mysql.password = araknemu
test_mysql.dbname = araknemu

test_ar.type = sqlite
Expand Down
63 changes: 63 additions & 0 deletions start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash
#
# This file is part of Araknemu.
#
# Araknemu is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Araknemu is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Araknemu. If not, see <https://www.gnu.org/licenses/>.
#
# Copyright (c) 2017-2024 Vincent Quatrevieux
#

# ==============================================================================
# This script is used to start Araknemu from a Docker container.
# It relies on environment variables to configure the JVM and wait for MariaDB.
# If you want to run Araknemu outside of a Docker container, use directly
# `java -jar target/araknemu-xxx-alpha-jar-with-dependencies.jar`
# ==============================================================================

if [ "${DB_TYPE:-mysql}" = "mysql" ]; then
# Wait for MariaDB to be ready
echo -n "Waiting for MariaDB to be ready..."
DB_STARTED=0

for ((i=0; i < 300; i++))
do
nc -z $DB_HOST 3306 && DB_STARTED=1 && break
echo -n "."
sleep 0.1
done

if [ "$DB_STARTED" != 1 ]; then
echo " [FAILED] MariaDB is not ready"
exit 1
else
echo " [OK]"
fi
fi

JAVA_MEMORY=${JAVA_MEMORY-"512m"}
JAVA_GC=${JAVA_GC:-"G1GC"}

if [ "$JAVA_GC_LOG" = "1" ]; then
JAVA_GC_LOG="-Xlog:gc*:file=/srv/logs/gc-%t.log:tags,time,uptime,level:filecount=10,filesize=8M"
fi

if [ -n "$JAVA_MEMORY" ]; then
JAVA_MEMORY="-Xms${JAVA_MEMORY} -Xmx${JAVA_MEMORY}"
fi

JAVA_OPTS="$JAVA_MEMORY -XX:+Use${JAVA_GC} $JAVA_GC_LOG $JAVA_OPTS"

echo "Starting Araknemu with java options: $JAVA_OPTS"

java $JAVA_OPTS -jar araknemu.jar

0 comments on commit f0cc510

Please sign in to comment.