From bb256b8027463fa8b5440accaeab7168e4bb5740 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Gl=C3=A4=C3=9Fle?= Date: Sat, 8 Apr 2017 12:28:19 +0200 Subject: [PATCH 1/4] Fix startup bug due to old node version Solution as suggested by @kpcyrd. Fixed behaviour: $ docker logs /cryptpad/server.js:44 for (let header in h) { res.setHeader(header, h[header]); } ^^^ SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode at exports.runInThisContext (vm.js:53:16) at Module._compile (module.js:374:25) at Object.Module._extensions..js (module.js:417:10) at Module.load (module.js:344:32) at Function.Module._load (module.js:301:12) at Function.Module.runMain (module.js:442:10) at startup (node.js:136:18) at node.js:966:3 --- Dockerfile | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 99b915055..bb249cce1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,4 @@ -FROM ubuntu:16.04 - -RUN apt-get update && apt-get install -y \ - vim \ - wget \ - git \ - curl \ - npm \ - nodejs-legacy +FROM node:6 ARG VERSION=0.3.0 @@ -40,4 +32,4 @@ ENV USE_SSL=false ENV STORAGE='./storage/file' ENV LOG_TO_STDOUT=true -CMD /container-start.sh \ No newline at end of file +CMD /container-start.sh From 074f27237f02a5aa0f294cdc53ce84d99f025f6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Gl=C3=A4=C3=9Fle?= Date: Sat, 8 Apr 2017 12:40:54 +0200 Subject: [PATCH 2/4] Improve docker-related documentation - install/usage should be at the top, it's the most relevant info for typical users - docker call was missing `run` argument - added `--restart=always` to run it as a service - change default data directory. I think it's bad advice keeping data cluttered all over your file-system in some git repositories that one may want to delete later on --- cryptpad-docker.md | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/cryptpad-docker.md b/cryptpad-docker.md index 1beb2412d..d329f0354 100644 --- a/cryptpad-docker.md +++ b/cryptpad-docker.md @@ -7,6 +7,21 @@ - Adding config.js to customize folder - Persistance for datastore and customize folder +## Run + +Run from the cryptpad source directory: + +``` +docker build -t xwiki/cryptpad . +docker run --restart=always -d --name cryptpad -p 3000:3000 -v /var/cryptpad:/cryptpad/datastore xwiki/cryptpad +``` + +Or, using docker-compose + +``` +docker-compose up -d +``` + ## TODO ``` @@ -28,21 +43,6 @@ Set configurations Dockerfile or in .env (using docker-compose) file. The .env variables are read by docker-compose and forwarded to docker container. On runtime, in `bin/container-start.sh` the settings are written to the `config.js` file. -## Run - -With docker - -``` -docker build -t xwiki/cryptpad . -docker -d --name cryptpad -p 3000:3000 -v ${PWD}/data:/cryptpad/datastore xwiki/cryptpad -``` - -With docker-compose - -``` -docker-compose up -d -``` - ## Persistance From c182a407cfaa8ae9ff2d6e3c9de4f28f62ec1f69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Gl=C3=A4=C3=9Fle?= Date: Sat, 8 Apr 2017 22:08:38 +0200 Subject: [PATCH 3/4] Fix typo in container-start.sh --- container-start.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/container-start.sh b/container-start.sh index db0bb924a..60ba6de76 100644 --- a/container-start.sh +++ b/container-start.sh @@ -13,11 +13,11 @@ mkdir -p customize [[ -n "$USE_SSL" ]] && echo "Using secure websockets: $USE_SSL" \ && sed -i "s/useSecureWebsockets: .*/useSecureWebsockets: ${USE_SSL},/g" customize/config.js -[[ -n "$USE_SSL" ]] && echo "Using storage adapter: $STORAGE" \ +[[ -n "$STORAGE" ]] && echo "Using storage adapter: $STORAGE" \ && sed -i "s/storage: .*/storage: ${STORAGE},/g" customize/config.js [[ -n "$LOG_TO_STDOUT" ]] && echo "Logging to stdout: $LOG_TO_STDOUT" \ && sed -i "s/logToStdout: .*/logToStdout: ${LOG_TO_STDOUT},/g" customize/config.js -exec node ./server.js \ No newline at end of file +exec node ./server.js From 2985c6a051563cab86fcb51c6bd2ecc12becde4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Gl=C3=A4=C3=9Fle?= Date: Sun, 9 Apr 2017 11:36:33 +0200 Subject: [PATCH 4/4] Cleanup Dockerfile, thanks to @kpcyrd --- Dockerfile | 25 +++++-------------------- container-start.sh | 12 ++++++------ 2 files changed, 11 insertions(+), 26 deletions(-) mode change 100644 => 100755 container-start.sh diff --git a/Dockerfile b/Dockerfile index bb249cce1..96a5ff520 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,28 +1,13 @@ -FROM node:6 - -ARG VERSION=0.3.0 - -# Download stable version -# RUN wget https://github.com/xwiki-labs/cryptpad/archive /${VERSION}.tar.gz -O /cryptpad.tar.gz \ -# && mkdir -p /cryptpad \ -# && tar -xzf /cryptpad.tar.gz -C /cryptpad --strip-components=1 \ -# && rm /cryptpad.tar.gz - -# Download from github -# RUN git clone https://github.com/xwiki-labs/cryptpad.git - -# Add code directly -ADD . /cryptpad +FROM node:6-alpine +COPY . /cryptpad WORKDIR /cryptpad -RUN npm install \ +RUN apk add --no-cache git tini \ + && npm install \ && npm install -g bower \ && bower install --allow-root -ADD container-start.sh /container-start.sh -RUN chmod u+x /container-start.sh - EXPOSE 3000 VOLUME /cryptpad/datastore @@ -32,4 +17,4 @@ ENV USE_SSL=false ENV STORAGE='./storage/file' ENV LOG_TO_STDOUT=true -CMD /container-start.sh +CMD ["/sbin/tini", "--", "/cryptpad/container-start.sh"] diff --git a/container-start.sh b/container-start.sh old mode 100644 new mode 100755 index 60ba6de76..89f3be1f1 --- a/container-start.sh +++ b/container-start.sh @@ -1,22 +1,22 @@ -#!/bin/bash +#!/bin/sh # Creating customize folder mkdir -p customize -[[ ! "$(ls -A customize)" ]] && echo "Creating customize folder" \ +[ -z "$(ls -A customize)" ] && echo "Creating customize folder" \ && cp -R customize.dist/* customize/ \ && cp config.js.dist customize/config.js # Linking config.js -[[ ! -h config.js ]] && echo "Linking config.js" && ln -s customize/config.js config.js +[ ! -h config.js ] && echo "Linking config.js" && ln -s customize/config.js config.js # Configure -[[ -n "$USE_SSL" ]] && echo "Using secure websockets: $USE_SSL" \ +[ -n "$USE_SSL" ] && echo "Using secure websockets: $USE_SSL" \ && sed -i "s/useSecureWebsockets: .*/useSecureWebsockets: ${USE_SSL},/g" customize/config.js -[[ -n "$STORAGE" ]] && echo "Using storage adapter: $STORAGE" \ +[ -n "$STORAGE" ] && echo "Using storage adapter: $STORAGE" \ && sed -i "s/storage: .*/storage: ${STORAGE},/g" customize/config.js -[[ -n "$LOG_TO_STDOUT" ]] && echo "Logging to stdout: $LOG_TO_STDOUT" \ +[ -n "$LOG_TO_STDOUT" ] && echo "Logging to stdout: $LOG_TO_STDOUT" \ && sed -i "s/logToStdout: .*/logToStdout: ${LOG_TO_STDOUT},/g" customize/config.js