-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathDockerfile.alpine-liberica
More file actions
120 lines (101 loc) 路 4.5 KB
/
Copy pathDockerfile.alpine-liberica
File metadata and controls
120 lines (101 loc) 路 4.5 KB
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
# syntax=docker/dockerfile:1.7
# STAGE 1: Builder
FROM alpine:3.24 AS builder
RUN apk add --no-cache curl unzip 7zip dos2unix
WORKDIR /build
# Download and extract Hytale Downloader
RUN curl -L -o hytale.zip https://downloader.hytale.com/hytale-downloader.zip && \
7z x hytale.zip -y -o./hytale -mmt=on && \
mv ./hytale/hytale-downloader-linux-amd64 ./hytale-downloader && \
chmod +x ./hytale-downloader && rm -rf hytale hytale.zip
# Prepare scripts
COPY scripts/ ./scripts/
COPY entrypoint.sh .
RUN find scripts -type f -name "*.sh" -exec dos2unix {} + && \
dos2unix entrypoint.sh && chmod -R +x scripts && chmod +x entrypoint.sh
# STAGE 2: Final Runtime
FROM bellsoft/liberica-openjre-alpine-musl:25.0.3-11
# Build arguments for customizable UID/GID
ARG UID=1000
ARG GID=1000
# Build arguments
ARG BUILDTIME=local
ARG VERSION=local
ARG REVISION=local
# OCI Metadata
LABEL org.opencontainers.image.title="Hytale Server" \
org.opencontainers.image.description="Hytale Docker server image with non-root execution, UDP optimization, and diagnostics." \
org.opencontainers.image.authors="deinfreu" \
org.opencontainers.image.url="https://github.com/deinfreu/hytale-server-container" \
org.opencontainers.image.source="https://github.com/deinfreu/hytale-server-container" \
org.opencontainers.image.version="${VERSION}" \
org.opencontainers.image.revision="${REVISION}" \
org.opencontainers.image.created="${BUILDTIME}" \
org.opencontainers.image.licenses="Apache-2.0"
# Runtime configuration
ENV USER=container \
HOME=/home/container \
UID=1000 \
GID=1000 \
SCRIPTS_PATH="/usr/local/bin/scripts" \
SERVER_PORT=5520 \
SERVER_IP="" \
JAVA_ARGS="" \
PROD=FALSE \
DEBUG=FALSE
# Install dependencies
RUN apk add --no-cache tini su-exec curl iproute2 ca-certificates tzdata jq libc6-compat libstdc++ gcompat 7zip coreutils
# Install QEMU static binary for x86_64 emulation (host must register binfmt)
ARG TARGETARCH
RUN if [ "$TARGETARCH" = "arm64" ]; then \
echo "[INFO] Detected ARM64, installing QEMU static binary for x86_64 emulation..."; \
apk add --no-cache qemu-x86_64 && \
# Verify QEMU is installed and accessible
which qemu-x86_64-static || which qemu-x86_64 || { echo "ERROR: QEMU not found"; exit 1; }; \
else \
echo "[INFO] Detected x86_64, skipping QEMU install (not required)"; \
fi
# Setup User (with UID/GID conflict handling)
RUN if getent passwd ${UID} > /dev/null 2>&1; then \
EXISTING_USER=$(getent passwd ${UID} | cut -d: -f1); \
EXISTING_GROUP=$(getent passwd ${UID} | cut -d: -f4); \
deluser ${EXISTING_USER} && \
if getent group ${GID} > /dev/null 2>&1; then \
GROUP_NAME=$(getent group ${GID} | cut -d: -f1); \
delgroup ${GROUP_NAME}; \
fi; \
addgroup -S -g ${GID} ${USER} && \
adduser -S -D -h ${HOME} -u ${UID} -G ${USER} ${USER}; \
else \
addgroup -S -g ${GID} ${USER} && \
adduser -S -D -h ${HOME} -u ${UID} -G ${USER} ${USER}; \
fi
# Ensure home directory exists with proper ownership and permissions before volume definition
RUN mkdir -p ${HOME} && \
chown -R ${USER}:${USER} ${HOME} && \
chmod 755 ${HOME}
# Copy artifacts from builder
COPY --from=builder --chown=root:root /build/hytale-downloader /usr/local/bin/hytale-downloader-bin
COPY --from=builder --chown=${USER}:${USER} /build/scripts/ /usr/local/bin/scripts/
COPY --from=builder --chown=${USER}:${USER} /build/entrypoint.sh /entrypoint.sh
# Create QEMU wrapper for hytale-downloader on ARM64
ARG TARGETARCH
RUN if [ "$TARGETARCH" = "arm64" ]; then \
QEMU_BIN=$(which qemu-x86_64-static || which qemu-x86_64) && \
echo '#!/bin/sh' > /usr/local/bin/hytale-downloader && \
echo "exec $QEMU_BIN /usr/local/bin/hytale-downloader-bin \"\$@\"" >> /usr/local/bin/hytale-downloader && \
chmod +x /usr/local/bin/hytale-downloader; \
else \
mv /usr/local/bin/hytale-downloader-bin /usr/local/bin/hytale-downloader; \
fi
# Image metadata file
RUN printf "buildtime=%s\nversion=%s\nrevision=%s\n" "${BUILDTIME}" "${VERSION}" "${REVISION}" > /etc/image.properties
# Final setup
WORKDIR ${HOME}
# Declare the volume inside the image metadata to enforce ownership hints
VOLUME [ "/home/container" ]
EXPOSE ${SERVER_PORT}/udp
STOPSIGNAL SIGTERM
HEALTHCHECK --interval=30s --timeout=5s --start-period=2m --retries=3 CMD ss -ulpn | grep -q ":${SERVER_PORT}" || exit 1
ENTRYPOINT ["/sbin/tini", "--"]
CMD ["/bin/sh", "/entrypoint.sh"]