fix: actually run the backend as a non-root user

This commit is contained in:
Emmanuel BENOîT 2025-01-03 23:53:54 +01:00
parent 18602a42f1
commit 46bc60351c
Signed by: Emmanuel BENOîT
SSH key fingerprint: SHA256:l7PFUUF5TCDsvYeQC9OnTNz08dFY7Fvf4Hv3neIqYpg
3 changed files with 6 additions and 2 deletions

View file

@ -12,12 +12,15 @@ USER $BUILD_UID
WORKDIR $BUILD
RUN --mount=type=cache,target=$MAVEN_HOME/.m2,uid=$BUILD_UID \
mvn -e -Duser.home=$MAVEN_HOME package
USER 0
RUN chown -R root $BUILD
FROM openjdk:7u211-jre-alpine AS backend
RUN <<EOF
set -e
mkdir -p /app/state
chown -R 1000 /app/state
touch /app/data-source.xml
chown -R 1000 /app/state /app/data-source.xml
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/lib /app/lib

View file

@ -8,7 +8,7 @@ run_init_command() {
if ! [ -f state/init-$stage ]; then
echo "Running initialization stage $stage"
echo " --> $*"
if /app/entrypoint.sh tool "$*"
if /app/entrypoint.sh tool $*
then
touch state/init-$stage
else

View file

@ -25,6 +25,7 @@ services:
dockerfile: docker/Dockerfile.application
target: backend
restart: always
user: "1000"
volumes:
- init-state:/app/state
environment: