docker: Add Dockerfile for multi-platforms.

This commit is contained in:
AirryCo
2024-11-26 19:41:30 +08:00
parent 8e48c4c579
commit 3aae31d100
5 changed files with 280 additions and 14 deletions

18
docker/Dockerfile Normal file
View File

@@ -0,0 +1,18 @@
FROM node:20.11.1-alpine AS server-builder
RUN apk add --no-cache git git-lfs && \
git clone -b 3.10.0-DEV https://github.com/AirryCo/spt-server.git /spt-server && \
cd /spt-server && git lfs pull && \
cd project && \
npm install && npm run build:release
FROM debian:bookworm-slim
LABEL author="AirryCo <henry@stblog.com.cn>"
ENV TZ=Asia/Shanghai
COPY --from=server-builder /spt-server/project/build/ /app/spt-server/
VOLUME /opt/spt-server
WORKDIR /opt/spt-server
EXPOSE 6969
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

26
docker/Dockerfile-fika Normal file
View File

@@ -0,0 +1,26 @@
FROM node:20.11.1-alpine AS fika-builder
RUN apk add --no-cache git git-lfs unzip && \
git clone -b spt-3.10 https://github.com/project-fika/Fika-Server.git /fika-server && \
cd /fika-server && \
npm install && npm run build && \
mkdir output && cd output && unzip /fika-server/dist/fika-server.zip
FROM node:20.11.1-alpine AS server-builder
RUN apk add --no-cache git git-lfs && \
git clone -b 3.10.0-DEV https://github.com/AirryCo/spt-server.git /spt-server && \
cd /spt-server && git lfs pull && \
cd project && \
npm install && npm run build:release
FROM debian:bookworm-slim
LABEL author="AirryCo <henry@stblog.com.cn>"
ENV TZ=Asia/Shanghai
COPY --from=server-builder /spt-server/project/build/ /app/spt-server/
COPY --from=fika-builder /fika-server/output/ /app/spt-server/
VOLUME /opt/spt-server
WORKDIR /opt/spt-server
EXPOSE 6969
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

37
docker/entrypoint.sh Normal file
View File

@@ -0,0 +1,37 @@
#!/bin/bash
if [ -f /opt/spt-server/SPT.Server ]; then
appHash=$(md5sum /app/spt-server/SPT.Server | awk '{ print $1 }')
optHash=$(md5sum /opt/spt-server/SPT.Server | awk '{ print $1 }')
if [ "$appHash" = "$optHash" ]; then
echo "MD5 verification successful!"
else
echo "MD5 mismatch, copy files to /opt/spt-server."
cp -r /app/spt-server /opt
echo "Finished!"
fi
else
echo "Program is not found, copy files to /opt/spt-server."
cp -r /app/spt-server /opt
echo "Finished!"
fi
cd /opt/spt-server
if [ -z "$backendIp" ]; then
IP=$(hostname -I | awk '{print $1}')
else
IP=$backendIp
fi
if [ -z "$backendPort" ]; then
PORT=6969
else
PORT=$backendPort
fi
sed -i "0,/127.0.0.1/s/127.0.0.1/${IP}/" SPT_Data/Server/configs/http.json
sed -i "s/6969/${PORT}/g" SPT_Data/Server/configs/http.json
chmod +x SPT.Server && ./SPT.Server