Skip to content

Commit

Permalink
Fix dockerfile (#49)
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

* Use existing user/group if they already exist

---------

Co-authored-by: Spoked <Spoked@localhost>
  • Loading branch information
dreulavelle and Spoked authored Dec 17, 2023
1 parent f89b5c0 commit ee59e95
Showing 1 changed file with 17 additions and 24 deletions.
41 changes: 17 additions & 24 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,34 +1,27 @@
#!/bin/sh

# Check and set default values for PUID and PGID if not provided
PUID=${PUID:-1000}
PGID=${PGID:-1000}
echo "Starting Container with ${PUID}:${PGID} permissions..."

echo "Starting Container with $PUID:$PGID permissions..."

# 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

# Create the iceberg group if it doesn't exist
if ! getent group $PGID > /dev/null 2>&1; then
# Create group if it doesn't exist or reuse the existing group
if ! getent group $PGID > /dev/null; then
addgroup -g $PGID iceberg
else
iceberg_group=$(getent group $PGID | cut -d: -f1)
echo "Group with GID $PGID already exists as $iceberg_group"
existing_group=$(getent group $PGID | cut -d: -f1)
echo "Group with GID $PGID already exists as $existing_group"
iceberg_group=$existing_group
fi

# Create the iceberg user
if ! getent passwd $PUID > /dev/null 2>&1; then
adduser -D -u $PUID -G iceberg iceberg
# Create user if it doesn't exist or reuse the existing user
if ! getent passwd $PUID > /dev/null; then
adduser -D -u $PUID -G ${iceberg_group:-iceberg} iceberg
else
iceberg_user=$(getent passwd $PUID | cut -d: -f1)
echo "User with UID $PUID already exists as $iceberg_user"
existing_user=$(getent passwd $PUID | cut -d: -f1)
echo "User with UID $PUID already exists as $existing_user"
iceberg_user=$existing_user
fi

chown -R iceberg:iceberg /iceberg
exec su iceberg -c "$@"
# Change ownership of relevant directories
chown -R ${PUID}:${PGID} /iceberg

echo "Initialization complete. Executing main process..."
exec su -s /bin/sh -c "$@" ${iceberg_user:-iceberg}

0 comments on commit ee59e95

Please sign in to comment.