File size: 4,915 Bytes
edc0020
 
179ea4e
c7bb537
f4ef69e
 
 
 
c7bb537
 
 
ed6ec09
 
f4ef69e
 
6669e6b
179ea4e
edc0020
 
 
 
 
 
 
 
1d4fb1d
b987181
edc0020
 
3d8a7d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4f7f53c
3d8a7d1
4f7f53c
 
1ffc2a5
4f7f53c
 
 
 
3d8a7d1
 
 
 
 
ed6ec09
1d4fb1d
 
 
 
 
 
 
ed6ec09
1d4fb1d
edc0020
 
3d8a7d1
 
 
48a7b11
edc0020
 
 
48a7b11
7936332
50835d0
ed6ec09
3d8a7d1
 
edc0020
c35ed79
f4ef69e
 
 
c7bb537
9b5b7b7
edc0020
179ea4e
1d4fb1d
edc0020
 
4b4f468
edc0020
4b4f468
edc0020
 
 
 
 
 
 
 
 
 
 
 
c7bb537
edc0020
44a1064
ed6ec09
edc0020
6b9b587
3d8a7d1
6b9b587
 
 
 
edc0020
 
 
6b9b587
3d8a7d1
6b9b587
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
FROM python:3.11-slim-bookworm

# -----------------------------------------------------
# Set Environment Variables
# -----------------------------------------------------
ENV PYTHONUNBUFFERED=1
ENV MINECRAFT_SERVER_DIR=/app/minecraft_server
ENV SERVER_JAR_NAME=server.jar
# NOTE: Adjust these memory values if your environment has more or less RAM.
ENV MAX_MEMORY=10G 
ENV MIN_MEMORY=1G
ENV WEB_PORT=7860
ENV SERVER_PORT=25565

# -----------------------------------------------------
# 1. Install core system dependencies
# -----------------------------------------------------
RUN apt-get update && apt-get install -y \
    curl \
    wget \
    unzip \
    zip \
    screen \
    procps \
    net-tools \
    ca-certificates \
    file \
    && rm -rf /var/lib/apt/lists/*

# -----------------------------------------------------
# 2. CRITICAL FIX: Create mcuser and Directories/Permissions
#    This must be done before the 'chown' commands in the playit block.
# -----------------------------------------------------
# Create app user and directories
RUN groupadd -r mcuser -g 1000 && \
    useradd -r -u 1000 -g mcuser mcuser

WORKDIR /app

# Create necessary directories
RUN mkdir -p ${MINECRAFT_SERVER_DIR} \
    ${MINECRAFT_SERVER_DIR}/mods \
    ${MINECRAFT_SERVER_DIR}/world \
    ${MINECRAFT_SERVER_DIR}/config \
    ${MINECRAFT_SERVER_DIR}/logs \
    /app/backups \
    /app/uploads \
    /app/static \
    /app/templates \
    && chown -R mcuser:mcuser /app

# -----------------------------------------------------
# 3. Install PlayIt.gg Agent (DIRECT DOWNLOAD & VERIFICATION) 🔑
# -----------------------------------------------------
USER root
# We keep curl install/removal here for efficiency if it wasn't installed above
RUN apt-get update && \
    apt-get install -y curl --no-install-recommends && \
    curl -L -o /usr/local/bin/playit https://github.com/playit-cloud/playit-agent/releases/latest/download/playit-linux-x86-64 && \    chmod +x /usr/local/bin/playit && \
    chown mcuser:mcuser /usr/local/bin/playit && \
    apt-get remove -y curl && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

# -----------------------------------------------------
# 4. Install Java (Temurin-21)
# -----------------------------------------------------
# Note: Since curl is already installed, the first line of the original Java install is redundant.
RUN apt-get update && apt-get install -y gnupg dirmngr && rm -rf /var/lib/apt/lists/*
RUN mkdir -p /etc/apt/keyrings && \
    wget -O - https://packages.adoptium.net/artifactory/api/gpg/key/public | tee /etc/apt/keyrings/adoptium.asc && \
    echo "deb [signed-by=/etc/apt/keyrings/adoptium.asc] https://packages.adoptium.net/artifactory/deb $(awk -F= '/^VERSION_CODENAME/{print$2}' /etc/os-release) main" | tee /etc/apt/sources.list.d/adoptium.list && \
    apt-get update && \
    apt-get install -y temurin-21-jdk && \
    rm -rf /var/lib/apt/lists/*

# Set Java environment
ENV JAVA_HOME=/usr/lib/jvm/temurin-21-jdk-amd64
ENV PATH="${JAVA_HOME}/bin:${PATH}"

# -----------------------------------------------------
# 5. Install Python Dependencies
# -----------------------------------------------------
# Copy requirements first for caching
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Force a rebuild when the installation changes
ENV CACHE_BUSTER=20251207_v33

# Copy application files (including the server.jar and other files)
# The CHOWN is redundant here since the final chown -R /app was done earlier
COPY . .

# --- Minecraft Setup ---
# Uses ENV vars for cleaner execution
RUN cp /app/${SERVER_JAR_NAME} ${MINECRAFT_SERVER_DIR}/${SERVER_JAR_NAME} && \
    echo "eula=true" > ${MINECRAFT_SERVER_DIR}/eula.txt && \
    chown -R mcuser:mcuser ${MINECRAFT_SERVER_DIR}
# --- End Setup ---

# Create default server.properties
RUN printf 'server-port=25565\n\
max-players=2\n\
online-mode=false\n\
enable-command-block=false\n\
spawn-protection=0\n\
view-distance=6\n\
simulation-distance=8\n\
motd=\\u00A7b\\u00A7lHF Spaces MC Server\\u00A7r - \\u00A7aOnline\n\
difficulty=normal\n\
gamemode=survival\n\
level-name=world\n\
pvp=true\n\
allow-flight=true\n\
white-list=false\n\
enforce-whitelist=false\n\
max-tick-time=60000\n\
network-compression-threshold=256\n\
enable-status=true\n\
enable-query=false\n' > ${MINECRAFT_SERVER_DIR}/server.properties

# Expose ports (7860 for web UI, 25565 for internal MC server)
EXPOSE ${WEB_PORT} ${SERVER_PORT}

# -----------------------------------------------------
# 6. Prepare Start Script
# -----------------------------------------------------
# Assuming 'start.sh' is copied in the previous COPY . . command
RUN chmod +x ./start.sh

# Switch to non-root user
USER mcuser

# -----------------------------------------------------
# 7. Update Start command to use the shell wrapper
# -----------------------------------------------------
CMD ["./start.sh"]