1
0
mirror of https://github.com/webrecorder/pywb.git synced 2025-03-15 00:03:28 +01:00
pywb/docker-entrypoint.sh
Ilya Kreymer b90ee427cf
Docker Improvements (#446)
* Misc improvements, including fixes from @funkyfuture:
- Dockerfile: Reduces number of created layers and source contents
- Support for automatic collection creation if INIT_COLLECTION is defined
- Add entry point script docker-entrypoint.sh
- update to latest python (3.7.2 currently)
- additions to .dockerignore
- setup.py and requirements cleanup (just use plain 'gevent' requirement)

* docker-entrypoint.sh improvements:
- before running cmd, match uid/gid to that of volume dir (specified via $VOLUME_DIR, defaulting to /webarchive)
- if volume is owned by root (default if none mounted), just run as root
- if volume is owned by different user, create/update user 'archivist' to match the uid/gid of $VOLUME_DIR, then run cmd as 'su archivist'
2019-02-27 09:13:38 -08:00

39 lines
1.1 KiB
Bash
Executable File

#!/bin/sh
set -e
# Get UID/GID from volume dir
VOLUME_UID=$(stat -c '%u' $VOLUME_DIR)
VOLUME_GID=$(stat -c '%g' $VOLUME_DIR)
MY_UID=$(id -u)
MY_GID=$(id -g)
# Run as custom user
if [ "$MY_GID" != "$VOLUME_GID" ] || [ "$MY_UID" != "$VOLUME_UID" ]; then
# create or modify user and group to match expected uid/gid
groupadd --gid $VOLUME_GID archivist || groupmod -o --gid $VOLUME_GID archivist
useradd -ms /bin/bash -u $VOLUME_UID -g $VOLUME_GID archivist || usermod -o -u $VOLUME_UID archivist
# initialize a collection if defined and not present
if [ -n "$INIT_COLLECTION" ] && [ ! -d $VOLUME_DIR/collections/$INIT_COLLECTION ]; then
su archivist -c "wb-manager init $INIT_COLLECTION"
fi
cmd="cd $PWD; $@"
# run process as new archivist user
su archivist -c "$cmd"
# run as current user (root)
else
# initialize a collection if defined and not present
if [ -n "$INIT_COLLECTION" ] && [ ! -d $VOLUME_DIR/collections/$INIT_COLLECTION ]; then
wb-manager init $INIT_COLLECTION
fi
# run process directly
exec $@
fi