Skip to content

Commit 0f51d1e

Browse files
committed
fix: change note permission cause error
Signed-off-by: BoHong Li <raccoon@hackmd.io>
1 parent b41de78 commit 0f51d1e

File tree

7 files changed

+122
-1
lines changed

7 files changed

+122
-1
lines changed

.dockerignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.git/
2+
node_modules/
3+
docs/
4+
test/
5+
.sequelizerc.example
6+
config.json.example
7+
public/build
8+

deployments/Dockerfile

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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"]

deployments/dev-Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM node:8.15.1-jessie
2+
3+
WORKDIR /codimd
4+
5+
EXPOSE 3000
6+
7+
VOLUME ['/codimd/node_modules']

deployments/dev-docker-compose.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
version: '3'
2+
services:
3+
dev-database:
4+
image: postgres:11.2
5+
environment:
6+
POSTGRES_USER: codimd
7+
POSTGRES_PASSWORD: password
8+
POSTGRES_DB: codimd
9+
dev-codimd:
10+
build:
11+
dockerfile: ./deployments/dev-Dockerfile
12+
context: ../
13+
environment:
14+
CMD_DB_URL: postgres://codimd:password@dev-database/codimd
15+
volumes:
16+
- ../:/codimd
17+
- node_modules:/codimd/node_modules
18+
- public_build:/codimd/public/build
19+
- public_view_build:/codimd/public/views/build
20+
ports:
21+
- 3000:3000
22+
volumes:
23+
node_modules:
24+
public_build:
25+
public_view_build:

deployments/docker-compose.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
version: '3'
2+
services:
3+
database:
4+
image: postgres:11.2
5+
environment:
6+
POSTGRES_USER: codimd
7+
POSTGRES_PASSWORD: password
8+
POSTGRES_DB: codimd
9+
codimd:
10+
build:
11+
dockerfile: ./deployments/Dockerfile
12+
context: ../
13+
environment:
14+
CMD_DB_URL: postgres://codimd:password@database/codimd
15+
ports:
16+
- 3000:3000

deployments/docker-entrypoint.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
pcheck -constr "$CMD_DB_URL"
6+
7+
sequelize db:migrate
8+
9+
node app.js

lib/realtimeClientConnection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class RealtimeClientConnection {
8282
}
8383

8484
async changeNotePermission (newPermission) {
85-
const changedRows = await models.Note.update({
85+
const [changedRows] = await models.Note.update({
8686
permission: newPermission
8787
}, {
8888
where: {

0 commit comments

Comments
 (0)