fix: change note permission cause error

Signed-off-by: BoHong Li <raccoon@hackmd.io>
This commit is contained in:
BoHong Li 2019-07-30 18:09:17 +08:00
parent b41de7820c
commit 0f51d1e306
No known key found for this signature in database
GPG Key ID: 06770355DC9ECD38
7 changed files with 122 additions and 1 deletions

8
.dockerignore Normal file
View File

@ -0,0 +1,8 @@
.git/
node_modules/
docs/
test/
.sequelizerc.example
config.json.example
public/build

56
deployments/Dockerfile Normal file
View File

@ -0,0 +1,56 @@
FROM node:8.15.1-jessie AS BUILD
# use multi-stage build to build frontend javascript
WORKDIR /codimd
COPY . ./
RUN yarn install --non-interactive --pure-lockfile && \
yarn build
# ----------------------------------------------------
# Runtime Stage
FROM node:8.15.1 AS RUNTIME
# build for production
ENV NODE_ENV production
ENV PATH="/home/codimd/.npm-global/bin:${PATH}"
# setup isolated user for more security
ARG USER_NAME=codimd
ARG UID=1500
ARG GID=1500
RUN set +x -ue && \
wget https://github.com/hackmdio/portchecker/releases/download/v1.0.1/portchecker-linux-amd64.tar.gz && \
tar xvf portchecker-linux-amd64.tar.gz -C /usr/local/bin && \
mv /usr/local/bin/portchecker-linux-amd64 /usr/local/bin/pcheck && \
# Add user and groupd
groupadd --gid $GID $USER_NAME && \
useradd --uid $UID --gid $USER_NAME --no-log-init --create-home $USER_NAME && \
# setup local npm global directory
mkdir /home/codimd/.npm-global && \
echo "prefix=/home/codimd/.npm-global/" > /home/codimd/.npmrc && \
# setup app dir
mkdir /codimd && \
# adjust permission
chown -R $USER_NAME:$USER_NAME /home/codimd
# Copy build stage file to runtime
COPY --from=BUILD /codimd /codimd
RUN chown -R $USER_NAME:$USER_NAME /codimd
# change running user name
USER $USER_NAME
# build project
WORKDIR /codimd
RUN set +x -ue && \
cliVer=$(cat package.json | grep sequelize-cli | awk '{print substr($1, 2, length($1) - 3)"@"substr($2, 2, length($2) - 3)}') && \
npm -g install "$cliVer" && \
yarn install --production --non-interactive --pure-lockfile && \
yarn cache clean
VOLUME /codimd/public/uploads
EXPOSE 3000
ENTRYPOINT ["/codimd/docker-entrypoint.sh"]

View File

@ -0,0 +1,7 @@
FROM node:8.15.1-jessie
WORKDIR /codimd
EXPOSE 3000
VOLUME ['/codimd/node_modules']

View File

@ -0,0 +1,25 @@
version: '3'
services:
dev-database:
image: postgres:11.2
environment:
POSTGRES_USER: codimd
POSTGRES_PASSWORD: password
POSTGRES_DB: codimd
dev-codimd:
build:
dockerfile: ./deployments/dev-Dockerfile
context: ../
environment:
CMD_DB_URL: postgres://codimd:password@dev-database/codimd
volumes:
- ../:/codimd
- node_modules:/codimd/node_modules
- public_build:/codimd/public/build
- public_view_build:/codimd/public/views/build
ports:
- 3000:3000
volumes:
node_modules:
public_build:
public_view_build:

View File

@ -0,0 +1,16 @@
version: '3'
services:
database:
image: postgres:11.2
environment:
POSTGRES_USER: codimd
POSTGRES_PASSWORD: password
POSTGRES_DB: codimd
codimd:
build:
dockerfile: ./deployments/Dockerfile
context: ../
environment:
CMD_DB_URL: postgres://codimd:password@database/codimd
ports:
- 3000:3000

View File

@ -0,0 +1,9 @@
#!/bin/bash
set -euo pipefail
pcheck -constr "$CMD_DB_URL"
sequelize db:migrate
node app.js

View File

@ -82,7 +82,7 @@ class RealtimeClientConnection {
}
async changeNotePermission (newPermission) {
const changedRows = await models.Note.update({
const [changedRows] = await models.Note.update({
permission: newPermission
}, {
where: {