Skip to content

Commit

Permalink
Allow arbitrary --user values
Browse files Browse the repository at this point in the history
  • Loading branch information
tianon committed Dec 12, 2016
1 parent 4128e2c commit fb60e5b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# https://github.com/nodejs/LTS
FROM node:4-slim

RUN groupadd user && useradd --create-home --home-dir /home/user -g user user

# grab gosu for easy step-down from root
ENV GOSU_VERSION 1.7
RUN set -x \
Expand Down Expand Up @@ -36,7 +38,7 @@ RUN buildDeps=' \
&& rm -rf /tmp/npm*

ENV GHOST_CONTENT /var/lib/ghost
RUN mkdir -p "$GHOST_CONTENT"
RUN mkdir -p "$GHOST_CONTENT" && chown -R user:user "$GHOST_CONTENT"
VOLUME $GHOST_CONTENT

COPY docker-entrypoint.sh /entrypoint.sh
Expand Down
15 changes: 6 additions & 9 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#!/bin/bash
set -e

# allow the container to be started with `--user`
if [[ "$*" == npm*start* ]] && [ "$(id -u)" = '0' ]; then
chown -R user "$GHOST_CONTENT"
exec gosu user "$BASH_SOURCE" "$@"
fi

if [[ "$*" == npm*start* ]]; then
baseDir="$GHOST_SOURCE/content"
for dir in "$baseDir"/*/ "$baseDir"/themes/*/; do
Expand All @@ -19,15 +25,6 @@ if [[ "$*" == npm*start* ]]; then
fi

ln -sf "$GHOST_CONTENT/config.js" "$GHOST_SOURCE/config.js"

PUID=${PUID:-1001}
PGID=${PGID:-1001}
groupadd -o -g "$PGID" user
useradd --create-home --home-dir /home/user -g user -o -u "$PUID" user

chown -R user:user "$GHOST_CONTENT"

set -- gosu user "$@"
fi

exec "$@"

0 comments on commit fb60e5b

Please sign in to comment.