feat: add game initialization to backend container

This commit is contained in:
Emmanuel BENOîT 2025-01-03 23:22:25 +01:00
parent 10e70a4cbc
commit 1ae7dbe936
Signed by: Emmanuel BENOîT
SSH key fingerprint: SHA256:l7PFUUF5TCDsvYeQC9OnTNz08dFY7Fvf4Hv3neIqYpg
3 changed files with 31 additions and 4 deletions

View file

@ -12,12 +12,14 @@ RUN --mount=type=cache,target=$MAVEN_HOME/.m2,uid=$BUILD_UID \
FROM openjdk:7u211-jre-alpine AS backend FROM openjdk:7u211-jre-alpine AS backend
RUN <<EOF RUN <<EOF
set -e set -e
mkdir -p /app mkdir -p /app/state
chown 1000 /app chown -R 1000 /app/state
EOF EOF
COPY --from=build /src/legacyworlds-server/legacyworlds-server-main/target/*.jar /app/server.jar COPY --from=build /src/legacyworlds-server/legacyworlds-server-main/target/*.jar /app/server.jar
COPY --from=build /src/legacyworlds-server/legacyworlds-server-main/target/lib /app/lib COPY --from=build /src/legacyworlds-server/legacyworlds-server-main/target/lib /app/lib
COPY --from=build /src/legacyworlds-server/legacyworlds-server-main/data /app/data
ADD docker/backend-entrypoint.sh /app/entrypoint.sh ADD docker/backend-entrypoint.sh /app/entrypoint.sh
VOLUME /app/state
ENTRYPOINT ["/app/entrypoint.sh"] ENTRYPOINT ["/app/entrypoint.sh"]
CMD ["server"] CMD ["server"]

View file

@ -1,5 +1,23 @@
#!/bin/sh #!/bin/sh
# Function used to run initialization commands.
run_init_command() {
local stage="$1"
shift
if ! [ -f state/init-$stage ]; then
echo "Running initialization stage $stage"
echo " --> $@"
if /app/entrypoint.sh tool "$*"
then
touch state/init-$stage
else
exit 1
fi
fi
}
cd /app cd /app
if ! [ -z "$LW_CONFIGURE" ]; then if ! [ -z "$LW_CONFIGURE" ]; then
@ -26,6 +44,9 @@ fi
cmd="$1" cmd="$1"
shift shift
if [ "$cmd" == server ]; then if [ "$cmd" == server ]; then
run_init_command import-text ImportText data/i18n-text.xml
run_init_command import-techs ImportTechs data/techs.xml
run_init_command import-buildables ImportBuildables data/buildables.xml
exec /usr/bin/java \ exec /usr/bin/java \
-Dlog4j.configuration=log4j.properties \ -Dlog4j.configuration=log4j.properties \
-jar server.jar -jar server.jar
@ -33,8 +54,9 @@ elif [ "$cmd" == shell ]; then
exec /bin/sh exec /bin/sh
elif [ "$cmd" == tool ]; then elif [ "$cmd" == tool ]; then
exec /usr/bin/java \ exec /usr/bin/java \
-jar legacyworlds-server-main-*.jar \ -Dlog4j.configuration=log4j.properties \
--run-tool "$*" -jar server.jar \
--run-tool "$@"
else else
echo "Invalid command '$cmd'" >&2 echo "Invalid command '$cmd'" >&2
exit 1 exit 1

View file

@ -25,6 +25,8 @@ services:
dockerfile: docker/Dockerfile.application dockerfile: docker/Dockerfile.application
target: backend target: backend
restart: always restart: always
volumes:
- init-state:/app/state
environment: environment:
LW_CONFIGURE: 1 LW_CONFIGURE: 1
LW_DB_HOST: db LW_DB_HOST: db
@ -54,6 +56,7 @@ services:
volumes: volumes:
database: database:
init-state:
secrets: secrets:
db_password: db_password: