Compare commits

...

1 Commits

Author SHA1 Message Date
082282ebe4 testing 2024-05-17 03:00:34 -04:00
9 changed files with 187 additions and 116 deletions

View File

@ -1,85 +0,0 @@
FROM debian:stable-slim
ARG VERSION=latest
ARG JAVA_VERSION=latest
ENV DEBIAN_FRONTEND=noninteractive
# Create minecraft user
RUN groupadd -g 1000 minecraft && \
useradd -m -u 1000 -g 1000 -d /app minecraft
# Install scripting dependencies
RUN apt-get update && \
apt-get install -y curl gpg jq procps screen strace && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Eclipse Adoptium DEB installer package
RUN set -ux && \
# Download the Eclipse Adoptium GPG key
curl -s https://packages.adoptium.net/artifactory/api/gpg/key/public \
| gpg --dearmor | tee /etc/apt/trusted.gpg.d/adoptium.gpg > /dev/null && \
# Configure the Eclipse Adoptium apt repository
VERSION_CODENAME="$(awk -F= '/^VERSION_CODENAME/{print $2}' /etc/os-release)" && \
echo "deb https://packages.adoptium.net/artifactory/deb $VERSION_CODENAME main" \
| tee /etc/apt/sources.list.d/adoptium.list
# Install Adoptium Temurin (OpenJDK Distribution)
RUN set -ux && \
# Grab latest LTS version if not specified
if [ "$JAVA_VERSION" = "latest" ]; then \
JAVA_VERSION="$( \
curl -s https://api.adoptium.net/v3/info/available_releases \
| jq '.most_recent_lts' \
)"; \
fi && \
# Install the Temurin version
apt-get update && \
apt-get install -y "temurin-${JAVA_VERSION}-jre" && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Download files and run as user
USER minecraft
WORKDIR /app
# Download and verify sha1sum for server.jar
RUN set -ux && \
# Grab latest version if not specified
if [ "$VERSION" = "latest" ]; then \
VERSION="$( \
curl -s https://launchermeta.mojang.com/mc/game/version_manifest.json \
| jq -r '.latest.release' \
)"; \
fi && \
# Get server.jar based on $VERSION
curl -s https://launchermeta.mojang.com/mc/game/version_manifest.json \
| jq -r --arg id "$VERSION" '.versions[] | select(.id == $id) | .url' \
| xargs curl -s | jq -r '.downloads.server' | tee "/tmp/dl.json" \
| jq -r '.url' | xargs curl -s -o server.jar && \
# Get SHA1 hash of server.jar and compare
SHA1="$(sha1sum server.jar | awk '{print $1}')" && \
EXPECTED="$(jq -r .sha1 /tmp/dl.json)"; rm /tmp/dl.json && \
if [ ! "$SHA1" = "$EXPECTED" ]; then \
echo "[ERROR] SHA1=\"$SHA1\" expected \"$EXPECTED\""; \
exit 1; \
fi
# Generate initial settings
RUN java -jar server.jar --initSettings --nogui
# Back to root to copy the entrypoint in
USER root
WORKDIR /app
# Copy in entrypoint script
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh
# Run app as minecraft user
USER minecraft
WORKDIR /app
# Expose port and run entrypoint script
EXPOSE 25565
ENTRYPOINT ["entrypoint.sh"]

View File

@ -1,17 +1,23 @@
CONTAINER = minecraft-minecraft-1 DOCKER_COMPOSE_COMMAND = docker compose -f docker-compose.build.yml
.PHONY: default build clean install PRUNE_IMAGES = \
default: build localhost/minecraft \
localhost/minecraft-base \
localhost/minecraft-spigot
build: .PHONY: all base vanilla spigot
docker compose build default: vanilla
all: vanilla spigot
base:
$(DOCKER_COMPOSE_COMMAND) build minecraft-base
vanilla: base
$(DOCKER_COMPOSE_COMMAND) build minecraft-vanilla
spigot: base
$(DOCKER_COMPOSE_COMMAND) build minecraft-spigot
clean: clean:
rm -f screenlog.0 docker image rm $(PRUNE_IMAGES) || true
docker compose down --rmi all
docker builder prune -f docker builder prune -f
install: build
touch screenlog.0
docker compose up -d && \
docker logs -f $(CONTAINER)

36
docker-compose.build.yml Normal file
View File

@ -0,0 +1,36 @@
services:
minecraft-base:
build:
context: .
dockerfile: ./dockerfiles/Dockerfile.base
args:
JAVA_VERSION: ${JAVA_VERSION:-latest}
image: ${BASE_IMAGE:-localhost/minecraft-base}:${BASE_TAG:-latest}
minecraft-vanilla:
build:
context: .
dockerfile: ./dockerfiles/Dockerfile.vanilla
args:
VERSION: ${VERSION:-latest}
image: ${IMAGE:-localhost/minecraft}:${TAG:-latest}
depends_on:
- minecraft-base
environment:
EULA: "${EULA:-false}"
DEBUG: "${DEBUG:-false}"
JVM_OPTS: "${JAVA_OPTS:--Xms1G -Xmx2G}"
minecraft-spigot:
build:
context: .
dockerfile: ./dockerfiles/Dockerfile.spigot
args:
VERSION: ${MINECRAFT_VERSION:-latest}
image: ${SPIGOT_IMAGE:-localhost/minecraft}:${SPIGOT_TAG:-spigot-latest}
depends_on:
- minecraft-base
environment:
EULA: "${EULA:-false}"
DEBUG: "${DEBUG:-false}"
JVM_OPTS: "${JAVA_OPTS:--Xms1G -Xmx2G}"

View File

@ -1,19 +0,0 @@
services:
minecraft:
build:
context: .
dockerfile: Dockerfile
args:
VERSION: ${VERSION:-latest}
JAVA_VERSION: ${JAVA_VERSION:-latest}
image: ${IMAGE:-minecraft}:${TAG:-latest}
ports:
- "0.0.0.0:25565:25565"
environment:
EULA: "${EULA:-false}"
DEBUG: "${DEBUG:-false}"
JVM_OPTS: "${JAVA_OPTS:--Xms1G -Xmx2G}"
SETTINGS_gamemode: "${GAMEMODE:-survival}"
SETTINGS_hardcore: "${HARDCORE:-false}"
SETTINGS_motd: "${MOTD:-A Minecraft Server}"
SETTINGS_pvp: "${PVP:-true}"

View File

@ -0,0 +1,39 @@
FROM debian:stable-slim
ARG JAVA_VERSION=latest
ENV DEBIAN_FRONTEND=noninteractive
# Create minecraft user
RUN groupadd -g 1000 minecraft && \
useradd -m -u 1000 -g 1000 -d /app minecraft
# Install scripting dependencies
RUN apt-get update && \
apt-get install -y curl git gpg jq procps screen strace && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Eclipse Adoptium DEB installer package
RUN set -ux && \
# Download the Eclipse Adoptium GPG key
curl -s https://packages.adoptium.net/artifactory/api/gpg/key/public \
| gpg --dearmor | tee /etc/apt/trusted.gpg.d/adoptium.gpg > /dev/null && \
# Configure the Eclipse Adoptium apt repository
VERSION_CODENAME="$(awk -F= '/^VERSION_CODENAME/{print $2}' /etc/os-release)" && \
echo "deb https://packages.adoptium.net/artifactory/deb $VERSION_CODENAME main" \
| tee /etc/apt/sources.list.d/adoptium.list
# Install Adoptium Temurin (OpenJDK Distribution)
RUN set -ux && \
# Grab latest LTS version if not specified
if [ "$JAVA_VERSION" = "latest" ]; then \
JAVA_VERSION="$( \
curl -s https://api.adoptium.net/v3/info/available_releases \
| jq '.most_recent_lts' \
)"; \
fi && \
# Install the Temurin version
apt-get update && \
apt-get install -y "temurin-${JAVA_VERSION}-jre" && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

View File

View File

View File

@ -0,0 +1,45 @@
FROM "${BASE_IMAGE:-localhost/minecraft-base}":"${BASE_TAG:-latest}"
# Minecraft version
ARG VERSION=latest
# SpigotMC BuildTools URL
ARG BASE_URL="https://hub.spigotmc.org/jenkins/job/BuildTools/"
ARG ARTIFACT_PATH="lastSuccessfulBuild/artifact/target/BuildTools.jar"
# Download files and run as user
USER minecraft
WORKDIR /app
# Download and build Spigot using BuildTools
RUN set -ux && \
# Grab latest version if not specified
if [ "$VERSION" = "latest" ]; then \
VERSION="$( \
curl -s https://launchermeta.mojang.com/mc/game/version_manifest.json \
| jq -r '.latest.release' \
)"; \
fi && \
# Download BuildTools.jar
curl -s -o BuildTools.jar "${BASE_URL}${ARTIFACT_PATH}" && \
## Run BuildTools to build specified version
java -jar BuildTools.jar --rev "$VERSION" --compile SPIGOT
# Generate initial settings
RUN java -jar server.jar --initSettings --nogui
# Back to root to copy the entrypoint in
USER root
WORKDIR /app
# Copy in entrypoint script
COPY ../entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh
# Run app as minecraft user
USER minecraft
WORKDIR /app
# Expose port and run entrypoint script
EXPOSE 25565
ENTRYPOINT ["entrypoint.sh"]

View File

@ -0,0 +1,49 @@
FROM "${BASE_IMAGE:-localhost/minecraft-base}":"${BASE_TAG:-latest}"
# Minecraft version
ARG VERSION=latest
# Download files and run as user
USER minecraft
WORKDIR /app
# Download and verify sha1sum for server.jar
RUN set -ux && \
# Grab latest version if not specified
if [ "$VERSION" = "latest" ]; then \
VERSION="$( \
curl -s https://launchermeta.mojang.com/mc/game/version_manifest.json \
| jq -r '.latest.release' \
)"; \
fi && \
# Get server.jar based on $VERSION
curl -s https://launchermeta.mojang.com/mc/game/version_manifest.json \
| jq -r --arg id "$VERSION" '.versions[] | select(.id == $id) | .url' \
| xargs curl -s | jq -r '.downloads.server' | tee "/tmp/dl.json" \
| jq -r '.url' | xargs curl -s -o server.jar && \
# Get SHA1 hash of server.jar and compare
SHA1="$(sha1sum server.jar | awk '{print $1}')" && \
EXPECTED="$(jq -r .sha1 /tmp/dl.json)"; rm /tmp/dl.json && \
if [ ! "$SHA1" = "$EXPECTED" ]; then \
echo "[ERROR] SHA1=\"$SHA1\" expected \"$EXPECTED\""; \
exit 1; \
fi
# Generate initial settings
RUN java -jar server.jar --initSettings --nogui
# Back to root to copy the entrypoint in
USER root
WORKDIR /app
# Copy in entrypoint script
COPY ../entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh
# Run app as minecraft user
USER minecraft
WORKDIR /app
# Expose port and run entrypoint script
EXPOSE 25565
ENTRYPOINT ["entrypoint.sh"]