inital commit

This commit is contained in:
Andrei Stoica 2020-04-22 18:16:12 -04:00
commit f8cecdc00c
5 changed files with 87 additions and 0 deletions

13
Makefile Normal file
View File

@ -0,0 +1,13 @@
WORKING_DIR := $(shell pwd)
test:
docker run -it --name mc-test -p 25565:25565 --rm -v $(WORKING_DIR)/spigot:/mc \
-w /mc openjdk java -Xms1G -Xmx4G -server -jar spigot.jar nogui
up:
systemctl start mc-server.service
down:
systemctl stop mc-server.service
include build/Makefile

27
README.md Normal file
View File

@ -0,0 +1,27 @@
# Running a Minecraft server (spigot) inside of docker
This is a all in one setup to run a Spigot server using docker. It also includes
a systemd unit file for setting it up to run automaticaly.
## Building
> make build-latest
- builds the latest version of of spigot
## deploying
> make deploy
- copies the latest build into the running directory
## Running
> make test
- run a test instance of the server
### Systemd unit file (mc-server.service)
1. assumes the working directory to be `/mc`, change it on line 7
2. copy to systemd config folder (/etc/systemd/system/ on Ubuntu)
> make up
- start the systemd service
> make down
- top the systemd service

9
build/Dockerfile Normal file
View File

@ -0,0 +1,9 @@
FROM openjdk:9-jdk-slim
RUN apt-get update && apt-get install -y --no-install-recommends \
git \
openssh-client \
procps \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*

25
build/Makefile Normal file
View File

@ -0,0 +1,25 @@
LATEST := $(shell ls -rt build/spigot*.jar | tail -1)
deploy: build-latest spigot
cp $(LATEST) spigot/spigot.jar
deploy-1.15.2: build/spigot-1.15.2.jar spigot
cp build/spigot-1.15.2.jar spigot/spigot.jar
build-latest: build-image
docker run -it --rm -v $(WORKING_DIR)/build:/mc -w /mc java-build java -cp /mc \
-jar BuildTools.jar
build/spigot-1.15.2.jar: build-image
docker run -it --rm -v $(WORKING_DIR)/build:/mc -w /mc java-build java -cp /mc \
-jar BuildTools.jar --rev 1.15.2
build-image: build/BuildTools.jar
docker build -t java-build build/
build/BuildTools.jar:
curl -o build/BuildTools.jar \
https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar
spigot:
mkdir spigot

13
mc-server.service Normal file
View File

@ -0,0 +1,13 @@
[Unit]
Description=Minecraft Server
After=docker.service
Requires=docker.service
[Service]
Environment="MC_DIR=/mc"
Restart=Always
ExecStart=/usr/bin/docker run -t --name mc -p 25565:25565 --rm -v ${MC_DIR}/spigot:/mc -w /mc openjdk java -Xms1G -Xmx4G -server -jar spigot.jar nogui
ExecStop=/usr/bin/docker container stop mc
[Install]
WantedBy=multi-user.target