46 Commits

Author SHA1 Message Date
bed8684352 Actually wait let's reorder those args 2022-06-14 14:33:13 -05:00
58e34860fd Actually make /minecraft writeable 2022-06-14 14:32:15 -05:00
8d2c901978 Fix invocation of addgroup and adduser
Hopefully really this time
2022-06-14 14:20:21 -05:00
07c8bfd165 Quote variables, actually scope in our arguments 2022-06-14 14:16:51 -05:00
30802403cc Use busyboxisms for creating a user/group 2022-06-14 14:14:21 -05:00
bdbcebf366 Ignore permissions on rsync 2022-06-14 14:10:39 -05:00
e48fa26b5a Try adding a user to the container 2022-06-14 14:10:19 -05:00
e057c808a8 Remove the JDK version and Forge version from our tags because we don't care about them
They're static for each version
2022-06-14 13:59:11 -05:00
1999a0c0d0 Remove the -a flag from our rsync
We really don't care about source perms, as it turns out
2022-06-14 13:56:39 -05:00
59a75d1d3e Add a tiny bit more logging before that rsync 2022-05-26 22:12:18 -05:00
eca3af7ffb Add findutils, be less verbose for easier log parsing 2022-05-26 22:05:42 -05:00
533ceb2c2e Add a patch to make sure we don't recursively copy root around 2022-05-26 21:59:36 -05:00
01d9af75f0 Add curl
oposie wopsie
2022-05-26 21:49:29 -05:00
c9d54cc46d Add link to DH in README 2022-05-17 11:34:13 -05:00
025d88f7e0 Fix JRE_VERSION being unscoped in the final stage 2022-05-17 11:33:48 -05:00
a107b4b76e Explicitly set progress to plain for easier debugging, label the final stage of the build 2022-05-17 11:24:15 -05:00
d410061076 Add some more flawed changes to the Dockerfile to debug JRE_VERSION 2022-05-17 11:22:36 -05:00
2a860d745d Add some flawed changes to build.sh to try and debug JRE_VERSION 2022-05-17 11:22:22 -05:00
e655849b38 set -e in the build script so it stops eating errors 2022-05-17 11:12:16 -05:00
904bd4ea78 Change README to point to a tag that actually exists 2022-05-17 11:11:21 -05:00
322b6f359d Use Alpine instead of the OpenJDK upstream image
Thinner and actually respects that JRE_VERSION var we added
2022-05-17 11:07:10 -05:00
4236f531da Add a line to the README about how I... don't really use tags all that often 2022-05-17 11:01:35 -05:00
76f8fc6644 Add LICENSE 2022-05-17 10:59:40 -05:00
c480cd4abd Touch up that README, make it more parseable 2022-05-17 10:58:51 -05:00
f62c82e61a Modularize the addition of OpenJDK, enabling branch convergence 2022-05-17 10:53:13 -05:00
18994698db Merge branch 'openjdk11' 2022-05-17 10:43:42 -05:00
614818ba04 Update 1.16 forge, add 1.18 forge 2022-05-17 10:42:15 -05:00
a35c565148 Okay, really change forge version 2022-02-09 17:10:26 -06:00
6dfd52c7d9 Bump Forge ver 2022-02-09 15:57:14 -06:00
b4fc6a2654 Merge branch 'openjdk11' of gitlab.com:rehashedsalt/docker-minecraft into openjdk11 2022-01-02 10:59:00 -06:00
7879f3b5e4 Add little helper line to the Docker log output to assist in usability 2022-01-02 10:57:28 -06:00
2e03a1faf8 Update Forge for 1.16
I uh... hope this fixes the log4j issue
2021-12-20 12:26:22 -06:00
bd2041a886 Ignore existing files when unpacking server zippies 2021-11-06 14:28:07 -05:00
82715dcd5b Ignore existing files when unpacking server zippies 2021-11-06 14:27:29 -05:00
62c4ef86af Add the ability to define a configuration repo that's also live-downloaded 2021-05-29 14:23:41 -05:00
2fba83fd15 Add the ability to define a configuration repo that's also live-downloaded 2021-05-29 14:22:53 -05:00
c50a4b4176 Attempt a build on ojdk11 2021-05-24 21:46:29 -05:00
60943d2f82 Backdate Forge on 1.16.5 2021-05-22 00:24:26 -05:00
c7328f43c2 Update the build script so it actually changes the Minecraft version 2021-05-22 00:14:16 -05:00
0dd98315e5 Testing an alternative approach to the CI 2021-05-22 00:07:13 -05:00
5be6e30444 Add documentation on that new server console 2021-05-12 23:20:31 -05:00
ed6fc1af16 Add trap to gracefully cleanup, add screen session 2021-05-12 22:41:01 -05:00
df3c6166ac Bump Forge to 1.16.5-36.1.13 2021-05-11 21:02:24 -05:00
7bd0953dad Update README 2021-04-09 16:56:32 -05:00
8a78fd604a Dynamically download modpacks at runtime if so desired 2021-04-09 16:54:45 -05:00
7a6404b861 Initial test build. Looks like everything works 2021-04-09 16:28:17 -05:00
8 changed files with 340 additions and 0 deletions

6
.dockerignore Normal file
View File

@@ -0,0 +1,6 @@
*.swp
.git
.gitignore
.gitlab-ci.yml
README.md
build.sh

27
.gitlab-ci.yml Normal file
View File

@@ -0,0 +1,27 @@
#
# This guy is awesome: https://dev.to/bzinoun/gitlab-ci-to-build-and-push-containers-to-registry-538a
#
image: morlay/buildx:607a2ce
variables:
# DinD's vfs driver is pretty intensive; this is less so
DOCKER_DRIVER: overlay2
CI_HUB_USERNAME: rehashedsalt
CI_PROJECT_NAME: minecraft-forge
stages:
- build
services:
- docker:dind
before_script:
- echo -n "$CI_LOGIN_PASSWORD" | docker login -u "$CI_LOGIN_USERNAME" --password-stdin
- docker version
- docker info
- apk add bash
after_script:
- docker logout hub.docker.com
# BUILD
Build:
stage: build
script:
- bash build.sh

48
Dockerfile Normal file
View File

@@ -0,0 +1,48 @@
# Args
ARG MINECRAFT_VERSION="1.16.5"
ARG FORGE_VERSION="36.2.26"
ARG JRE_VERSION="openjdk8-jre"
ARG UID=1520
ARG USER=minecraft
ARG GID=1520
ARG GROUP=minecraft
# The first stage just builds up the modpack
FROM alpine:latest AS build
# Use all of our arguments
ARG MINECRAFT_VERSION
ARG FORGE_VERSION
ARG JRE_VERSION
# Build us up the basics of the Minecraft server environment
COPY start-server.sh /minecraft/start-server.sh
WORKDIR /minecraft
RUN apk add curl "${JRE_VERSION}" &&\
curl -L "https://files.minecraftforge.net/maven/net/minecraftforge/forge/${MINECRAFT_VERSION}-${FORGE_VERSION}/forge-${MINECRAFT_VERSION}-${FORGE_VERSION}-installer.jar" -o installer.jar &&\
java -jar installer.jar --installServer &&\
echo "eula=true" > eula.txt &&\
rm installer.jar installer.jar.log && \
ln -s "forge-${MINECRAFT_VERSION}-${FORGE_VERSION}.jar" server.jar
# Stuff them in a smaller container with fewer layers
FROM alpine:latest AS final
# Use only a subset of arguments
ARG JRE_VERSION
ARG UID
ARG USER
ARG GID
ARG GROUP
# Build the thing up
RUN apk add bash curl findutils rsync screen "${JRE_VERSION}"
WORKDIR /minecraft
COPY --from=build /minecraft .
RUN addgroup -g "${GID}" "${GROUP}" && \
adduser -h /minecraft -s /bin/sh -D -H -u "${UID}" -G "${GROUP}" "${USER}" && \
chown "${USER}:${GROUP}" /minecraft
USER $USER
CMD [ "bash", "start-server.sh" ]
EXPOSE 25565

7
LICENSE Normal file
View File

@@ -0,0 +1,7 @@
Copyright 2021 Salt
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

84
README.md Normal file
View File

@@ -0,0 +1,84 @@
# docker-minecraft
A Dockerfile and some assorted scripts to build a Minecraft Forge server container.
## Usage
Deploy as expected:
```bash
docker run -p 25565:25565 rehashedsalt/minecraft-forge:1.16.5-36.2.35-openjdk11-jre-master
```
And badda bing, badda boom, you'll have a Minecraft Forge server of whatever the tag is.
The tag looks long and unweildy, but it's just this:
```
rehashedsalt/minecraft-forge:${MINECRAFT_VERSION}-${FORGE_VERSION}-${OPENJDK_VERSION}-${BRANCH_OR_TAG_NAME}
```
You can see what the supported combinations of tags are by looking them up in `build.sh`. Each version only supports one edition of Java and one edition of Forge. Getting CI/CD to automagically determine the latest version of Forge is on the to-do list.
Admittedly, I don't use tags very often. You'd do well to target `master` as the refname if you want bleeding edge stuff.
Full list of tags is available on [Dockerhub](https://hub.docker.com/r/rehashedsalt/minecraft-forge/tags).
## Server Console
You can access the server console in a screen session pretty easily:
```bash
docker exec -it mycontainer screen -r minecraft
```
## Application State
For obvious reasons, you'll want to consult the documentation of any mods you have installed, but a majority of application state lives here-ish:
* `/minecraft/world`
* `/minecraft/ops.json`, `whitelist.json`, `banned-ips.json`, `banned-players.json`, etc.
* `/minecraft/logs`
## Environment Variables
variable|description
---|---
`JRE_XMX`|Maximum amount of heap passed to the main Minecraft process
`JRE_XMS`|Minimum heap size passed to the main Minecraft process
`FORGE_PACK_ZIP`|If provided, the URL to a zip or tar.gz file that contains the modpack that needs to be installed. Will be intelligently extracted into the server directory through the magic of `find`.
`CONFIG_REPO`|If provided, the URI to a git repository that contains configuration to copy over top the pack. The root of the repo will be the root of the server directory.
`ARGS`|Any additional arguments to be passed to the JVM
## Useful Arguments
The following arguments may be useful to pass through `$ARGS` from time to time:
* `-Dfml.queryResult=confirm` - Useful when confirming through world corruption
* Consider [this advice from a Forge dev](https://old.reddit.com/r/feedthebeast/comments/5jhuk9/modded_mc_and_memory_usage_a_history_with_a/) (circa 5+ years ago but still pretty relevant)
## Weird Defaults
The default `server.properties` contains the following changes to better facilitate usage in a modded environment:
```
allow-flight=true
difficulty=hard
enable-command-block=true
spawn-protection=0
```
## FAQ
**Why do you download the pack at runtime?**
It allows for transparent upgrades without having to build a whole new container. You may lose container consistency, but you gain simplicity in definition.
Of course, nothing prevents you from just not using this magic variable and instead `FROM`ing this container and building your own pack.
## License
MIT

54
build.sh Executable file
View File

@@ -0,0 +1,54 @@
#! /bin/bash
#
# Build the Docker image for a series of different Forge versions
#
set -e
# MC version list
readonly -a mcversions=(
"1.12.2"
"1.16.5"
"1.18.2"
)
# Forge version dictionary (we only support one version per)
readonly -A forgeversions=(
["1.12.2"]="14.23.5.2855"
["1.16.5"]="36.2.35"
["1.18.2"]="40.1.20"
)
# JRE versions (in the form of Alpine packages)
readonly -A jreversions=(
["1.12.2"]="openjdk8-jre"
["1.16.5"]="openjdk11-jre"
["1.18.2"]="openjdk11-jre"
)
# Build images
docker buildx create --use
for mc in ${mcversions[@]}; do
forge="${forgeversions[$mc]}"
jre="${jreversions[$mc]}"
CI_HUB_USERNAME="${CI_HUB_USERNAME:=rehashedsalt}"
CI_PROJECT_NAME="${CI_PROJECT_NAME:=minecraft-forge}"
tag="$CI_HUB_USERNAME/$CI_PROJECT_NAME:$mc-${CI_COMMIT_REF_NAME:=bleeding}"
echo "Building image..."
echo " Minecraft: $mc"
echo " Forge: $forge"
echo " JRE: $jre"
echo " Ref: $CI_COMMIT_REF_NAME"
echo "Dockerhub tag: $tag"
# --no-cache is required for clean builds
docker buildx build \
--build-arg MINECRAFT_VERSION="$mc" \
--build-arg FORGE_VERSION="$forge" \
--build-arg JRE_VERSION="$jre" \
--no-cache \
--platform linux/amd64 \
--progress plain \
--tag "$tag" \
--push \
.
done
docker images

52
server.properties Normal file
View File

@@ -0,0 +1,52 @@
#Minecraft server properties
#Fri Apr 09 16:05:21 CDT 2021
allow-flight=true
allow-nether=true
broadcast-console-to-ops=true
broadcast-rcon-to-ops=true
difficulty=hard
enable-command-block=true
enable-jmx-monitoring=false
enable-query=false
enable-rcon=false
enable-status=true
enforce-whitelist=false
entity-broadcast-range-percentage=100
force-gamemode=false
function-permission-level=2
gamemode=survival
generate-structures=true
generator-settings=
hardcore=false
level-name=world
level-seed=
level-type=default
max-build-height=256
max-players=20
max-tick-time=60000
max-world-size=29999984
motd=A Minecraft Server
network-compression-threshold=256
online-mode=true
op-permission-level=4
player-idle-timeout=0
prevent-proxy-connections=false
pvp=true
query.port=25565
rate-limit=0
rcon.password=
rcon.port=25575
resource-pack=
resource-pack-sha1=
server-ip=
server-port=25565
snooper-enabled=true
spawn-animals=true
spawn-monsters=true
spawn-npcs=true
spawn-protection=0
sync-chunk-writes=true
text-filtering-config=
use-native-transport=true
view-distance=10
white-list=false

62
start-server.sh Executable file
View File

@@ -0,0 +1,62 @@
#! /bin/bash
#
# start-server.sh
# Copyright (C) 2021 Vintage Salt <rehashedsalt@cock.li>
#
# Distributed under terms of the MIT license.
#
set -e
# Download and extract a pack zip, if one is provided
if [ -n "$FORGE_PACK_ZIP" ]; then
echo "Downloading pack: $FORGE_PACK_ZIP"
tmpdir="$(mktemp -d)"
pushd "$tmpdir" > /dev/null 2>&1
curl -L "$FORGE_PACK_ZIP" -o pack.zip
unzip -q pack.zip
ls -alh
directory="$(find . -type d -iname "mods" -execdir pwd \; | sort -n | head -n 1)"
if [ -z "$directory" ]; then
echo "Unable to find mods directory"
else
echo "Found modpack directory: $directory"
fi
echo "Syncing content to /minecraft"
rsync --no-perms --no-owner --no-group --ignore-existing "$directory"/ /minecraft/
popd > /dev/null 2>&1
fi
# Then also download and extract a config repo, if one exists
if [ -n "$CONFIG_REPO" ]; then
echo "Downloading config repo: $CONFIG_REPO"
tmpdir="$(mktemp -d)"
pushd "$tmpdir" > /dev/null 2>&1
git clone "$CONFIG_REPO" .
rm -rf .git
rsync -av --delete ./ /minecraft/
popd > /dev/null 2>&1
fi
# Entrypoint will be server.jar
args="-jar server.jar nogui"
# Memory configuration
[ -n "$JRE_XMX" ] && args="-Xmx$JRE_XMX $args"
[ -n "$JRE_XMS" ] && args="-Xms$JRE_XMS $args"
[ -n "$ARGS" ] && args="$ARGS $args"
# Debugging info
java -version
echo "Invoking java with args: $args"
echo
echo "To see the server console, execute this command in the container:"
echo " screen -r minecraft"
# Start 'er up
cleanup() {
screen -p 0 -S minecraft -X stuff save-all^M
screen -p 0 -S minecraft -X stuff stop^M
}
trap cleanup EXIT
screen -DmS minecraft java $args