This repository has been archived by the owner on Jan 12, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 65
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 #72 from AlexandreVassard/master
Docker compatibility
- Loading branch information
Showing
7 changed files
with
258 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.env | ||
.env.example | ||
.gitattributes | ||
.gitignore | ||
compose.yml | ||
Dockerfile | ||
LICENSE.txt | ||
README.md | ||
.github | ||
.vscode |
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,26 @@ | ||
# Server | ||
SERVER_BIND=0.0.0.0 | ||
SERVER_PORT=12321 | ||
|
||
# Rcon | ||
RCON_BIND=0.0.0.0 | ||
RCON_PORT=12309 | ||
|
||
# Mus | ||
MUS_BIND=0.0.0.0 | ||
MUS_PORT=12322 | ||
|
||
# Database | ||
MYSQL_HOSTNAME=mariadb | ||
MYSQL_PORT=3306 | ||
MYSQL_USER=kepler | ||
MYSQL_PASSWORD=verysecret | ||
MYSQL_DATABASE=kepler | ||
MARIADB_ROOT_PASSWORD=veryverysecret | ||
|
||
# Logging | ||
LOG_RECEIVED_PACKETS=false | ||
LOG_SENT_PACKETS=false | ||
|
||
# Console | ||
DEBUG=false |
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 |
---|---|---|
|
@@ -24,3 +24,5 @@ error.log | |
.env | ||
Kepler-Server/src/main/java/META-INF/MANIFEST.MF | ||
*.log | ||
.env | ||
.vscode |
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,56 @@ | ||
############## | ||
# BASE STAGE # | ||
############## | ||
|
||
FROM alpine:3.20 AS base | ||
|
||
# Add OpenJDK17 | ||
RUN apk add openjdk17=17.0.12_p7-r0 | ||
|
||
# Uses /kepler directory | ||
WORKDIR /kepler | ||
|
||
############### | ||
# BUILD STAGE # | ||
############### | ||
|
||
FROM base AS build | ||
|
||
# Add unzip | ||
RUN apk add unzip=6.0-r14 | ||
|
||
# Copy every files/folders that are not in .dockerignore | ||
COPY . . | ||
|
||
# Convert CRLF to LF executable files (failing build for Windows without this) | ||
RUN sed -i 's/\r$//' gradlew tools/scripts/run.sh entrypoint.sh | ||
|
||
# Make gradlew, entrypoint.sh and run.sh executable | ||
RUN chmod +x gradlew entrypoint.sh tools/scripts/run.sh | ||
|
||
# Run gradle build | ||
RUN ./gradlew distZip | ||
|
||
# Unzip builded Kepler server | ||
RUN unzip -qq ./Kepler-Server/build/distributions/Kepler-Server.zip -d ./release | ||
|
||
# Prepare build directory | ||
RUN rm -rf ./release/Kepler-Server/bin && \ | ||
mkdir -p ./build/lib && \ | ||
mv ./release/Kepler-Server/lib/Kepler-Server.jar ./build/kepler.jar && \ | ||
mv ./release/Kepler-Server/lib/* ./build/lib && \ | ||
mv ./entrypoint.sh ./build/entrypoint.sh && \ | ||
cp tools/scripts/run.sh ./build/ | ||
|
||
#################### | ||
# PRODUCTION STAGE # | ||
#################### | ||
|
||
FROM base AS production | ||
|
||
# Copy builded Kepler server | ||
COPY --from=build /kepler/build ./ | ||
|
||
ENTRYPOINT [ "sh", "entrypoint.sh" ] | ||
|
||
CMD [ "sh", "run.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,33 @@ | ||
services: | ||
kepler: | ||
build: . | ||
container_name: kepler | ||
restart: unless-stopped | ||
env_file: | ||
- .env | ||
depends_on: | ||
mariadb: | ||
condition: service_healthy | ||
ports: | ||
- "${SERVER_PORT}:${SERVER_PORT}" | ||
- "${RCON_PORT}:${RCON_PORT}" | ||
- "${MUS_PORT}:${MUS_PORT}" | ||
mariadb: | ||
image: mariadb:11.4 | ||
container_name: kepler-mariadb | ||
restart: unless-stopped | ||
env_file: | ||
- .env | ||
volumes: | ||
- mariadb:/var/lib/mysql | ||
- ./tools/kepler.sql:/docker-entrypoint-initdb.d/kepler.sql | ||
healthcheck: | ||
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"] | ||
start_period: 10s | ||
interval: 10s | ||
timeout: 5s | ||
retries: 3 | ||
|
||
volumes: | ||
mariadb: | ||
name: kepler-mariadb |
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,79 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
INI_FILE="/kepler/server.ini" | ||
|
||
# Function to check for the existence of server.ini | ||
check_for_ini_file() { | ||
if [ -f $INI_FILE ]; then | ||
return 0 | ||
else | ||
return 1 | ||
fi | ||
} | ||
|
||
if ! check_for_ini_file; then | ||
echo "[+] server.ini file not detected, running Kepler to create it..." | ||
./run.sh &> /dev/null | ||
echo "[+] Cleaning up logs..." | ||
rm -f server.log error.log | ||
fi | ||
|
||
echo "[+] server.ini file detected !" | ||
|
||
# Function to update the .ini file | ||
update_ini_file() { | ||
local key=$1 | ||
local value=$2 | ||
local ini_file=$3 | ||
local default_value=$4 | ||
|
||
if [ -n "$value" ]; then | ||
if grep -q "^$key=" "$ini_file"; then | ||
sed -i "s|^$key=.*|$key=$value|" "$ini_file" | ||
else | ||
echo "$key=$value" >> "$ini_file" | ||
fi | ||
else | ||
if grep -q "^$key=" "$ini_file"; then | ||
sed -i "s|^$key=.*|$key=$default_value|" "$ini_file" | ||
else | ||
echo "$key=$default_value" >> "$ini_file" | ||
fi | ||
fi | ||
|
||
|
||
} | ||
|
||
echo "[+] Configuring server.ini with environment variables..." | ||
|
||
# Server | ||
update_ini_file "server.bind" "$SERVER_BIND" "$INI_FILE" "127.0.0.1" | ||
update_ini_file "server.port" "$SERVER_PORT" "$INI_FILE" "12321" | ||
|
||
# Rcon | ||
update_ini_file "rcon.bind" "$RCON_BIND" "$INI_FILE" "127.0.0.1" | ||
update_ini_file "rcon.port" "$RCON_PORT" "$INI_FILE" "12309" | ||
|
||
# Mus | ||
update_ini_file "mus.bind" "$MUS_BIND" "$INI_FILE" "127.0.0.1" | ||
update_ini_file "mus.port" "$MUS_PORT" "$INI_FILE" "12322" | ||
|
||
# Database | ||
update_ini_file "mysql.hostname" "$MYSQL_HOSTNAME" "$INI_FILE" "127.0.0.1" | ||
update_ini_file "mysql.port" "$MYSQL_PORT" "$INI_FILE" "3306" | ||
update_ini_file "mysql.username" "$MYSQL_USER" "$INI_FILE" "kepler" | ||
update_ini_file "mysql.password" "$MYSQL_PASSWORD" "$INI_FILE" "verysecret" | ||
update_ini_file "mysql.database" "$MYSQL_DATABASE" "$INI_FILE" "kepler" | ||
|
||
# Logging | ||
update_ini_file "log.received.packets" "$LOG_RECEIVED_PACKETS" "$INI_FILE" "false" | ||
update_ini_file "log.sent.packets" "$LOG_SENT_PACKETS" "$INI_FILE" "false" | ||
|
||
# Console | ||
update_ini_file "debug" "$DEBUG" "$INI_FILE" "false" | ||
|
||
echo "[+] Running Kepler..." | ||
|
||
# Execute the command passed to the entrypoint | ||
exec "$@" |