From a04a6e0f7aee5cca280939e4b8f4f3317465d0b2 Mon Sep 17 00:00:00 2001 From: connlost <4348524953.h@gmail.com> Date: Sun, 28 Apr 2024 12:34:57 +0800 Subject: [PATCH] Docker: No longer building the app in runtime. --- docker/.dockerignore | 4 +++ docker/Dockerfile | 50 ++++++++------------------------ docker/app.sh | 18 ++++++++++++ docker/entrypoint.sh | 32 -------------------- docker/sample-docker-compose.yml | 1 - 5 files changed, 34 insertions(+), 71 deletions(-) create mode 100644 docker/app.sh delete mode 100644 docker/entrypoint.sh diff --git a/docker/.dockerignore b/docker/.dockerignore index 90f633f..cd98e40 100644 --- a/docker/.dockerignore +++ b/docker/.dockerignore @@ -1,4 +1,8 @@ .git +.github +.vscode +save_data_re +tests venv/ logs/ gamesave*/ diff --git a/docker/Dockerfile b/docker/Dockerfile index b8eaed9..9010cc4 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,52 +1,26 @@ -# Use an official Python runtime as a parent image -# FROM python:3.11-slim FROM nikolaik/python-nodejs:python3.12-nodejs21-slim -# Define environment variables for customization -# ENV TZ=UTC \ -# PUID=1000 \ -# PGID=1000 \ -# APP_PORT=8000 \ -# APP_LANG=en \ -# LANG=C.UTF-8 \ -# PYTHONUNBUFFERED=1 \ -# MODE=--cli \ -# SAVE_PATH="/mnt/gamesave" \ -# PASSWORD=null - -# Set the working directory in the container +ENV PATH=/usr/local/nginx/bin:$PATH +EXPOSE $APP_PORT + WORKDIR /app -# Install dependencies required for managing permissions and timezone RUN apt-get update && apt-get install -y --no-install-recommends \ tini \ gosu \ tzdata \ - # && curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \ - # && apt-get install -y nodejs \ && apt-get clean && rm -rf /var/lib/apt/lists/* -# https://github.com/nikolaik/docker-python-nodejs -# All images have a default user `pn`` with uid 1000 and gid 1000. -# Create the appuser user and group before setting permissions -# RUN groupadd -g 1000 appuser && \ -# useradd -m -u 1000 -g appuser -s /bin/bash appuser - -# Copy the application's requirements.txt and setup script, then install Python dependencies -# COPY ./requirements.txt ./ -# RUN pip install --no-cache-dir -r requirements.txt +COPY --chown=pn:pn ./ /app -# Copy the rest of the application's source code -COPY ./ /app +RUN cd "/app/frontend/palworld-pal-editor-webui" \ + && npm install \ + && npm run build \ + && mv "/app/frontend/palworld-pal-editor-webui/dist" "/app/src/palworld_pal_editor/webui" -# Copy the entrypoint script into the image and make it executable -COPY ./docker/entrypoint.sh /entrypoint.sh -RUN chmod +x /entrypoint.sh -RUN chmod +x /app/setup_and_run.sh +RUN pip install --no-cache-dir -r requirements.txt \ + && pip install -e . -ENTRYPOINT ["/entrypoint.sh"] - -# Expose the port dynamically -EXPOSE $APP_PORT +RUN chmod +x /app/docker/app.sh -CMD ["./setup_and_run.sh"] +CMD ["/app/docker/app.sh"] \ No newline at end of file diff --git a/docker/app.sh b/docker/app.sh new file mode 100644 index 0000000..23cf0d1 --- /dev/null +++ b/docker/app.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +if [ ! -z "$PUID" ] && [ ! -z "$PGID" ]; then + usermod -u $PUID pn + groupmod -g $PGID pn +fi + +cmd="python -m palworld_pal_editor --nocli" + +if [ -n "$APP_LANG" ]; then cmd="$cmd --lang=\"$APP_LANG\""; fi +if [ -n "$APP_PORT" ]; then cmd="$cmd --port=$APP_PORT"; fi +if [ -n "$MODE" ]; then cmd="$cmd --mode=\"$MODE\""; fi +if [ -n "$SAVE_PATH" ]; then cmd="$cmd --path=\"$SAVE_PATH\""; fi +if [ -n "$PASSWORD" ]; then cmd="$cmd --password=\"$PASSWORD\""; fi + +echo "Launching: $cmd" + +eval "$cmd" \ No newline at end of file diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh deleted file mode 100644 index 566626b..0000000 --- a/docker/entrypoint.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash -set -e - -# Optionally, set the timezone based on the TZ environment variable -if [ -n "$TZ" ]; then - ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone -fi - -# Update the IDs of the user and group "appuser" to match PUID and PGID provided by the user -if [ ! -z "$PUID" ] && [ ! -z "$PGID" ]; then - usermod -u $PUID pn - groupmod -g $PGID pn -fi - -# Ensure the working directory is owned by the appuser, adjusting permissions as necessary -chown -R pn:pn /app - - - -cmd="./setup_and_run.sh --nocli" - -# Check each environment variable and append it to the command if it exists -if [ -n "$APP_LANG" ]; then cmd="$cmd --lang=\"$APP_LANG\""; fi -if [ -n "$APP_PORT" ]; then cmd="$cmd --port=$APP_PORT"; fi -if [ -n "$MODE" ]; then cmd="$cmd --mode=\"$MODE\""; fi -if [ -n "$SAVE_PATH" ]; then cmd="$cmd --path=\"$SAVE_PATH\""; fi -if [ -n "$PASSWORD" ]; then cmd="$cmd --password=\"$PASSWORD\""; fi -# if [ -n "$INTERACTIVE" ]; then cmd="$cmd --interactive"; fi - -echo "Launching: $cmd" - -eval exec "su pn -c '$cmd'" diff --git a/docker/sample-docker-compose.yml b/docker/sample-docker-compose.yml index afa08b5..bcf7dcc 100644 --- a/docker/sample-docker-compose.yml +++ b/docker/sample-docker-compose.yml @@ -7,7 +7,6 @@ services: ports: - 58888:58888 environment: - - TZ=UTC - PUID=1000 # change this to your uid - PGID=1000 - APP_PORT=58888 # make sure this matches the port you are going to map