|
| 1 | +FROM node:8.15.1-jessie AS BUILD |
| 2 | +# use multi-stage build to build frontend javascript |
| 3 | +WORKDIR /codimd |
| 4 | + |
| 5 | +COPY . ./ |
| 6 | + |
| 7 | +RUN yarn install --non-interactive --pure-lockfile && \ |
| 8 | + yarn build |
| 9 | + |
| 10 | +# ---------------------------------------------------- |
| 11 | +# Runtime Stage |
| 12 | +FROM node:8.15.1 AS RUNTIME |
| 13 | + |
| 14 | +# build for production |
| 15 | +ENV NODE_ENV production |
| 16 | +ENV PATH="/home/codimd/.npm-global/bin:${PATH}" |
| 17 | + |
| 18 | +# setup isolated user for more security |
| 19 | +ARG USER_NAME=codimd |
| 20 | +ARG UID=1500 |
| 21 | +ARG GID=1500 |
| 22 | + |
| 23 | +RUN set +x -ue && \ |
| 24 | + wget https://github.com/hackmdio/portchecker/releases/download/v1.0.1/portchecker-linux-amd64.tar.gz && \ |
| 25 | + tar xvf portchecker-linux-amd64.tar.gz -C /usr/local/bin && \ |
| 26 | + mv /usr/local/bin/portchecker-linux-amd64 /usr/local/bin/pcheck && \ |
| 27 | + # Add user and groupd |
| 28 | + groupadd --gid $GID $USER_NAME && \ |
| 29 | + useradd --uid $UID --gid $USER_NAME --no-log-init --create-home $USER_NAME && \ |
| 30 | + # setup local npm global directory |
| 31 | + mkdir /home/codimd/.npm-global && \ |
| 32 | + echo "prefix=/home/codimd/.npm-global/" > /home/codimd/.npmrc && \ |
| 33 | + # setup app dir |
| 34 | + mkdir /codimd && \ |
| 35 | + # adjust permission |
| 36 | + chown -R $USER_NAME:$USER_NAME /home/codimd |
| 37 | + |
| 38 | +# Copy build stage file to runtime |
| 39 | +COPY --from=BUILD /codimd /codimd |
| 40 | +RUN chown -R $USER_NAME:$USER_NAME /codimd |
| 41 | + |
| 42 | +# change running user name |
| 43 | +USER $USER_NAME |
| 44 | +# build project |
| 45 | +WORKDIR /codimd |
| 46 | + |
| 47 | +RUN set +x -ue && \ |
| 48 | + cliVer=$(cat package.json | grep sequelize-cli | awk '{print substr($1, 2, length($1) - 3)"@"substr($2, 2, length($2) - 3)}') && \ |
| 49 | + npm -g install "$cliVer" && \ |
| 50 | + yarn install --production --non-interactive --pure-lockfile && \ |
| 51 | + yarn cache clean |
| 52 | + |
| 53 | +VOLUME /codimd/public/uploads |
| 54 | +EXPOSE 3000 |
| 55 | + |
| 56 | +ENTRYPOINT ["/codimd/docker-entrypoint.sh"] |
0 commit comments