diff --git a/Dockerfile b/Dockerfile index e0d7f6c..f8044c3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,11 @@ FROM python:3.11-alpine as python-builder -RUN apk add --no-cache g++ python3-dev libpq-dev libstdc++ +RUN apk add --no-cache g++ python3-dev libpq-dev libstdc++ shadow # Add local user so we don't run as root -RUN adduser -D app -USER app +RUN groupmod -g 1000 users \ + && useradd -u 911 -U app \ + && usermod -G users app ENV PATH="/home/app/.local/bin:${PATH}" @@ -30,21 +31,24 @@ LABEL org.opencontainers.image.source=https://github.com/Donkie/Spoolman LABEL org.opencontainers.image.description="Keep track of your inventory of 3D-printer filament spools." LABEL org.opencontainers.image.licenses=MIT -RUN apk add --no-cache libstdc++ +RUN apk add --no-cache libstdc++ su-exec shadow # Add local user so we don't run as root -RUN adduser -D app \ +RUN groupmod -g 1000 users \ + && useradd -u 1000 -U app \ + && usermod -G users app \ && mkdir -p /home/app/.local/share/spoolman \ && chown -R app:app /home/app/.local/share/spoolman -USER app - # Copy built client COPY --chown=app:app ./client/dist /home/app/spoolman/client/dist # Copy built app COPY --chown=app:app --from=python-builder /home/app/spoolman /home/app/spoolman +COPY entrypoint.sh /home/app/spoolman/entrypoint.sh +RUN chmod +x /home/app/spoolman/entrypoint.sh + WORKDIR /home/app/spoolman ENV PATH="/home/app/spoolman/.venv/bin:${PATH}" @@ -57,5 +61,5 @@ ENV BUILD_DATE=${BUILD_DATE} # Run command EXPOSE 8000 -ENTRYPOINT ["uvicorn", "spoolman.main:app"] +ENTRYPOINT ["/home/app/spoolman/entrypoint.sh"] CMD ["--host", "0.0.0.0", "--port", "8000"] diff --git a/README.md b/README.md index 30f2d40..a5e5c68 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,8 @@ If you want to connect with an external database instead, specify the `SPOOLMAN_ | SPOOLMAN_DB_QUERY | Query parameters for the database connection, e.g. set to `unix_socket=/path/to/mysql.sock` to connect using a MySQL socket. | | SPOOLMAN_LOGGING_LEVEL | Logging level, any of: `CRITICAL`, `ERROR`, `WARNING`, `INFO`, `DEBUG`, defaults to `INFO`. | | SPOOLMAN_AUTOMATIC_BACKUP | Automatic nightly DB backups for SQLite databases. Enabled by default, set to `FALSE` to disable. | +| PUID | (*docker only*) Set the UID of the user in the docker container. Default is 1000. | +| PGID | (*docker only*) Set the GID of the user in the docker container. Default is 1000. | ## Frequently Asked Questions (FAQs) ### QR Code Does not work on HTTP / The page is not served over HTTPS diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..237ef5b --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +PUID=${PUID:-1000} +PGID=${PGID:-1000} + +groupmod -o -g "$PGID" app +usermod -o -u "$PUID" app + +echo User UID: $(id -u app) +echo User GID: $(id -g app) + +echo "Starting uvicorn..." + +# Execute the uvicorn command with any additional arguments +exec su-exec "app" uvicorn spoolman.main:app "$@"