Skip to content

Commit e5df356

Browse files
authored
Merge pull request #72 from AlexandreVassard/master
Docker compatibility
2 parents e232f49 + d73908f commit e5df356

7 files changed

+258
-0
lines changed

.dockerignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.env
2+
.env.example
3+
.gitattributes
4+
.gitignore
5+
compose.yml
6+
Dockerfile
7+
LICENSE.txt
8+
README.md
9+
.github
10+
.vscode

.env.example

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Server
2+
SERVER_BIND=0.0.0.0
3+
SERVER_PORT=12321
4+
5+
# Rcon
6+
RCON_BIND=0.0.0.0
7+
RCON_PORT=12309
8+
9+
# Mus
10+
MUS_BIND=0.0.0.0
11+
MUS_PORT=12322
12+
13+
# Database
14+
MYSQL_HOSTNAME=mariadb
15+
MYSQL_PORT=3306
16+
MYSQL_USER=kepler
17+
MYSQL_PASSWORD=verysecret
18+
MYSQL_DATABASE=kepler
19+
MARIADB_ROOT_PASSWORD=veryverysecret
20+
21+
# Logging
22+
LOG_RECEIVED_PACKETS=false
23+
LOG_SENT_PACKETS=false
24+
25+
# Console
26+
DEBUG=false

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ error.log
2424
.env
2525
Kepler-Server/src/main/java/META-INF/MANIFEST.MF
2626
*.log
27+
.env
28+
.vscode

Dockerfile

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
##############
2+
# BASE STAGE #
3+
##############
4+
5+
FROM alpine:3.20 AS base
6+
7+
# Add OpenJDK17
8+
RUN apk add openjdk17=17.0.12_p7-r0
9+
10+
# Uses /kepler directory
11+
WORKDIR /kepler
12+
13+
###############
14+
# BUILD STAGE #
15+
###############
16+
17+
FROM base AS build
18+
19+
# Add unzip
20+
RUN apk add unzip=6.0-r14
21+
22+
# Copy every files/folders that are not in .dockerignore
23+
COPY . .
24+
25+
# Convert CRLF to LF executable files (failing build for Windows without this)
26+
RUN sed -i 's/\r$//' gradlew tools/scripts/run.sh entrypoint.sh
27+
28+
# Make gradlew, entrypoint.sh and run.sh executable
29+
RUN chmod +x gradlew entrypoint.sh tools/scripts/run.sh
30+
31+
# Run gradle build
32+
RUN ./gradlew distZip
33+
34+
# Unzip builded Kepler server
35+
RUN unzip -qq ./Kepler-Server/build/distributions/Kepler-Server.zip -d ./release
36+
37+
# Prepare build directory
38+
RUN rm -rf ./release/Kepler-Server/bin && \
39+
mkdir -p ./build/lib && \
40+
mv ./release/Kepler-Server/lib/Kepler-Server.jar ./build/kepler.jar && \
41+
mv ./release/Kepler-Server/lib/* ./build/lib && \
42+
mv ./entrypoint.sh ./build/entrypoint.sh && \
43+
cp tools/scripts/run.sh ./build/
44+
45+
####################
46+
# PRODUCTION STAGE #
47+
####################
48+
49+
FROM base AS production
50+
51+
# Copy builded Kepler server
52+
COPY --from=build /kepler/build ./
53+
54+
ENTRYPOINT [ "sh", "entrypoint.sh" ]
55+
56+
CMD [ "sh", "run.sh" ]

README.md

+52
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,58 @@ As for the client, you can find version 14 DCRs [here](https://web.archive.org/w
6262

6363
Setup the loader files on a web server, and once Kepler is started, ensure the loader is connecting to the correct IP and ports for both the standard connection and MUS connection. The MUS connection is used for the camera.
6464

65+
# Docker installation
66+
67+
Install [Docker](https://docs.docker.com/engine/install/) and [git](https://git-scm.com/downloads) (optional) on your device.
68+
69+
### 1. Clone repository
70+
71+
```shell
72+
git clone https://github.com/Quackster/Kepler.git
73+
```
74+
75+
_You can also [download](https://github.com/Quackster/Kepler/archive/refs/heads/master.zip) this repository and unzip it._
76+
77+
### 2. Configure variables
78+
79+
Copy `.env.example` file to `.env` :
80+
81+
```shell
82+
cp .env.example .env
83+
```
84+
85+
You can now configure all variables in `.env` file with values needed.
86+
87+
_Don't change `MYSQL_HOST` except if you change the name of the service `mariadb` in Docker compose file._
88+
89+
_You neither should change `MYSQL_PORT`._
90+
91+
### 3. Start Kepler
92+
93+
You just need to run Docker compose inside of Kepler directory :
94+
95+
```shell
96+
docker compose up -d
97+
```
98+
99+
To stop Kepler :
100+
101+
```shell
102+
docker compose down
103+
```
104+
105+
### Docker FAQ
106+
107+
#### Reset MariaDB database
108+
109+
You need to first stop Kepler, then remove MariaDB volume :
110+
111+
```shell
112+
docker compose down && docker volume rm kepler-mariadb
113+
```
114+
115+
You can now start Kepler again, database will be wiped out !
116+
65117
## License
66118

67119
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

compose.yml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
services:
2+
kepler:
3+
build: .
4+
container_name: kepler
5+
restart: unless-stopped
6+
env_file:
7+
- .env
8+
depends_on:
9+
mariadb:
10+
condition: service_healthy
11+
ports:
12+
- "${SERVER_PORT}:${SERVER_PORT}"
13+
- "${RCON_PORT}:${RCON_PORT}"
14+
- "${MUS_PORT}:${MUS_PORT}"
15+
mariadb:
16+
image: mariadb:11.4
17+
container_name: kepler-mariadb
18+
restart: unless-stopped
19+
env_file:
20+
- .env
21+
volumes:
22+
- mariadb:/var/lib/mysql
23+
- ./tools/kepler.sql:/docker-entrypoint-initdb.d/kepler.sql
24+
healthcheck:
25+
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
26+
start_period: 10s
27+
interval: 10s
28+
timeout: 5s
29+
retries: 3
30+
31+
volumes:
32+
mariadb:
33+
name: kepler-mariadb

entrypoint.sh

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/bin/bash
2+
set -e
3+
4+
INI_FILE="/kepler/server.ini"
5+
6+
# Function to check for the existence of server.ini
7+
check_for_ini_file() {
8+
if [ -f $INI_FILE ]; then
9+
return 0
10+
else
11+
return 1
12+
fi
13+
}
14+
15+
if ! check_for_ini_file; then
16+
echo "[+] server.ini file not detected, running Kepler to create it..."
17+
./run.sh &> /dev/null
18+
echo "[+] Cleaning up logs..."
19+
rm -f server.log error.log
20+
fi
21+
22+
echo "[+] server.ini file detected !"
23+
24+
# Function to update the .ini file
25+
update_ini_file() {
26+
local key=$1
27+
local value=$2
28+
local ini_file=$3
29+
local default_value=$4
30+
31+
if [ -n "$value" ]; then
32+
if grep -q "^$key=" "$ini_file"; then
33+
sed -i "s|^$key=.*|$key=$value|" "$ini_file"
34+
else
35+
echo "$key=$value" >> "$ini_file"
36+
fi
37+
else
38+
if grep -q "^$key=" "$ini_file"; then
39+
sed -i "s|^$key=.*|$key=$default_value|" "$ini_file"
40+
else
41+
echo "$key=$default_value" >> "$ini_file"
42+
fi
43+
fi
44+
45+
46+
}
47+
48+
echo "[+] Configuring server.ini with environment variables..."
49+
50+
# Server
51+
update_ini_file "server.bind" "$SERVER_BIND" "$INI_FILE" "127.0.0.1"
52+
update_ini_file "server.port" "$SERVER_PORT" "$INI_FILE" "12321"
53+
54+
# Rcon
55+
update_ini_file "rcon.bind" "$RCON_BIND" "$INI_FILE" "127.0.0.1"
56+
update_ini_file "rcon.port" "$RCON_PORT" "$INI_FILE" "12309"
57+
58+
# Mus
59+
update_ini_file "mus.bind" "$MUS_BIND" "$INI_FILE" "127.0.0.1"
60+
update_ini_file "mus.port" "$MUS_PORT" "$INI_FILE" "12322"
61+
62+
# Database
63+
update_ini_file "mysql.hostname" "$MYSQL_HOSTNAME" "$INI_FILE" "127.0.0.1"
64+
update_ini_file "mysql.port" "$MYSQL_PORT" "$INI_FILE" "3306"
65+
update_ini_file "mysql.username" "$MYSQL_USER" "$INI_FILE" "kepler"
66+
update_ini_file "mysql.password" "$MYSQL_PASSWORD" "$INI_FILE" "verysecret"
67+
update_ini_file "mysql.database" "$MYSQL_DATABASE" "$INI_FILE" "kepler"
68+
69+
# Logging
70+
update_ini_file "log.received.packets" "$LOG_RECEIVED_PACKETS" "$INI_FILE" "false"
71+
update_ini_file "log.sent.packets" "$LOG_SENT_PACKETS" "$INI_FILE" "false"
72+
73+
# Console
74+
update_ini_file "debug" "$DEBUG" "$INI_FILE" "false"
75+
76+
echo "[+] Running Kepler..."
77+
78+
# Execute the command passed to the entrypoint
79+
exec "$@"

0 commit comments

Comments
 (0)