From e08cd16366f16e8cfff81035e5742eafa6010735 Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Sat, 23 Feb 2019 17:58:58 +0100 Subject: [PATCH] Fix service provisioning --- Dockerfile | 26 +++++++++--------- Makefile | 6 ++-- docker-compose.yml | 25 +++++++++++++++++ entrypoint.sh | 68 ++++++++++++++++++++++++++++++++++------------ 4 files changed, 93 insertions(+), 32 deletions(-) create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile index 5f12671..aa53b69 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,12 @@ # Stable version of etherpad doesn't support npm 2 -FROM debian:jessie -MAINTAINER Tony Motakis +FROM node:11-slim +MAINTAINER Glenn Y. Rolland -ENV ETHERPAD_VERSION 1.6.1 +ENV ETHERPAD_VERSION 1.7.5 RUN apt-get update && \ - apt-get install -y curl unzip nodejs-legacy npm mysql-client && \ + apt-get install -y curl unzip mysql-client python netcat && \ rm -r /var/lib/apt/lists/* WORKDIR /opt/ @@ -17,20 +17,20 @@ RUN curl -SL \ rm etherpad.zip && \ mv etherpad-lite-${ETHERPAD_VERSION} etherpad-lite -WORKDIR etherpad-lite +WORKDIR /opt/etherpad-lite -RUN bin/installDeps.sh && rm settings.json -COPY entrypoint.sh /entrypoint.sh COPY parseurl.py /parseurl.py -RUN chmod +x /entrypoint.sh +COPY entrypoint.sh /entrypoint.sh -RUN sed -i 's/^node/exec\ node/' bin/run.sh +# Pre-install +RUN bin/installDeps.sh && rm settings.json && \ + chmod +x /entrypoint.sh && \ + sed -i 's/^node/exec\ node/' bin/run.sh && \ + ln -s var/settings.json settings.json && \ + npm install ep_author_neat ep_headings2 ep_set_title_on_pad ep_adminpads ep_mypads VOLUME /opt/etherpad-lite/var -RUN ln -s var/settings.json settings.json - -RUN npm install ep_author_neat ep_headings2 ep_set_title_on_pad ep_adminpads - EXPOSE 9001 ENTRYPOINT ["/entrypoint.sh"] CMD ["bin/run.sh", "--root"] + diff --git a/Makefile b/Makefile index db26441..c996fe3 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,17 @@ +NAME=$(shell basename "$$(pwd)") + all: build run # --build-arg "BUNDLE_BITBUCKET__ORG=$(BUNDLE_BITBUCKET__ORG)" \ build: - docker build -t dt-service-pad . + docker build -t "$(NAME)" . run: docker run --rm -p 9001:9001 \ -e DATABASE_URL="mysql://user:foo@databasehost/database?options" \ - -t dt-service-pad \ + -t "$(NAME)" \ # diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..0bfee44 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,25 @@ +version: "3" +services: + db: + image: mariadb:10.3 + volumes: + - ./data/db:/var/lib/mysql + environment: + MYSQL_ROOT_PASSWORD: insecure + MYSQL_DATABASE: etherpad + + etherpad: + build: . + environment: + DATABASE_URL: mysql://root:insecure@db/etherpad + ETHERPAD_ADMIN_USER: admin + ETHERPAD_ADMIN_PASSWORD: insecure + NODE_ENV: production + ports: + - "9001:9001" + depends_on: + - "db" + +# volumes: +# - data/etherpad:/var/www/html/documents + diff --git a/entrypoint.sh b/entrypoint.sh index e9317d9..b6e19bd 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,9 +1,9 @@ -#!/bin/bash +#!/bin/sh set -e chmod +x /parseurl.py /parseurl.py ETHERPAD_DB_ -eval $(/parseurl.py ETHERPAD_DB_) +eval "$(/parseurl.py ETHERPAD_DB_)" # ETHERPAD_DB_PASSWORD is mandatory in mysql container, so we're not offering # any default. If we're linked to MySQL through legacy link, then we can try @@ -24,26 +24,49 @@ if [ -z "$ETHERPAD_DB_PASSWORD" ]; then exit 1 fi -: ${ETHERPAD_TITLE:=Etherpad} -: ${ETHERPAD_PORT:=9001} -: ${ETHERPAD_SESSION_KEY:=$( - node -p "require('crypto').randomBytes(32).toString('hex')")} +RANDOM_STRING="$(node -p "require('crypto').randomBytes(32).toString('hex')")}" + +# Sanitize DB information +ETHERPAD_DB_HOST="${ETHERPAD_DB_HOST:-}" +ETHERPAD_DB_PORT="${ETHERPAD_DB_PORT:-3306}" + +# Sanitize etherpad info +ETHERPAD_PORT="${ETHERPAD_PORT:-9001}" +ETHERPAD_SESSION_KEY="${ETHERPAD_SESSION_KEY:-$RANDOM_STRING}" +ETHERPAD_TITLE="${ETHERPAD_TITLE:-Etherpad}" + +# Wait for database +echo "Waiting MySQL/MariaDB to be available on port 3306..." + +while ! nc -z "${ETHERPAD_DB_HOST}" "${ETHERPAD_DB_PORT}" ; do + sleep 1 # wait for 1/10 of the second before check again +done + +echo "Service MySQL/MariaDB seems ready" +sleep 1 # Check if database already exists -RESULT=`mysql -u${ETHERPAD_DB_USERNAME} -p${ETHERPAD_DB_PASSWORD} \ - -h${ETHERPAD_DB_HOST} --skip-column-names \ - -e "SHOW DATABASES LIKE '${ETHERPAD_DB_NAME}'"` +RESULT="$(mysql \ + "-u${ETHERPAD_DB_USERNAME}" \ + "-p${ETHERPAD_DB_PASSWORD}" \ + "-P${ETHERPAD_DB_PORT}" \ + "-h${ETHERPAD_DB_HOST}" \ + --skip-column-names \ + -e "SHOW DATABASES LIKE '${ETHERPAD_DB_NAME}'")" -if [ "$RESULT" != $ETHERPAD_DB_NAME ]; then +if [ "$RESULT" != "$ETHERPAD_DB_NAME" ]; then # mysql database does not exist, create it echo "Creating database ${ETHERPAD_DB_NAME}" - mysql -u${ETHERPAD_DB_USERNAME} -p${ETHERPAD_DB_PASSWORD} -h${ETHERPAD_DB_HOST} \ - -e "create database ${ETHERPAD_DB_NAME}" + mysql "-u${ETHERPAD_DB_USERNAME}" \ + "-p${ETHERPAD_DB_PASSWORD}" \ + "-P${ETHERPAD_DB_PORT}" \ + "-h${ETHERPAD_DB_HOST}" \ + -e "create database ${ETHERPAD_DB_NAME}" fi -if [ ! -f settings.json ]; then - +if ! [ -f settings.json ]; then + echo "Creating database configuration" cat <<- EOF > settings.json { "title": "${ETHERPAD_TITLE}", @@ -59,9 +82,9 @@ if [ ! -f settings.json ]; then }, EOF - if [ $ETHERPAD_ADMIN_PASSWORD ]; then - - : ${ETHERPAD_ADMIN_USER:=admin} + if [ -n "$ETHERPAD_ADMIN_PASSWORD" ]; then + ETHERPAD_ADMIN_USER="${ETHERPAD_ADMIN_USER:-admin}" + echo "Creating admin user configuration for $ETHERPAD_ADMIN_USER/$ETHERPAD_ADMIN_PASSWORD" cat <<- EOF >> settings.json "users": { @@ -78,4 +101,15 @@ if [ ! -f settings.json ]; then EOF fi +if ! grep -q '/* GLENUX BEGIN */' src/static/css/pad.css ; then + cat >> src/static/css/pad.css <<-MARK + /* GLENUX BEGIN */ + body#innerdocbody { + font-size: 16px; + line-height: 20px + } + MARK +fi + exec "$@" +