-
Notifications
You must be signed in to change notification settings - Fork 29
/
Dockerfile
143 lines (120 loc) · 4.18 KB
/
Dockerfile
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
139
140
141
142
143
# Java Version
ARG JAVA_VERSION=16
################################
### We use a java base image ###
################################
FROM openjdk:${JAVA_VERSION}-alpine AS build
#####################################
### Maintained by Felix Klauke ###
### Contact: info@felix-klauke.de ###
#####################################
LABEL maintainer="Felix Klauke <info@felix-klauke.de>"
#################
### Arguments ###
#################
ARG PAPER_VERSION=1.17
ARG PAPER_DOWNLOAD_URL=https://papermc.io/api/v1/paper/${PAPER_VERSION}/latest/download
ARG MINECRAFT_BUILD_USER=minecraft-build
ENV MINECRAFT_BUILD_PATH=/opt/minecraft
#########################
### Working directory ###
#########################
WORKDIR ${MINECRAFT_BUILD_PATH}
##########################
### Download paperclip ###
##########################
ADD ${PAPER_DOWNLOAD_URL} paper.jar
############
### User ###
############
RUN adduser -s /bin/bash ${MINECRAFT_BUILD_USER} -D && \
chown ${MINECRAFT_BUILD_USER} ${MINECRAFT_BUILD_PATH} -R
USER ${MINECRAFT_BUILD_USER}
############################################
### Run paperclip and obtain patched jar ###
############################################
RUN java -jar ${MINECRAFT_BUILD_PATH}/paper.jar; exit 0
# Copy built jar
RUN mv ${MINECRAFT_BUILD_PATH}/cache/patched*.jar ${MINECRAFT_BUILD_PATH}/paper.jar
###########################
### Running environment ###
###########################
FROM openjdk:${JAVA_VERSION}-alpine AS runtime
##########################
### Environment & ARGS ###
##########################
ENV MINECRAFT_PATH=/opt/minecraft
ENV SERVER_PATH=${MINECRAFT_PATH}/server
ENV DATA_PATH=${MINECRAFT_PATH}/data
ENV LOGS_PATH=${MINECRAFT_PATH}/logs
ENV CONFIG_PATH=${MINECRAFT_PATH}/config
ENV WORLDS_PATH=${MINECRAFT_PATH}/worlds
ENV PLUGINS_PATH=${MINECRAFT_PATH}/plugins
ENV PROPERTIES_LOCATION=${CONFIG_PATH}/server.properties
ENV JAVA_HEAP_SIZE=4G
ENV JAVA_ARGS="-server -Dcom.mojang.eula.agree=true"
ENV SPIGOT_ARGS="--nojline"
ENV PAPER_ARGS=""
#################
### Libraries ###
#################
RUN apk add py3-pip
RUN pip3 install mcstatus
###################
### Healthcheck ###
###################
HEALTHCHECK --interval=10s --timeout=5s --start-period=120s \
CMD mcstatus localhost:$( cat $PROPERTIES_LOCATION | grep "server-port" | cut -d'=' -f2 ) ping
#########################
### Working directory ###
#########################
WORKDIR ${SERVER_PATH}
###########################################
### Obtain runable jar from build stage ###
###########################################
COPY --from=build /opt/minecraft/paper.jar ${SERVER_PATH}/
######################
### Obtain scripts ###
######################
ADD scripts/docker-entrypoint.sh docker-entrypoint.sh
RUN chmod +x docker-entrypoint.sh
############
### User ###
############
RUN addgroup minecraft && \
adduser -s /bin/bash minecraft -G minecraft -h ${MINECRAFT_PATH} -D && \
mkdir ${LOGS_PATH} ${DATA_PATH} ${WORLDS_PATH} ${PLUGINS_PATH} ${CONFIG_PATH} && \
chown -R minecraft:minecraft ${MINECRAFT_PATH}
USER minecraft
#########################
### Setup environment ###
#########################
# Create symlink for plugin volume as hotfix for some plugins who hard code their directories
RUN ln -s $PLUGINS_PATH $SERVER_PATH/plugins && \
# Create symlink for persistent data
ln -s $DATA_PATH/banned-ips.json $SERVER_PATH/banned-ips.json && \
ln -s $DATA_PATH/banned-players.json $SERVER_PATH/banned-players.json && \
ln -s $DATA_PATH/help.yml $SERVER_PATH/help.yml && \
ln -s $DATA_PATH/ops.json $SERVER_PATH/ops.json && \
ln -s $DATA_PATH/permissions.yml $SERVER_PATH/permissions.yml && \
ln -s $DATA_PATH/whitelist.json $SERVER_PATH/whitelist.json && \
# Create symlink for logs
ln -s $LOGS_PATH $SERVER_PATH/logs
###############
### Volumes ###
###############
VOLUME "${CONFIG_PATH}"
VOLUME "${WORLDS_PATH}"
VOLUME "${PLUGINS_PATH}"
VOLUME "${DATA_PATH}"
VOLUME "${LOGS_PATH}"
#############################
### Expose minecraft port ###
#############################
EXPOSE 25565
######################################
### Entrypoint is the start script ###
######################################
ENTRYPOINT [ "./docker-entrypoint.sh" ]
# Run Command
CMD [ "serve" ]