From 1783d5a00af54651086ed28fc8a812b7dd333cd7 Mon Sep 17 00:00:00 2001 From: Miguel Laginha Date: Thu, 23 Nov 2017 11:16:08 +0000 Subject: [PATCH] Moved to alpine linux New base image Some refactoring --- Dockerfile | 178 ++++++++++++++++---------------------------------- README.md | 6 +- entrypoint.sh | 35 ++++++++++ 3 files changed, 96 insertions(+), 123 deletions(-) create mode 100644 entrypoint.sh diff --git a/Dockerfile b/Dockerfile index ed78699..fc6c7a4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,144 +22,82 @@ # $ docker run -it --name=etherpad --net=host oae-etherpad:latest # -FROM buildpack-deps:jessie-scm -LABEL Name=hilary Version=12.5.0 -MAINTAINER Apereo Foundation - -# node -RUN apt-get update && apt-get install -y --no-install-recommends \ - autoconf \ - automake \ - bzip2 \ - file \ - g++ \ - gcc \ - git \ - graphicsmagick \ - libbz2-dev \ - libc6-dev \ - libcurl4-openssl-dev \ - libevent-dev \ - libffi-dev \ - libgeoip-dev \ - libglib2.0-dev \ - libjpeg-dev \ - liblzma-dev \ - libmagickcore-dev \ - libmagickwand-dev \ - libmysqlclient-dev \ - libncurses-dev \ - libpng-dev \ - libpq-dev \ - libreadline-dev \ - libsqlite3-dev \ - libssl-dev \ - libtool \ - libwebp-dev \ - libxml2-dev \ - libxslt-dev \ - libyaml-dev \ - make \ - patch \ - python-pip \ - xz-utils \ - zlib1g-dev \ - && rm -rf /var/lib/apt/lists/* - -RUN groupadd --gid 1000 node \ - && useradd --uid 1000 --gid node --shell /bin/bash --create-home node - -# gpg keys listed at https://github.com/nodejs/node -RUN set -ex \ - && for key in \ - 9554F04D7259F04124DE6B476D5A82AC7E37093B \ - 94AE36675C464D64BAFA68DD7434390BDBE9B9C5 \ - 0034A06D9D9B0064CE8ADF6BF1747F4AD2306D93 \ - FD3A5288F042B6850C66B31F09FE44734EB7990E \ - 71DCFD284A79C3B38668286BC97EC7A07EDE3FC1 \ - DD8F2338BAE7501E3DD5AC78C273792F7D83545D \ - B9AE9905FFD7803F25714661B63B535A4C206CA9 \ - C4F0DFFF4E8C1A8236409D08E73BC641CC11F4C8 \ - 56730D5401028683275BD23C23EFEFE93C4CFFFE \ - ; do \ - gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \ - done - -ENV NPM_CONFIG_LOGLEVEL info -ENV NODE_VERSION 6.10.0 - -RUN curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.xz" \ - && curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/SHASUMS256.txt.asc" \ - && gpg --batch --decrypt --output SHASUMS256.txt SHASUMS256.txt.asc \ - && grep " node-v$NODE_VERSION-linux-x64.tar.xz\$" SHASUMS256.txt | sha256sum -c - \ - && tar -xJf "node-v$NODE_VERSION-linux-x64.tar.xz" -C /usr/local --strip-components=1 \ - && rm "node-v$NODE_VERSION-linux-x64.tar.xz" SHASUMS256.txt.asc SHASUMS256.txt \ - && ln -s /usr/local/bin/node /usr/local/bin/nodejs - -ENV YARN_VERSION 0.21.3 - -RUN set -ex \ - && for key in \ - 6A010C5166006599AA17F08146C2130DFD2497F5 \ - ; do \ - gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \ - done \ - && curl -fSL -o yarn.js "https://yarnpkg.com/downloads/$YARN_VERSION/yarn-legacy-$YARN_VERSION.js" \ - && curl -fSL -o yarn.js.asc "https://yarnpkg.com/downloads/$YARN_VERSION/yarn-legacy-$YARN_VERSION.js.asc" \ - && gpg --batch --verify yarn.js.asc yarn.js \ - && rm yarn.js.asc \ - && mv yarn.js /usr/local/bin/yarn \ - && chmod +x /usr/local/bin/yarn - -# install etherpad and apply configuration -RUN mkdir -p /opt && cd /opt -WORKDIR /opt/ -RUN git clone https://github.com/ether/etherpad-lite.git etherpad && cd etherpad && mv settings.json.template settings.json && touch APIKEY.txt - -WORKDIR /opt/etherpad/ - -# Install node dependencies -RUN /opt/etherpad/bin/installDeps.sh +# FROM alpine:3.6 +FROM node:6.12.0-alpine +LABEL Name=AlpineDockerEtherpad +LABEL Author=ApereoFoundation +LABEL Email=oae@apereo.org -# Next two lines are production config ONLY -RUN sed -i -e 's/dbType\" : \"dirty/dbType\" : \"cassandra/g' settings.json -RUN sed -i -e 's/"filename" : "var\/dirty.db"/"clientOptions": {"keyspace": "etherpad", "port": "9042", "contactPoints": ["oae-cassandra"]},"columnFamily": "Etherpad"/g' settings.json - -RUN sed -i -e 's/defaultPadText" : ".*"/defaultPadText" : ""/g' settings.json -RUN echo "13SirapH8t3kxUh5T5aqWXhXahMzoZRA" > APIKEY.txt +# +# Install etherpad +# +ENV ETHERPAD_VERSION 1.6.2 +ENV ETHERPAD_PATH /opt/etherpad + +COPY entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh \ + && apk --no-cache add curl git su-exec \ + && addgroup -S -g 1001 etherpad \ + && adduser -S -u 1001 -G etherpad -G node etherpad \ + && curl -sLo /etherpad.tar.gz https://github.com/ether/etherpad-lite/archive/${ETHERPAD_VERSION}.tar.gz \ + && mkdir -p /opt \ + && tar -xz -C /opt -f /etherpad.tar.gz \ + && mv /opt/etherpad-lite-${ETHERPAD_VERSION} ${ETHERPAD_PATH} \ + && rm -f /etherpad.tar.gz \ + && sed -i -e "93 s,grep.*,grep -E -o 'v[0-9]\.[0-9](\.[0-9])?')," ${ETHERPAD_PATH}/bin/installDeps.sh \ + && sed -i -e '96 s,if.*,if [ "${VERSION#v}" = "$NEEDED_VERSION" ]; then,' ${ETHERPAD_PATH}/bin/installDeps.sh \ + && ${ETHERPAD_PATH}/bin/installDeps.sh \ + && rm -rf /tmp/* +# COPY settings.json /opt/etherpad/settings.json +RUN mv ${ETHERPAD_PATH}/settings.json.template ${ETHERPAD_PATH}/settings.json +COPY init.cql ${ETHERPAD_PATH}/init.cql +RUN chown -R etherpad:etherpad ${ETHERPAD_PATH} -# We need to run a specific cqlsh command before this works -RUN pip install cqlsh -RUN echo "CREATE KEYSPACE etherpad WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};" > /tmp/.create_etherpad_keyspace.cql3 +# Next two lines are production config ONLY +RUN sed -i -e 's/defaultPadText" : ".*"/defaultPadText" : ""/g' ${ETHERPAD_PATH}/settings.json +RUN sed -i -e 's/dbType\" : \"dirty/dbType\" : \"cassandra/g' ${ETHERPAD_PATH}/settings.json +RUN sed -i -e 's/"filename" : "var\/dirty.db"/"clientOptions": {"keyspace": "etherpad", "port": 9160, "contactPoints": ["oae-cassandra"]},"columnFamily": "Etherpad"/g' ${ETHERPAD_PATH}/settings.json # Install ep_headings module -RUN cd /opt/etherpad && npm install ep_headings +RUN cd ${ETHERPAD_PATH} && npm install ep_headings # Etherpad OAE plugin -RUN cd /opt/etherpad/node_modules && git clone https://github.com/oaeproject/ep_oae && cd ep_oae && npm install +RUN cd ${ETHERPAD_PATH}/node_modules \ + && git clone https://github.com/oaeproject/ep_oae \ + && cd ep_oae \ + && npm install # Not strictly necessary if we're using default IP and port RUN sed -i -e '/defaultPadText/a \ - "ep_oae": {"mq": { "host": "oae-rabbitmq", "port": 5672 } },' settings.json + "ep_oae": {"mq": { "host": "oae-rabbitmq", "port": 5672 } },' ${ETHERPAD_PATH}/settings.json # CSS changes -RUN cd /opt/etherpad && rm node_modules/ep_headings/templates/editbarButtons.ejs && cp node_modules/ep_oae/static/templates/editbarButtons.ejs node_modules/ep_headings/templates/editbarButtons.ejs -RUN cd /opt/etherpad/ && rm src/static/custom/pad.css && cp node_modules/ep_oae/static/css/pad.css src/static/custom/pad.css +RUN rm ${ETHERPAD_PATH}/node_modules/ep_headings/templates/editbarButtons.ejs && cp ${ETHERPAD_PATH}/node_modules/ep_oae/static/templates/editbarButtons.ejs ${ETHERPAD_PATH}/node_modules/ep_headings/templates/editbarButtons.ejs +RUN rm ${ETHERPAD_PATH}/src/static/custom/pad.css && cp ${ETHERPAD_PATH}/node_modules/ep_oae/static/css/pad.css ${ETHERPAD_PATH}/src/static/custom/pad.css # Edit protocols in config -RUN sed -i -e 's/\["xhr-polling", "jsonp-polling", "htmlfile"\],/\["websocket", "xhr-polling", "jsonp-polling", "htmlfile"\],/g' settings.json +RUN sed -i -e 's/\["xhr-polling", "jsonp-polling", "htmlfile"\],/\["websocket", "xhr-polling", "jsonp-polling", "htmlfile"\],/g' ${ETHERPAD_PATH}/settings.json # Edit toolbar in config RUN sed -i -e '/"loadTest/a \ -"toolbar": {"left": [["bold", "italic", "underline", "strikethrough", "orderedlist", "unorderedlist", "indent", "outdent"]],"right": [["showusers"]]},' settings.json + "toolbar": {"left": [["bold", "italic", "underline", "strikethrough", "orderedlist", "unorderedlist", "indent", "outdent"]],"right": [["showusers"]]},' ${ETHERPAD_PATH}/settings.json -EXPOSE 9001 -RUN groupadd --gid 1001 etherpad && useradd --uid 1001 --gid etherpad --shell /bin/bash --create-home etherpad +# We need to run a specific cqlsh command before this works +RUN apk --no-cache add python py-pip git bash +RUN pip install cqlsh==4.0.1 +RUN pip install thrift==0.9.3 +RUN echo "CREATE KEYSPACE IF NOT EXISTS etherpad WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};" > ${ETHERPAD_PATH}/init.cql -CMD cqlsh -f /tmp/.create_etherpad_keyspace.cql3 oae-cassandra 9042 && bin/run.sh --root -# CMD ["bin/run.sh", "--root"] +# miguel addon +# USER etherpad -# TODO try to run this as non-root if possible -# CMD ["su", "-", "etherpad", "-c", "/bin/sh /opt/etherpad/bin/run.sh"] +# debug and experimental +RUN echo "13SirapH8t3kxUh5T5aqWXhXahMzoZRA" > ${ETHERPAD_PATH}/APIKEY.txt +EXPOSE 9001 +# ENTRYPOINT ["/bin/bash", "/entrypoint.sh"] +ENTRYPOINT ["/entrypoint.sh"] +CMD ["/opt/etherpad/bin/run.sh"] +# CMD cqlsh -f ${ETHERPAD_PATH}/init.cql oae-cassandra 9160 && ${ETHERPAD_PATH}/bin/run.sh +# CMD ["cqlsh", "-f", "/opt/etherpad/init.cql", "oae-cassandra", "9160", "&&", "${ETHERPAD_PATH}/bin/run.sh"] \ No newline at end of file diff --git a/README.md b/README.md index 29b227c..31bf54a 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ -# oae-etherpad +# Etherpad docker image -Adapted version of etherpad-lite integrated in OAE project +Adapted version of etherpad-lite for OAE. ## Usage ### Run from dockerhub ``` -docker run -it --name=etherpad --net=host oaeproject/oae-etherpad +docker run -it --name=etherpad --net=host oaeproject/oae-etherpad-docker ``` ### Build the image locally diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..e3ab4cd --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,35 @@ +# +# Copyright 2017 Apereo Foundation (AF) Licensed under the +# Educational Community License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may +# obtain a copy of the License at +# +# http://opensource.org/licenses/ECL-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an "AS IS" +# BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express +# or implied. See the License for the specific language governing +# permissions and limitations under the License. +# + +#!/bin/bash +set -e + +EP=/opt/etherpad + +random_key() { + dd if=/dev/urandom bs=64 count=1 2>/dev/null|sha256sum|cut -d' ' -f1|tr -d '\n' +} + +cqlsh -f /opt/etherpad/init.cql oae-cassandra 9160 + +if [ "$EP/bin/run.sh" = "$1" ]; then + [ -r $EP/APIKEY.txt ] || random_key > $EP/APIKEY.txt + [ -r $EP/SESSIONKEY.txt ] || random_key > $EP/SESSIONKEY.txt + # touch $EP/node_modules/ep_etherpad-lite/.ep_initialized + chown -R etherpad:etherpad $EP/settings.json $EP/var + exec su-exec etherpad "$@" +fi + +exec "$@" \ No newline at end of file