Compare commits
44 Commits
8a78fd604a
...
master
Author | SHA1 | Date | |
---|---|---|---|
bed8684352 | |||
58e34860fd | |||
8d2c901978 | |||
07c8bfd165 | |||
30802403cc | |||
bdbcebf366 | |||
e48fa26b5a | |||
e057c808a8 | |||
1999a0c0d0 | |||
59a75d1d3e | |||
eca3af7ffb | |||
533ceb2c2e | |||
01d9af75f0 | |||
c9d54cc46d | |||
025d88f7e0 | |||
a107b4b76e | |||
d410061076 | |||
2a860d745d | |||
e655849b38 | |||
904bd4ea78 | |||
322b6f359d | |||
4236f531da | |||
76f8fc6644 | |||
c480cd4abd | |||
f62c82e61a | |||
18994698db | |||
614818ba04 | |||
a35c565148 | |||
6dfd52c7d9 | |||
b4fc6a2654 | |||
7879f3b5e4 | |||
2e03a1faf8 | |||
bd2041a886 | |||
82715dcd5b | |||
62c4ef86af | |||
2fba83fd15 | |||
c50a4b4176 | |||
60943d2f82 | |||
c7328f43c2 | |||
0dd98315e5 | |||
5be6e30444 | |||
ed6fc1af16 | |||
df3c6166ac | |||
7bd0953dad |
@@ -3,3 +3,4 @@
|
||||
.gitignore
|
||||
.gitlab-ci.yml
|
||||
README.md
|
||||
build.sh
|
||||
|
@@ -10,14 +10,13 @@ variables:
|
||||
CI_PROJECT_NAME: minecraft-forge
|
||||
stages:
|
||||
- build
|
||||
# - test
|
||||
- push
|
||||
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
|
||||
|
||||
@@ -25,43 +24,4 @@ after_script:
|
||||
Build:
|
||||
stage: build
|
||||
script:
|
||||
- docker pull $CI_HUB_USERNAME/$CI_PROJECT_NAME:latest || true
|
||||
- docker buildx create --use
|
||||
- >
|
||||
docker buildx build
|
||||
--pull
|
||||
--platform linux/amd64
|
||||
--cache-from $CI_HUB_USERNAME/$CI_PROJECT_NAME:latest
|
||||
--tag $CI_HUB_USERNAME/$CI_PROJECT_NAME:$CI_COMMIT_SHORT_SHA
|
||||
--push
|
||||
.
|
||||
- docker images
|
||||
|
||||
# PUSH
|
||||
Push_When_Tag:
|
||||
stage: push
|
||||
only:
|
||||
- tags
|
||||
script:
|
||||
- docker pull $CI_HUB_USERNAME/$CI_PROJECT_NAME:$CI_COMMIT_SHORT_SHA
|
||||
- >
|
||||
docker tag
|
||||
$CI_HUB_USERNAME/$CI_PROJECT_NAME:$CI_COMMIT_SHORT_SHA
|
||||
$CI_HUB_USERNAME/$CI_PROJECT_NAME:$CI_COMMIT_REF_NAME
|
||||
- >
|
||||
docker tag
|
||||
$CI_HUB_USERNAME/$CI_PROJECT_NAME:$CI_COMMIT_SHORT_SHA
|
||||
$CI_HUB_USERNAME/$CI_PROJECT_NAME:latest
|
||||
- docker images
|
||||
- docker push $CI_HUB_USERNAME/$CI_PROJECT_NAME:$CI_COMMIT_REF_NAME
|
||||
- docker push $CI_HUB_USERNAME/$CI_PROJECT_NAME:latest
|
||||
Push_Bleeding:
|
||||
stage: push
|
||||
script:
|
||||
- docker pull $CI_HUB_USERNAME/$CI_PROJECT_NAME:$CI_COMMIT_SHORT_SHA
|
||||
- >
|
||||
docker tag
|
||||
$CI_HUB_USERNAME/$CI_PROJECT_NAME:$CI_COMMIT_SHORT_SHA
|
||||
$CI_HUB_USERNAME/$CI_PROJECT_NAME:bleeding
|
||||
- docker images
|
||||
- docker push $CI_HUB_USERNAME/$CI_PROJECT_NAME:bleeding
|
||||
- bash build.sh
|
||||
|
40
Dockerfile
40
Dockerfile
@@ -1,24 +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
|
||||
|
||||
# Args
|
||||
ARG MINECRAFT_VERSION="1.16.5"
|
||||
ARG FORGE_VERSION="36.1.4"
|
||||
# Use all of our arguments
|
||||
ARG MINECRAFT_VERSION
|
||||
ARG FORGE_VERSION
|
||||
ARG JRE_VERSION
|
||||
|
||||
# The actual setup work
|
||||
# Build us up the basics of the Minecraft server environment
|
||||
COPY start-server.sh /minecraft/start-server.sh
|
||||
WORKDIR /minecraft
|
||||
RUN apk add curl openjdk8-jre &&\
|
||||
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
|
||||
|
||||
# The second stage is the actual container
|
||||
FROM openjdk:8
|
||||
RUN apt-get update && apt-get install rsync -y
|
||||
# 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
7
LICENSE
Normal 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.
|
27
README.md
27
README.md
@@ -7,10 +7,30 @@ A Dockerfile and some assorted scripts to build a Minecraft Forge server contain
|
||||
Deploy as expected:
|
||||
|
||||
```bash
|
||||
docker run -p 25565:25565 rehashedsalt/minecraft-forge
|
||||
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 latest stable is.
|
||||
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
|
||||
|
||||
@@ -29,6 +49,7 @@ 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
|
||||
@@ -37,6 +58,8 @@ 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:
|
||||
|
54
build.sh
Executable file
54
build.sh
Executable 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
|
@@ -1,4 +1,4 @@
|
||||
#! /bin/sh
|
||||
#! /bin/bash
|
||||
#
|
||||
# start-server.sh
|
||||
# Copyright (C) 2021 Vintage Salt <rehashedsalt@cock.li>
|
||||
@@ -13,10 +13,27 @@ if [ -n "$FORGE_PACK_ZIP" ]; then
|
||||
tmpdir="$(mktemp -d)"
|
||||
pushd "$tmpdir" > /dev/null 2>&1
|
||||
curl -L "$FORGE_PACK_ZIP" -o pack.zip
|
||||
unzip pack.zip
|
||||
unzip -q pack.zip
|
||||
ls -alh
|
||||
directory="$(find . -type d -iname "mods" -execdir pwd \; | sort -n | head -n 1)"
|
||||
echo "Found modpack directory: $directory"
|
||||
rsync -av "$directory"/ /minecraft/
|
||||
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
|
||||
|
||||
@@ -31,7 +48,15 @@ args="-jar server.jar nogui"
|
||||
# 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
|
||||
java $args
|
||||
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
|
||||
|
||||
|
Reference in New Issue
Block a user