misukisu commited on
Commit
d7f1cb3
·
verified ·
1 Parent(s): e0148ea

Add Minecraft Paper and playit Space

Browse files
Files changed (3) hide show
  1. Dockerfile +8 -0
  2. README.md +9 -4
  3. start.sh +20 -0
Dockerfile ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ FROM debian:bookworm-slim
2
+ ENV DEBIAN_FRONTEND=noninteractive
3
+ RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates curl wget jq openjdk-21-jre-headless python3 procps && rm -rf /var/lib/apt/lists/*
4
+ WORKDIR /app
5
+ COPY start.sh /app/start.sh
6
+ RUN chmod +x /app/start.sh
7
+ EXPOSE 7860
8
+ CMD ["/app/start.sh"]
README.md CHANGED
@@ -1,10 +1,15 @@
1
  ---
2
  title: Minecraft Server
3
- emoji: 🏃
4
- colorFrom: red
5
- colorTo: green
6
  sdk: docker
7
  pinned: false
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
1
  ---
2
  title: Minecraft Server
3
+ emoji: ⛏️
4
+ colorFrom: green
5
+ colorTo: gray
6
  sdk: docker
7
  pinned: false
8
+ app_port: 7860
9
  ---
10
 
11
+ # Minecraft Server
12
+
13
+ A small Paper Minecraft server exposed through playit.gg. The dashboard on port 7860 shows startup logs and the playit claim URL when the agent requests one.
14
+
15
+ Important: Hugging Face Spaces are ephemeral unless persistent storage is configured. Set MC_VERSION and optional PLAYIT_SECRET as Space variables/secrets as needed.
start.sh ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ set -Eeuo pipefail
3
+ mkdir -p /app/minecraft /app/logs
4
+ exec > >(tee -a /app/logs/startup.log) 2>&1
5
+ PORT="${MC_PORT:-25565}"; VERSION="${MC_VERSION:-1.21.8}"
6
+ cd /app/minecraft
7
+ if [ ! -f paper.jar ]; then build="$(curl -fsSL "https://api.papermc.io/v2/projects/paper/versions/${VERSION}" | jq -r '.builds[-1]')"; curl -fL --retry 3 -o paper.jar "https://api.papermc.io/v2/projects/paper/versions/${VERSION}/builds/${build}/downloads/paper-${VERSION}-${build}.jar"; fi
8
+ echo 'eula=true' > eula.txt
9
+ python3 - <<'PY' &
10
+ from http.server import BaseHTTPRequestHandler,HTTPServer
11
+ from pathlib import Path
12
+ class H(BaseHTTPRequestHandler):
13
+ def do_GET(self):
14
+ t=Path('/app/logs/startup.log').read_text(errors='replace')[-12000:]; b=('<html><meta http-equiv="refresh" content="5"><body><h1>Minecraft Server</h1><pre>'+t.replace('&','&amp;').replace('<','&lt;')+'</pre></body></html>').encode(); self.send_response(200); self.send_header('Content-Type','text/html'); self.send_header('Content-Length',str(len(b))); self.end_headers(); self.wfile.write(b)
15
+ def log_message(self,*a): pass
16
+ HTTPServer(('0.0.0.0',7860),H).serve_forever()
17
+ PY
18
+ if [ ! -x /usr/local/bin/playit ]; then curl -fL --retry 3 -o /usr/local/bin/playit https://github.com/playit-cloud/playit-agent/releases/latest/download/playit-linux-amd64; chmod +x /usr/local/bin/playit; fi
19
+ if [ -n "${PLAYIT_SECRET:-}" ]; then playit --secret "$PLAYIT_SECRET" >> /app/logs/startup.log 2>&1 & else playit >> /app/logs/startup.log 2>&1 & fi
20
+ java -Xms512M -Xmx${MC_MEMORY:-2G} -jar paper.jar --nogui --port "$PORT"