diff --git a/tx-etherpad/Dockerfile b/tx-etherpad/Dockerfile index 82cb31852f15291da391356abf91af6bb85fac2a..0ff1708220f9e0f5bf2a33ac83afa73a2c930a79 100644 --- a/tx-etherpad/Dockerfile +++ b/tx-etherpad/Dockerfile @@ -1,27 +1,36 @@ FROM tx-debian:latest -MAINTAINER antoinebarbare@gmail.com +MAINTAINER antoine@barbare.me -#Installation de NodeJS + NPM -RUN echo "deb http://ftp.us.debian.org/debian wheezy-backports main" >> /etc/apt/sources.list -RUN DEBIAN_FRONTEND=noninteactive apt-get -y update -RUN apt-get install -y curl nodejs-legacy +ENV ETHERPAD_VERSION 1.6.0 -RUN curl -L --insecure -O https://www.npmjs.org/install.sh \ - && /bin/bash install.sh \ +RUN apt-get update && \ + apt-get install -y unzip nodejs-legacy npm mysql-client supervisor && \ + rm -r /var/lib/apt/lists/* -RUN apt-get install gzip git curl python libssl-dev pkg-config build-essential +WORKDIR /opt/ -#Installation Etherpad -WORKDIR /opt -RUN git clone 'git://github.com/ether/etherpad-lite.git' -WORKDIR /opt/etherpad-lite -RUN git checkout develop && rm -Rf src/node_modules +RUN curl -SL \ + https://github.com/ether/etherpad-lite/archive/${ETHERPAD_VERSION}.zip \ + > etherpad.zip && unzip etherpad && rm etherpad.zip && \ + mv etherpad-lite-${ETHERPAD_VERSION} etherpad-lite -ADD add/settings.json /opt/etherpad-lite/settings.json +WORKDIR etherpad-lite #First starting of services -RUN /opt/etherpad-lite/bin/installDeps.sh +RUN bin/installDeps.sh && rm settings.json +RUN ln -s var/settings.json settings.json -EXPOSE 80 +#Copy configuration +COPY add/entrypoint.sh /entrypoint.sh +COPY add/supervisord.conf /etc/supervisord.conf + +RUN chmod +x /entrypoint.sh + +#Set settings based on evironement variables +ENTRYPOINT ["/entrypoint.sh"] -CMD /opt/etherpad-lite/bin/run.sh --root +#Start Etherpad with supervisor +CMD /usr/bin/supervisord -c /etc/supervisord.conf + +EXPOSE 80 +VOLUME /opt/etherpad-lite/var diff --git a/tx-etherpad/add/entrypoint.sh b/tx-etherpad/add/entrypoint.sh new file mode 100644 index 0000000000000000000000000000000000000000..f9b5fc80fbe1a3a9d28d7f3b46303feb2f69a5c4 --- /dev/null +++ b/tx-etherpad/add/entrypoint.sh @@ -0,0 +1,82 @@ +#!/bin/bash +set -e + +if [ -z "$MYSQL_PORT_3306_TCP_ADDR" ]; then + echo >&2 'error: missing MYSQL_PORT_3306_TCP environment variable' + echo >&2 ' Did you forget to --link some_mysql_container:mysql ?' + exit 1 +fi + +# if we're linked to MySQL, and we're using the root user, and our linked +# container has a default "root" password set up and passed through... :) +: ${ETHERPAD_DB_USER:=root} +if [ "$ETHERPAD_DB_USER" = 'root' ]; then + : ${ETHERPAD_DB_PASSWORD:=$MYSQL_ENV_MYSQL_ROOT_PASSWORD} +fi +: ${ETHERPAD_DB_NAME:=etherpad} + +ETHERPAD_DB_NAME=$( echo $ETHERPAD_DB_NAME | sed 's/\./_/g' ) + +if [ -z "$ETHERPAD_DB_PASSWORD" ]; then + echo >&2 'error: missing required ETHERPAD_DB_PASSWORD environment variable' + echo >&2 ' Did you forget to -e ETHERPAD_DB_PASSWORD=... ?' + echo >&2 + echo >&2 ' (Also of interest might be ETHERPAD_DB_USER and ETHERPAD_DB_NAME.)' + exit 1 +fi + +: ${ETHERPAD_TITLE:=Etherpad} +: ${ETHERPAD_PORT:=80} +: ${ETHERPAD_SESSION_KEY:=$( + node -p "require('crypto').randomBytes(32).toString('hex')")} + +# Check if database already exists +RESULT=`mysql -u${ETHERPAD_DB_USER} -p${ETHERPAD_DB_PASSWORD} \ + -hmysql --skip-column-names \ + -e "SHOW DATABASES LIKE '${ETHERPAD_DB_NAME}'"` + +if [ "$RESULT" != $ETHERPAD_DB_NAME ]; then + # mysql database does not exist, create it + echo "Creating database ${ETHERPAD_DB_NAME}" + + mysql -u${ETHERPAD_DB_USER} -p${ETHERPAD_DB_PASSWORD} -hmysql \ + -e "create database ${ETHERPAD_DB_NAME}" +fi + +if [ ! -f settings.json ]; then + + cat <<- EOF > settings.json + { + "title": "${ETHERPAD_TITLE}", + "ip": "0.0.0.0", + "port" :${ETHERPAD_PORT}, + "sessionKey" : "${ETHERPAD_SESSION_KEY}", + "dbType" : "mysql", + "dbSettings" : { + "user" : "${ETHERPAD_DB_USER}", + "host" : "mysql", + "password": "${ETHERPAD_DB_PASSWORD}", + "database": "${ETHERPAD_DB_NAME}" + }, + EOF + + if [ $ETHERPAD_ADMIN_PASSWORD ]; then + + : ${ETHERPAD_ADMIN_USER:=admin} + + cat <<- EOF >> settings.json + "users": { + "${ETHERPAD_ADMIN_USER}": { + "password": "${ETHERPAD_ADMIN_PASSWORD}", + "is_admin": true + } + }, + EOF + fi + + cat <<- EOF >> settings.json + } + EOF +fi + +exec "$@" diff --git a/tx-etherpad/add/supervisord.conf b/tx-etherpad/add/supervisord.conf new file mode 100644 index 0000000000000000000000000000000000000000..ad31835bd660256110732426f11342b218e368f9 --- /dev/null +++ b/tx-etherpad/add/supervisord.conf @@ -0,0 +1,5 @@ +[supervisord] +nodaemon=true + +[program:etherpad] +command=/bin/bash -c "/opt/etherpad-lite/bin/run.sh --root"