diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..6b8710a --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +.git diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ae60e0d --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +# ignore swp files +*.sw[g-p] + +# ignore .env file +.env + +# ignore jar files +*.jar diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..18612f6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +FROM openjdk:8-jdk-alpine + +LABEL author="ViViV_" maintainer="sysadmin@whiteshield.ch" +LABEL author="thehuntedpie" maintainer="thehuntedpie@gmail.com" + +EXPOSE 6567/TCP +EXPOSE 6567/UDP + +RUN apk add --update --no-cache curl ca-certificates openssl git \ + tar bash +RUN apk add --update --no-cache sqlite + +RUN adduser -D -h /var/lib/mindustry mindustry + +COPY Mindustry-server-4.0-alpha-56.jar /usr/local/share/mindustry/server.jar + +USER root + +WORKDIR /var/lib/mindustry + +VOLUME /var/lib/mindustry/.mindustry + +COPY ./docker-entrypoint.sh / + +ENTRYPOINT ["/docker-entrypoint.sh"] +CMD ["host"] diff --git a/README.md b/README.md index 1960ab9..dd61784 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,25 @@ Just download docker-compose.yml Host Server : `docker-compose up -d` -Attach terminal `docker attach ${CONTAINER_NAME}` - ## Docker Commands -Host Server : `docker run --name mindustry -ti -p 6567:6567/tcp -p 6567:6567/udp viviv/mindustry` +Host Server : `docker run --name mindustry -i -p 6567:6567/tcp -p 6567:6567/udp viviv/mindustry` + +# Manage Mindustry Console + +## Attach Console +Attach terminal with `docker attach --sig-proxy=false mindustry_server` + +ATTENTION! The terminal will not have any indicators that you have connected to the console. Just type help to get started. + +### Detach Console +To detach the console type Ctrl-C . The server should remain running. + +### Console Commands +The script 'console.sh' lets you run commands in the console from outside the container with output. + +usage: `./console.sh status` +WARNING! This script seems to perform well but is not very well tested. Use with caution! ### Enjoy !! diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..eee3ea5 --- /dev/null +++ b/build.sh @@ -0,0 +1,2 @@ +#!/bin/bash +docker-compose -f docker-compose.build.yml build mindustry diff --git a/console.sh b/console.sh new file mode 100755 index 0000000..5771140 --- /dev/null +++ b/console.sh @@ -0,0 +1,18 @@ +#!/bin/bash +COMMAND=${@}; +CONTAINER=mindustry_server; +DATE=`date -Iseconds`; + +echo "$COMMAND" | docker attach $CONTAINER & +PID=$$ + +# reasonably speaking, logs dont happen til action is done +while [ "$LOGS" == "" ]; do + LOGS=$(docker logs --since "$DATE" $CONTAINER) +done + +# sleep just in case stuff is still going on +sleep 1 + +echo "$LOGS" +{kill $PID} 2>/dev/null diff --git a/deploy.sh b/deploy.sh new file mode 100755 index 0000000..69d0310 --- /dev/null +++ b/deploy.sh @@ -0,0 +1,7 @@ +#!/bin/bash +# COMPOSE_PROJECT_NAME should be a unique string for this deployment. Otherwise, if you run multiple deployments, docker-compose down may take down a previous deployment with the same COMPOSE_PROJECT_NAME or parent folder name + +COMPOSE_PROJECT_NAME=mindustry-server + +docker-compose down +docker-compose up -d diff --git a/docker-compose.build.yml b/docker-compose.build.yml new file mode 100644 index 0000000..ede2dd0 --- /dev/null +++ b/docker-compose.build.yml @@ -0,0 +1,7 @@ +version: '3.1' + +services: + mindustry: + build: . + image: thehuntedpie/mindustry:4.0-alpha-56 + diff --git a/docker-compose.yml b/docker-compose.yml index c8b54bf..16fb563 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,13 +1,19 @@ -version: '3.1' +version: "3.1" services: mindustry: - image: viviv/mindustry + image: "thehuntedpie/mindustry:4.0-alpha-56" + container_name: "mindustry_server" + hostname: "mindustry-server" ports: - - '6567:6567/tcp' - - '6567:6567/udp' - tty: true + - "6567:6567/tcp" #host-port:internal-port + - "6567:6567/udp" + environment: + - "JAVA_OPTS=-Xms1G -Xmx2G" #set memory limits + command: + - "load 1,host" # load save 1 and then host. see help for options + tty: false stdin_open: true restart: always volumes: - - "/data/mindustry:/root/.mindustry" + - "/data/mindustry:/var/lib/mindustry/.mindustry" diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100755 index 0000000..c43e15e --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,8 @@ +#!/bin/bash -x +Server_Args=$1 + +# change ownership of home directory +chown mindustry:mindustry -R ~mindustry + +# run server as non-elevated user +su mindustry bash -c 'java -jar /usr/local/share/mindustry/server.jar '"${Server_Args}" diff --git a/dockerfile b/dockerfile deleted file mode 100644 index 25b1683..0000000 --- a/dockerfile +++ /dev/null @@ -1,21 +0,0 @@ -FROM openjdk:8-jdk-alpine - -LABEL author="ViViV_" maintainer="sysadmin@whiteshield.ch" - -EXPOSE 6567/TCP -EXPOSE 6567/UDP - -RUN apk add --update --no-cache curl ca-certificates openssl git tar bash sqlite \ - && adduser -D -h /home/container container - -ADD . /home/container/ -USER root -ENV USER=root HOME=/home/container - -WORKDIR /home/container - -VOLUME /data/mindustry - -COPY ./entrypoint.sh /entrypoint.sh - -CMD ["/bin/bash", "/entrypoint.sh"] diff --git a/entrypoint.sh b/entrypoint.sh deleted file mode 100644 index 0ba4779..0000000 --- a/entrypoint.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -su container -java -jar -Xms1G -Xmx2G Mindustry-server-4.0-alpha-56.jar host diff --git a/push.sh b/push.sh new file mode 100755 index 0000000..85b8798 --- /dev/null +++ b/push.sh @@ -0,0 +1,2 @@ +#!/bin/bash +docker-compose -f docker-compose.build.yml push mindustry