From f89b5c0189fdc471fc9cd51221ed19941fb25e6d Mon Sep 17 00:00:00 2001 From: JustHereToBreakThings <154031386+JustHereToBreakThings@users.noreply.github.com> Date: Sun, 17 Dec 2023 01:01:30 -0500 Subject: [PATCH] Fix dockerfile (#48) * remove entrypoint as its causing issues. set default puid/pgid. * handle user management better --------- Co-authored-by: Spoked Co-authored-by: Spoked <5782630+dreulavelle@users.noreply.github.com> --- Dockerfile | 23 +++++++++-------------- entrypoint.sh | 49 ++++++++++++++++++++++++++----------------------- 2 files changed, 35 insertions(+), 37 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9efcaf71..d35b0ec2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,10 +4,6 @@ LABEL org.label-schema.name="Iceberg" \ org.label-schema.description="Iceberg Debrid Downloader" \ org.label-schema.url="https://github.com/dreulavelle/iceberg" -# Define environment variables for PUID and PGID -ENV PUID=1000 -ENV PGID=1000 - # Install necessary packages RUN apk --update add python3 py3-pip nodejs npm bash shadow vim nano rclone && \ rm -rf /var/cache/apk/* @@ -31,17 +27,16 @@ RUN cd frontend && \ pnpm install && \ pnpm run build -# Create user and group for the application -RUN addgroup -g ${PGID} iceberg && \ - adduser -D -u ${PUID} -G iceberg iceberg && \ - chown -R iceberg:iceberg /iceberg - -# Switch to the new user -USER iceberg - # Expose necessary ports EXPOSE 4173 8080 +# Copy and set permissions for the entrypoint script +COPY entrypoint.sh /usr/local/bin/entrypoint.sh +RUN chmod +x /usr/local/bin/entrypoint.sh + +# Set the entrypoint script +ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] + # Start the backend first, then the frontend (suppressed frontend output) -CMD cd /iceberg/backend && source /venv/bin/activate && exec python main.py & \ - cd /iceberg/frontend && pnpm run preview --host 0.0.0.0 >/dev/null 2>&1 \ No newline at end of file +CMD cd backend && source /venv/bin/activate && exec python main.py & \ + cd frontend && pnpm run preview --host 0.0.0.0 >/dev/null 2>&1 diff --git a/entrypoint.sh b/entrypoint.sh index 85aeeefd..96578540 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,31 +1,34 @@ #!/bin/sh -# Exit immediately if a command exits with a non-zero status -# set -e +# Check and set default values for PUID and PGID if not provided +PUID=${PUID:-1000} +PGID=${PGID:-1000} -# Treat unset variables as an error -# set -u +echo "Starting Container with $PUID:$PGID permissions..." -echo "Starting Iceberg container..." +# Check if the iceberg user or group exists, and delete if they do +if getent passwd iceberg > /dev/null 2>&1; then + deluser iceberg +fi +if getent group iceberg > /dev/null 2>&1; then + delgroup iceberg +fi -# Check for required environment variables and validate configuration -# NOTE: This will be used to check for rclone flags and other configuration later -# required_vars=("REQUIRED_VAR1" "REQUIRED_VAR2") -# for var in "${required_vars[@]}"; do -# if [ -z "${!var:-}" ]; then -# echo "Error: Required environment variable '$var' not set." -# exit 1 -# fi -# done +# Create the iceberg group if it doesn't exist +if ! getent group $PGID > /dev/null 2>&1; then + addgroup -g $PGID iceberg +else + iceberg_group=$(getent group $PGID | cut -d: -f1) + echo "Group with GID $PGID already exists as $iceberg_group" +fi -PUID=${PUID:-1000} -PGID=${PGID:-1000} +# Create the iceberg user +if ! getent passwd $PUID > /dev/null 2>&1; then + adduser -D -u $PUID -G iceberg iceberg +else + iceberg_user=$(getent passwd $PUID | cut -d: -f1) + echo "User with UID $PUID already exists as $iceberg_user" +fi -addgroup -g $PGID iceberg -adduser -D -u $PUID -G iceberg iceberg chown -R iceberg:iceberg /iceberg -chmod -R 755 /iceberg - -trap "echo 'Shutting down...'; exit" SIGINT SIGTERM -echo "Initialization complete. Executing main process..." -exec "$@" +exec su iceberg -c "$@"