Fix service provisioning

This commit is contained in:
Glenn Y. Rolland 2019-02-23 17:58:58 +01:00
parent d6762656d1
commit e08cd16366
4 changed files with 93 additions and 32 deletions

View file

@ -1,12 +1,12 @@
# Stable version of etherpad doesn't support npm 2 # Stable version of etherpad doesn't support npm 2
FROM debian:jessie FROM node:11-slim
MAINTAINER Tony Motakis <tvelocity@gmail.com> MAINTAINER Glenn Y. Rolland <glenux@glenux.net>
ENV ETHERPAD_VERSION 1.6.1 ENV ETHERPAD_VERSION 1.7.5
RUN apt-get update && \ 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/* rm -r /var/lib/apt/lists/*
WORKDIR /opt/ WORKDIR /opt/
@ -17,20 +17,20 @@ RUN curl -SL \
rm etherpad.zip && \ rm etherpad.zip && \
mv etherpad-lite-${ETHERPAD_VERSION} etherpad-lite 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 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 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 EXPOSE 9001
ENTRYPOINT ["/entrypoint.sh"] ENTRYPOINT ["/entrypoint.sh"]
CMD ["bin/run.sh", "--root"] CMD ["bin/run.sh", "--root"]

View file

@ -1,15 +1,17 @@
NAME=$(shell basename "$$(pwd)")
all: build run all: build run
# --build-arg "BUNDLE_BITBUCKET__ORG=$(BUNDLE_BITBUCKET__ORG)" \ # --build-arg "BUNDLE_BITBUCKET__ORG=$(BUNDLE_BITBUCKET__ORG)" \
build: build:
docker build -t dt-service-pad . docker build -t "$(NAME)" .
run: run:
docker run --rm -p 9001:9001 \ docker run --rm -p 9001:9001 \
-e DATABASE_URL="mysql://user:foo@databasehost/database?options" \ -e DATABASE_URL="mysql://user:foo@databasehost/database?options" \
-t dt-service-pad \ -t "$(NAME)" \
# #

25
docker-compose.yml Normal file
View file

@ -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

View file

@ -1,9 +1,9 @@
#!/bin/bash #!/bin/sh
set -e set -e
chmod +x /parseurl.py chmod +x /parseurl.py
/parseurl.py ETHERPAD_DB_ /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 # 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 # 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 exit 1
fi fi
: ${ETHERPAD_TITLE:=Etherpad} RANDOM_STRING="$(node -p "require('crypto').randomBytes(32).toString('hex')")}"
: ${ETHERPAD_PORT:=9001}
: ${ETHERPAD_SESSION_KEY:=$( # Sanitize DB information
node -p "require('crypto').randomBytes(32).toString('hex')")} 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 # Check if database already exists
RESULT=`mysql -u${ETHERPAD_DB_USERNAME} -p${ETHERPAD_DB_PASSWORD} \ RESULT="$(mysql \
-h${ETHERPAD_DB_HOST} --skip-column-names \ "-u${ETHERPAD_DB_USERNAME}" \
-e "SHOW DATABASES LIKE '${ETHERPAD_DB_NAME}'"` "-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 # mysql database does not exist, create it
echo "Creating database ${ETHERPAD_DB_NAME}" echo "Creating database ${ETHERPAD_DB_NAME}"
mysql -u${ETHERPAD_DB_USERNAME} -p${ETHERPAD_DB_PASSWORD} -h${ETHERPAD_DB_HOST} \ mysql "-u${ETHERPAD_DB_USERNAME}" \
-e "create database ${ETHERPAD_DB_NAME}" "-p${ETHERPAD_DB_PASSWORD}" \
"-P${ETHERPAD_DB_PORT}" \
"-h${ETHERPAD_DB_HOST}" \
-e "create database ${ETHERPAD_DB_NAME}"
fi fi
if [ ! -f settings.json ]; then if ! [ -f settings.json ]; then
echo "Creating database configuration"
cat <<- EOF > settings.json cat <<- EOF > settings.json
{ {
"title": "${ETHERPAD_TITLE}", "title": "${ETHERPAD_TITLE}",
@ -59,9 +82,9 @@ if [ ! -f settings.json ]; then
}, },
EOF EOF
if [ $ETHERPAD_ADMIN_PASSWORD ]; then if [ -n "$ETHERPAD_ADMIN_PASSWORD" ]; then
ETHERPAD_ADMIN_USER="${ETHERPAD_ADMIN_USER:-admin}"
: ${ETHERPAD_ADMIN_USER:=admin} echo "Creating admin user configuration for $ETHERPAD_ADMIN_USER/$ETHERPAD_ADMIN_PASSWORD"
cat <<- EOF >> settings.json cat <<- EOF >> settings.json
"users": { "users": {
@ -78,4 +101,15 @@ if [ ! -f settings.json ]; then
EOF EOF
fi 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 "$@" exec "$@"