manage group from entrypoint

This commit is contained in:
Kyle Spearrin 2018-04-16 15:17:13 -04:00
parent 3643222b3c
commit c0f38216ef
2 changed files with 40 additions and 10 deletions

View File

@ -10,8 +10,6 @@ WORKDIR /app
EXPOSE 5000 EXPOSE 5000
COPY ./dist . COPY ./dist .
COPY entrypoint.sh / COPY entrypoint.sh /
RUN chmod +x /entrypoint.sh
RUN groupadd -g 999 bitwarden \
&& chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"] ENTRYPOINT ["/entrypoint.sh"]

View File

@ -1,33 +1,65 @@
#!/bin/bash #!/bin/bash
# Setup
GROUPNAME="bitwarden"
USERNAME="bitwarden" USERNAME="bitwarden"
NOUSER=`id -u $USERNAME > /dev/null 2>&1; echo $?`
CURRENTGID=`getent group $GROUPNAME | cut -d: -f3`
LGID=${LOCAL_GID:-999}
CURRENTUID=`id -u $USERNAME`
NOUSER=`$CURRENTUID > /dev/null 2>&1; echo $?`
LUID=${LOCAL_UID:-999} LUID=${LOCAL_UID:-999}
# Step down from host root # Step down from host root
if [ $LGID == 0 ]
then
LGID=999
fi
if [ $LUID == 0 ] if [ $LUID == 0 ]
then then
LUID=999 LUID=999
fi fi
if [ $NOUSER == 0 ] && [ `id -u $USERNAME` != $LUID ] # Create group
if [ $CURRENTGID ]
then
if [ $CURRENTGID != $LGID ]
then
groupmod -g $LGID $GROUPNAME
fi
else
groupadd -g $LGID $GROUPNAME
fi
# Create user and assign group
if [ $NOUSER == 0 ] && [ $CURRENTUID != $LUID ]
then then
usermod -u $LUID $USERNAME usermod -u $LUID $USERNAME
elif [ $NOUSER == 1 ] elif [ $NOUSER == 1 ]
then then
useradd -r -u $LUID -g $USERNAME $USERNAME useradd -r -u $LUID -g $GROUPNAME $USERNAME
fi fi
# Make home directory for user
if [ ! -d "/home/$USERNAME" ] if [ ! -d "/home/$USERNAME" ]
then then
mkhomedir_helper $USERNAME mkhomedir_helper $USERNAME
fi fi
chown -R $USERNAME:$USERNAME /etc/bitwarden # The rest...
chown -R $USERNAME:$GROUPNAME /etc/bitwarden
cp /etc/bitwarden/web/settings.js /app/js/settings.js cp /etc/bitwarden/web/settings.js /app/js/settings.js
cp /etc/bitwarden/web/app-id.json /app/app-id.json cp /etc/bitwarden/web/app-id.json /app/app-id.json
chown -R $USERNAME:$USERNAME /app chown -R $USERNAME:$GROUPNAME /app
chown -R $USERNAME:$USERNAME /bitwarden_server chown -R $USERNAME:$GROUPNAME /bitwarden_server
gosu $USERNAME:$USERNAME dotnet /bitwarden_server/Server.dll \ gosu $USERNAME:$GROUPNAME dotnet /bitwarden_server/Server.dll \
/contentRoot=/app /webRoot=. /serveUnknown=false /contentRoot=/app /webRoot=. /serveUnknown=false