Skip to content

Instantly share code, notes, and snippets.

@whatupdave
Created November 30, 2017 18:15
Show Gist options
  • Save whatupdave/9066571f2380b55562815a75d0020dfd to your computer and use it in GitHub Desktop.
Save whatupdave/9066571f2380b55562815a75d0020dfd to your computer and use it in GitHub Desktop.
Some game dockerfiles
FROM frolvlad/alpine-glibc
MAINTAINER Dave Newman dave@partycloud.com
RUN apk --update add bash curl xz
RUN addgroup -S -g 1000 game && \
adduser -H -S -u 1000 game && \
mkdir /data && \
chown game:game /data
ENV HOME /data
ENV SAVEFILE /data/saves/factorio_save.zip
COPY run.sh /usr/local/bin/run
RUN chmod +x /usr/local/bin/*
ENTRYPOINT ["/usr/local/bin/run"]
EXPOSE 34197/udp
USER game:game
VOLUME /data
WORKDIR /data
#!/bin/bash
set -euo pipefail
download-server () {
local url
if [ -z "${VERSION-}" ]; then
url=$(curl --silent -L https://www.factorio.com/download-headless/stable | \
grep -o -m1 "/get-download/.*/headless/linux64" | \
awk '{print "https://www.factorio.com"$1}')
else
url="https://factorio.com/get-download/$VERSION/headless/linux64"
fi
echo "----> Installing new server $url"
(
cd /data
curl --location --remote-name --remote-header-name --silent "$url"
find . -name '*.tar.xz' -exec tar xJ --strip 1 -f {} \;
find . -name '*.tar.gz' -exec tar xz --strip 1 -f {} \;
rm *.tar*
)
}
start-server () {
if [ ! -f $SAVEFILE ]; then
echo "----> Creating a new map"
/data/bin/x64/factorio --create "$SAVEFILE"
fi
local cmd="/data/bin/x64/factorio --start-server $SAVEFILE"
if [ ! -z "${BIND-}" ]; then
cmd="$cmd --bind $BIND"
fi
exec $cmd
}
# this is super fragile
if [ ! -f /data/bin/x64/factorio ]; then
download-server
fi
if [ $# -eq 0 ]; then
start-server
fi
exec "$@"
FROM openjdk:8-alpine
MAINTAINER Dave Newman dave@partycloud.com
RUN apk --no-cache add \
bash \
ca-certificates \
curl \
jq \
openssl \
wget && \
update-ca-certificates
RUN addgroup -S -g 1000 game && \
adduser -H -S -u 1000 game && \
mkdir /data && \
chown game:game /data
COPY run.sh /usr/local/bin/run
RUN chmod +x /usr/local/bin/*
ENTRYPOINT ["/usr/local/bin/run"]
EXPOSE 25565
USER game:game
VOLUME /data
WORKDIR /data
#!/bin/bash
set -eu
install-vanilla() {
MC_VER=$(curl --silent https://launchermeta.mojang.com/mc/game/version_manifest.json | jq -r '.latest.release')
echo "--- install minecraft vanilla $MC_VER ---"
curl "https://s3.amazonaws.com/Minecraft.Download/versions/$MC_VER/minecraft_server.$MC_VER.jar" > server.jar
}
install-custom() {
echo "--- install minecraft modpack $INSTALL ---"
curl -Lo server.zip "$INSTALL"
unzip server.zip
rm server.zip
}
install-server() {
if [[ ! -f server.jar && ! -f ServerStart.sh ]]; then
if [ ! -z "${INSTALL-}" ]; then
install-custom
else
install-vanilla
fi
echo "eula=true" > eula.txt
fi
}
start-server() {
local cmd="java -jar server.jar nogui"
if [ -f ServerStart.sh ]; then
chmod +x ServerStart.sh
cmd="./ServerStart.sh"
fi
exec $cmd
}
if [ $# -eq 0 ]; then
install-server
start-server
fi
exec "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment