Skip to content

Commit

Permalink
Fix dockerfile (#48)
Browse files Browse the repository at this point in the history
* remove entrypoint as its causing issues. set default puid/pgid.

* handle user management better

---------

Co-authored-by: Spoked <Spoked@localhost>
Co-authored-by: Spoked <[email protected]>
  • Loading branch information
3 people authored Dec 17, 2023
1 parent 750822d commit f89b5c0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 37 deletions.
23 changes: 9 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/*
Expand All @@ -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
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
49 changes: 26 additions & 23 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"

0 comments on commit f89b5c0

Please sign in to comment.