-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #350 from vincent4vx/chore-docker
chore: setup docker
- Loading branch information
Showing
11 changed files
with
290 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |