-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow configuring server.properties
Configuring the server.properties file is managed by passing environment variables prefixed with `MC_`. The prefix is removed, any `_` are replaced with `-` and the value is lowercased to find the correct server.properties key. For example: `MC_MAX_PLAYERS` becomes `max-players` refactor: separate user configuration to a stand-alone script This will allow this script to be moved elsewhere to simplify maintenance and allow for reusability. docs: create readme file
- Loading branch information
1 parent
6e3cb0e
commit da309e5
Showing
5 changed files
with
128 additions
and
11 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 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,82 @@ | ||
# [anthonyporthouse/minecraft-server](https://github.com/anthonyporthouse/minecraft-server) | ||
|
||
## Tags | ||
|
||
The major tags determine which version of java you will be using to run minecraft. | ||
|
||
- `java8` | ||
- `java11` | ||
- `java16` | ||
- `java17` | ||
|
||
## Usage | ||
|
||
### docker-compose | ||
|
||
Example `docker-compose.yaml` file: | ||
|
||
```yaml | ||
--- | ||
services: | ||
minecraft: | ||
image: ghcr.io/anthonyporthouse/minecraft-server:java17 | ||
|
||
restart: unless-stopped | ||
|
||
environment: | ||
PUID: 1000 | ||
PGID: 1000 | ||
|
||
MINECRAFT_VERSION: 1.20.2 | ||
JAVA_OPTS: -Xms1G -Xmx2G | ||
|
||
MC_DIFFICULTY: hard | ||
MC_MOTD: My Server | ||
|
||
ports: | ||
- "25565:25565" | ||
|
||
volumes: | ||
- ./server:/minecraft | ||
|
||
``` | ||
|
||
### Environment Variables | ||
|
||
To make this image more useful several environment variables are available to use. | ||
|
||
**`PUID`** | ||
|
||
> Default Value: `1000` | ||
This environment variable specifies the ID to use for the minecraft user inside of the container. | ||
|
||
This should map to the current users UID which can be found using `id -u` on Linux or Mac. | ||
|
||
**`PGID`** | ||
|
||
> Default Value: `1000` | ||
This environment variable specifies the ID to use for the minecraft group inside of the container. | ||
|
||
This should map to the current users GID which can be found using `id -g` on Linux or Mac. | ||
|
||
**`MINECRAFT_VERSION`** | ||
|
||
> Default Value: `1.20.2` | ||
This environment variable specifies which version of Minecraft you wish to run. This can be any version supported, either stable or prerelease. | ||
|
||
If this is changed after an initial run the container will pull the new version and use that. | ||
|
||
**`JAVA_OPTS`** | ||
|
||
> Default Value: `-Xms1G -Xmx2G` | ||
This environment variable allows you to specify custom JVM arguments when running minecraft. | ||
|
||
**`MC_*`** | ||
|
||
Any environment variable that is prefixed with `MC_` will have its prefix removed, be lowercased and have any `_` replaced with `-` then be either replaced, or appended to the `server.properties` file. | ||
|
||
Example: `MC_MAX_PLAYERS` with value `10` sets the value of `max-players=10` in the `server.properties` file. |
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,18 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
vars=("${!MC_@}") | ||
|
||
if [ ! -f /minecraft/server.properties ]; then | ||
echo "#" > /minecraft/server.properties | ||
fi | ||
|
||
for var in "${vars[@]}"; do | ||
|
||
name=$(echo "$var" | tr '[:upper:]' '[:lower:]' | sed -e 's/^mc_//' -e 's/_/-/') | ||
value=$(printenv "$var") | ||
|
||
echo "$name=$value" | ||
|
||
sed -i "/^$name=/{h;s/=.*/=$value/};\${x;/^$/{s//$name=$value/;H};x}" /minecraft/server.properties | ||
done |
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,23 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
# Username/Groupname to use | ||
USER=$1 | ||
|
||
# Target User ID | ||
PUID=$2 | ||
|
||
# Target Group ID | ||
PGID=$3 | ||
|
||
if [ ! "$(id -u "${USER}")" -eq "$PUID" ]; then usermod -o -u "$PUID" "${USER}" ; fi | ||
if [ ! "$(id -g "${USER}")" -eq "$PGID" ]; then groupmod -o -g "$PGID" "${USER}" ; fi | ||
|
||
echo " | ||
----------------------------------- | ||
GID/UID | ||
----------------------------------- | ||
User uid: $(id -u "${USER}") | ||
User gid: $(id -g "${USER}") | ||
----------------------------------- | ||
" |