From b47f3917bde6c8f5129ea9e7e636ca592aadff48 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Sat, 22 Sep 2018 12:27:45 -0500 Subject: [PATCH] added support for docker to run with a certain PUID and PGID --- Dockerfile | 8 +++---- docker_startup.sh | 37 +++++++++++++++++++++++---------- src/services/docs/docs.class.js | 2 ++ 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/Dockerfile b/Dockerfile index c4da66b..631527d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM node:8-alpine -RUN apk add yarn git bash +RUN apk add yarn git bash s6 RUN mkdir -p /opt/mykb # install node_modules to tmp so it can be cached @@ -15,13 +15,13 @@ RUN cd /opt/mykb && yarn build COPY docker_startup.sh /mykb RUN chmod +x /mykb -VOLUME /kb -VOLUME /db -VOLUME /config +VOLUME /kb /db /config EXPOSE 3030 ARG GIT_NAME=mykb ARG GIT_EMAIL=mykb@localhost +ARG PUID +ARG PGID CMD [ "/mykb" ] \ No newline at end of file diff --git a/docker_startup.sh b/docker_startup.sh index 7201325..671b138 100644 --- a/docker_startup.sh +++ b/docker_startup.sh @@ -1,25 +1,40 @@ #!/bin/bash +PKGDIR="/opt/mykb" +DBDIR="$PKGDIR/db" +KBDIR="$PKGDIR/kb" +CONFDIR="$PKGDIR/config" + if [ -d "/db" ];then - rm -rf /opt/mykb/db - ln -s /db /opt/mykb/db + rm -rf $DBDIR + ln -s /db $DBDIR + DBDIR="/db" fi if [ -d "/kb" ];then rm -rf /opt/mykb/kb ln -s /kb /opt/mykb/kb + KBDIR="/kb" fi if [ -d "/config" ];then - for i in /opt/mykb/config/*;do file=${i#/opt/mykb/config/}; if [ ! -f "/config/$file" ];then cp "$i" "/config/$file"; fi;done - rm -rf /opt/mykb/config - ln -s /config /opt/mykb/config + for i in $CONFDIR/*;do file=${i#/opt/mykb/config/}; if [ ! -f "/config/$file" ];then cp "$i" "/config/$file"; fi;done + rm -rf $CONFDIR + ln -s /config $CONFDIR + CONFDIR="/config" fi -git config --global user.email "$GIT_EMAIL" -git config --global user.name "$GIT_NAME" - cd /opt/mykb -echo $PWD -NODE_ENV=production node ./genSecret.js -yarn start \ No newline at end of file +export NODE_ENV=production + +if [ -z "$PUID" ];then + echo 'no PUID set running as default user' + node ./genSecret.js && node ./src +else + echo 'chowning files' + DIRS=($KBDIR $DBDIR $CONFDIR) + for dir in ${DIRS[@]};do chown "$PUID:$PGID" $dir;done + chown "$PUID:$PGID" -R $CONFDIR + s6-setuidgid "$PUID:$PGID" node ./genSecret.js + s6-setuidgid "$PUID:$PGID" node ./src +fi \ No newline at end of file diff --git a/src/services/docs/docs.class.js b/src/services/docs/docs.class.js index 245d56a..b9b6e82 100644 --- a/src/services/docs/docs.class.js +++ b/src/services/docs/docs.class.js @@ -22,6 +22,8 @@ class Service { fs.stat(path.join(this.docsDir, '.git'), async err => { if (err && err.code === 'ENOENT') { git.init().then(() => { + git.addConfig('user.name', 'mykb') + git.addConfig('user.email', 'mykb@localhost') if (this.numInitDocs === 0) return git.add('./*').then(() => git.commit('initial commit')) })