diff --git a/minecraft/build/Dockerfile b/minecraft/build/Dockerfile new file mode 100644 index 0000000..fe09d9e --- /dev/null +++ b/minecraft/build/Dockerfile @@ -0,0 +1,6 @@ +FROM docker.0k.io/alpine:3.18 + +RUN apk add openjdk17 && \ + mkdir /var/lib/minecraft + +WORKDIR /var/lib/minecraft \ No newline at end of file diff --git a/minecraft/hooks/init b/minecraft/hooks/init new file mode 100755 index 0000000..626db1d --- /dev/null +++ b/minecraft/hooks/init @@ -0,0 +1,25 @@ +#!/bin/bash + +## Init is run on host +## For now it is run every time the script is launched, but +## it should be launched only once after build. + +## Accessible variables are: +## - SERVICE_NAME Name of current service +## - DOCKER_BASE_IMAGE Base image from which this service might be built if any +## - SERVICE_DATASTORE Location on host of the DATASTORE of this service +## - SERVICE_CONFIGSTORE Location on host of the CONFIGSTORE of this service + + +. lib/common + +set -e + +version=$(options-get version) || exit 1 + +minecraft:init-binary "$version" + +threads=$(options-get threads) || exit 1 +mem=$(options-get mem) || exit 1 + +minecraft:init-command "$threads" "$mem" \ No newline at end of file diff --git a/minecraft/lib/common b/minecraft/lib/common new file mode 100644 index 0000000..12ea88b --- /dev/null +++ b/minecraft/lib/common @@ -0,0 +1,39 @@ +# -*- mode: shell-script -*- + + +MINECRAFT_PATH="$SERVICE_CONFIGSTORE/opt/apps/minecraft" +MINECRAFT_DATA="/var/lib/minecraft" + +minecraft:init-binary() { + local version="$1" + + MINECRAFT_BINARY="${MINECRAFT_PATH}/minecraft_server.${version}.jar" + if ! [ -f "$MINECRAFT_BINARY" ]; then + mkdir -p "${MINECRAFT_PATH}" + wget "https://docker.0k.io/downloads/minecraft_server.${version}.jar" \ + -O "$MINECRAFT_BINARY" + fi + init-config-add " +$SERVICE_NAME: + volumes: + - \"${MINECRAFT_BINARY}:${MINECRAFT_DATA}/server.jar\" +" + +} + + +minecraft:init-command() { + local threads="${1:-4}" mem="${2:-2048M}" + init-config-add " +$SERVICE_NAME: + command: + - java + - -Xmx${mem} + - -Xms${mem} + - -XX:ParallelGCThreads=${threads} + - -jar + - server.jar + - nogui +" + echo "eula=TRUE" > "$SERVICE_DATASTORE/${MINECRAFT_DATA}/eula.txt" +} \ No newline at end of file diff --git a/minecraft/metadata.yml b/minecraft/metadata.yml new file mode 100644 index 0000000..4bee9fe --- /dev/null +++ b/minecraft/metadata.yml @@ -0,0 +1,23 @@ +description: "Minecraft" +maintainer: "Valentin Lab " + +data-resources: + - /var/lib/minecraft +default-options: + version: 1.19.4 + forge: true + threads: 2 + mem: 2048M +uses: + backup: + constraint: recommended + auto: pair + solves: + backup: "Automatic regular backup" + default-options: + ## First pattern matching wins, no pattern matching includes. + ## include-patterns are checked first, then exclude-patterns + ## Patterns rules: + ## - ending / for directory + ## - '*' authorized + ## - must start with a '/', will start from $SERVICE_DATASTORE