diff --git a/Dockerfile b/Dockerfile index a248fd4c..e0b7ad76 100755 --- a/Dockerfile +++ b/Dockerfile @@ -1,34 +1,34 @@ ARG PYTHON=python:3.8 - FROM $PYTHON +RUN groupadd -g 1001 archivist && useradd -m -u 1001 -g archivist -s /bin/bash archivist + WORKDIR /pywb -COPY requirements.txt extra_requirements.txt ./ - +COPY --chown=archivist:archivist requirements.txt extra_requirements.txt ./ RUN pip install --no-cache-dir -r requirements.txt -r extra_requirements.txt -COPY . ./ +COPY --chown=archivist:archivist . ./ RUN python setup.py install \ && mv ./docker-entrypoint.sh / \ - && mkdir /uwsgi && mv ./uwsgi.ini /uwsgi/ \ - && mkdir /webarchive && mv ./config.yaml /webarchive/ + && mkdir -p /uwsgi /webarchive \ + && mv ./uwsgi.ini /uwsgi/ \ + && mv ./config.yaml /webarchive/ \ + && chmod -R g+rwX /webarchive /pywb WORKDIR /webarchive -# auto init collection ENV INIT_COLLECTION '' - ENV VOLUME_DIR /webarchive -#USER archivist -COPY docker-entrypoint.sh ./ +COPY --chown=archivist:archivist docker-entrypoint.sh /docker-entrypoint.sh +RUN chmod +x /docker-entrypoint.sh + +USER archivist -# volume and port VOLUME /webarchive EXPOSE 8080 ENTRYPOINT ["/docker-entrypoint.sh"] CMD ["uwsgi", "/uwsgi/uwsgi.ini"] - diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 787dd13f..ed16eb36 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -2,38 +2,8 @@ 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 - cd $VOLUME_DIR - wb-manager init $INIT_COLLECTION - fi - - # run process directly - exec $@ +if [ -n "$INIT_COLLECTION" ] && [ ! -d "$VOLUME_DIR/collections/$INIT_COLLECTION" ]; then + wb-manager init "$INIT_COLLECTION" || echo "Warning: Could not initialize collection." fi +exec "$@"