Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dockerfile #48

Merged
merged 3 commits into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 "$@"
Loading