added support for docker to run with a certain PUID and PGID
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
FROM node:8-alpine
|
FROM node:8-alpine
|
||||||
|
|
||||||
RUN apk add yarn git bash
|
RUN apk add yarn git bash s6
|
||||||
RUN mkdir -p /opt/mykb
|
RUN mkdir -p /opt/mykb
|
||||||
|
|
||||||
# install node_modules to tmp so it can be cached
|
# 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
|
COPY docker_startup.sh /mykb
|
||||||
RUN chmod +x /mykb
|
RUN chmod +x /mykb
|
||||||
|
|
||||||
VOLUME /kb
|
VOLUME /kb /db /config
|
||||||
VOLUME /db
|
|
||||||
VOLUME /config
|
|
||||||
|
|
||||||
EXPOSE 3030
|
EXPOSE 3030
|
||||||
|
|
||||||
ARG GIT_NAME=mykb
|
ARG GIT_NAME=mykb
|
||||||
ARG GIT_EMAIL=mykb@localhost
|
ARG GIT_EMAIL=mykb@localhost
|
||||||
|
ARG PUID
|
||||||
|
ARG PGID
|
||||||
|
|
||||||
CMD [ "/mykb" ]
|
CMD [ "/mykb" ]
|
||||||
@@ -1,25 +1,40 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
PKGDIR="/opt/mykb"
|
||||||
|
DBDIR="$PKGDIR/db"
|
||||||
|
KBDIR="$PKGDIR/kb"
|
||||||
|
CONFDIR="$PKGDIR/config"
|
||||||
|
|
||||||
if [ -d "/db" ];then
|
if [ -d "/db" ];then
|
||||||
rm -rf /opt/mykb/db
|
rm -rf $DBDIR
|
||||||
ln -s /db /opt/mykb/db
|
ln -s /db $DBDIR
|
||||||
|
DBDIR="/db"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -d "/kb" ];then
|
if [ -d "/kb" ];then
|
||||||
rm -rf /opt/mykb/kb
|
rm -rf /opt/mykb/kb
|
||||||
ln -s /kb /opt/mykb/kb
|
ln -s /kb /opt/mykb/kb
|
||||||
|
KBDIR="/kb"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -d "/config" ];then
|
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
|
for i in $CONFDIR/*;do file=${i#/opt/mykb/config/}; if [ ! -f "/config/$file" ];then cp "$i" "/config/$file"; fi;done
|
||||||
rm -rf /opt/mykb/config
|
rm -rf $CONFDIR
|
||||||
ln -s /config /opt/mykb/config
|
ln -s /config $CONFDIR
|
||||||
|
CONFDIR="/config"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
git config --global user.email "$GIT_EMAIL"
|
|
||||||
git config --global user.name "$GIT_NAME"
|
|
||||||
|
|
||||||
cd /opt/mykb
|
cd /opt/mykb
|
||||||
echo $PWD
|
export NODE_ENV=production
|
||||||
NODE_ENV=production node ./genSecret.js
|
|
||||||
yarn start
|
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
|
||||||
@@ -22,6 +22,8 @@ class Service {
|
|||||||
fs.stat(path.join(this.docsDir, '.git'), async err => {
|
fs.stat(path.join(this.docsDir, '.git'), async err => {
|
||||||
if (err && err.code === 'ENOENT') {
|
if (err && err.code === 'ENOENT') {
|
||||||
git.init().then(() => {
|
git.init().then(() => {
|
||||||
|
git.addConfig('user.name', 'mykb')
|
||||||
|
git.addConfig('user.email', 'mykb@localhost')
|
||||||
if (this.numInitDocs === 0) return
|
if (this.numInitDocs === 0) return
|
||||||
git.add('./*').then(() => git.commit('initial commit'))
|
git.add('./*').then(() => git.commit('initial commit'))
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user