Added URL parser

This commit is contained in:
Glenn Y. Rolland 2017-07-07 15:02:43 +02:00
parent a17d1184fe
commit ce668be090
4 changed files with 211 additions and 1 deletions

33
Dockerfile Normal file
View file

@ -0,0 +1,33 @@
# Stable version of etherpad doesn't support npm 2
FROM debian:jessie
MAINTAINER Tony Motakis <tvelocity@gmail.com>
ENV ETHERPAD_VERSION 1.6.1
RUN apt-get update && \
apt-get install -y curl unzip nodejs-legacy npm mysql-client && \
rm -r /var/lib/apt/lists/*
WORKDIR /opt/
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
WORKDIR etherpad-lite
RUN bin/installDeps.sh && rm settings.json
COPY entrypoint.sh /entrypoint.sh
COPY parseurl.py /parseurl.py
RUN sed -i 's/^node/exec\ node/' bin/run.sh
VOLUME /opt/etherpad-lite/var
RUN ln -s var/settings.json settings.json
EXPOSE 9001
ENTRYPOINT ["/entrypoint.sh"]
CMD ["bin/run.sh", "--root"]

View file

@ -1 +1,74 @@
# My project's README # Etherpad Lite image for docker
This is a docker image for [Etherpad Lite](http://etherpad.org/) collaborative
text editor. The Dockerfile for this image has been inspired by the
[official Wordpress](https://registry.hub.docker.com/_/wordpress/) Dockerfile and
[johbo's etherpad-lite](https://registry.hub.docker.com/u/johbo/etherpad-lite/)
image.
This image uses an mysql container for the backend for the pads. It is based
on debian jessie instead of the official node docker image, since the latest
stable version of etherpad-lite does not support npm 2.
## About Etherpad Lite
> *From the official website:*
Etherpad allows you to edit documents collaboratively in real-time, much like a live multi-player editor that runs in your browser. Write articles, press releases, to-do lists, etc. together with your friends, fellow students or colleagues, all working on the same document at the same time.
![alt text](http://i.imgur.com/zYrGkg3.gif "Etherpad in action on PrimaryPad")
All instances provide access to all data through a well-documented API and supports import/export to many major data exchange formats. And if the built-in feature set isn't enough for you, there's tons of plugins that allow you to customize your instance to suit your needs.
You don't need to set up a server and install Etherpad in order to use it. Just pick one of publicly available instances that friendly people from everywhere around the world have set up. Alternatively, you can set up your own instance by following our installation guide
## Quickstart
First you need a running mysql container, for example:
```bash
$ docker network create ep_network
$ docker run -d --network ep_network -e MYSQL_ROOT_PASSWORD=password --name ep_mysql mysql
```
Finally you can start an instance of Etherpad Lite:
```bash
$ docker run -d \
--network ep_network \
-e ETHERPAD_DB_HOST=ep_mysql \
-e ETHERPAD_DB_PASSWORD=password \
-p 9001:9001 \
tvelocity/etherpad-lite
```
Etherpad will automatically create an `etherpad` database in the specified mysql
server if it does not already exist.
You can now access Etherpad Lite from http://localhost:9001/
## Environment variables
This image supports the following environment variables:
* `ETHERPAD_TITLE`: Title of the Etherpad Lite instance. Defaults to "Etherpad".
* `ETHERPAD_PORT`: Port of the Etherpad Lite instance. Defaults to 9001.
* `ETHERPAD_SESSION_KEY`: Session key for the Etherpad Lite configuraition. You
can set this in case of migrating from another installation. A value is
automatically generated by default.
* `ETHERPAD_ADMIN_PASSWORD`: If set, an admin account is enabled for Etherpad,
and the /admin/ interface is accessible via it.
* `ETHERPAD_ADMIN_USER`: If the admin password is set, this defaults to "admin".
Otherwise the user can set it to another username.
* `ETHERPAD_DB_HOST`: Hostname of the mysql databse to use. Defaults to `mysql`
* `ETHERPAD_DB_USER`: By default Etherpad Lite will attempt to connect as root
to the mysql container.
* `ETHERPAD_DB_PASSWORD`: MySQL password to use, mandatory. If legacy links
are used and ETHERPAD_DB_USER is root, then `MYSQL_ENV_MYSQL_ROOT_PASSWORD` is
automatically used.
* `ETHERPAD_DB_NAME`: The mysql database to use. Defaults to *etherpad*. If the
database is not available, it will be created when the container is launched.
The generated settings.json file will be available as a volume under
*/opt/etherpad-lite/var/*.

81
entrypoint.sh Normal file
View file

@ -0,0 +1,81 @@
#!/bin/bash
set -e
chmod +x parseurl.py
eval $(./parseurl.py)
: ${ETHERPAD_DB_HOST:=mysql}
: ${ETHERPAD_DB_USER:=root}
: ${ETHERPAD_DB_NAME:=etherpad}
ETHERPAD_DB_NAME=$( echo $ETHERPAD_DB_NAME | sed 's/\./_/g' )
# 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
# using the password from the env variable MYSQL_ENV_MYSQL_ROOT_PASSWORD
if [ "$ETHERPAD_DB_USER" = 'root' ]; then
: ${ETHERPAD_DB_PASSWORD:=$MYSQL_ENV_MYSQL_ROOT_PASSWORD}
fi
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:=9001}
: ${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} \
-h${ETHERPAD_DB_HOST} --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} -h${ETHERPAD_DB_HOST} \
-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" : "${ETHERPAD_DB_HOST}",
"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 "$@"

23
parseurl.py Executable file
View file

@ -0,0 +1,23 @@
#!/usr/bin/env python
import sys
import os
from urlparse import urlparse
prefix = sys.argv[1]
uri = os.environ['DATABASE_URL']
result = urlparse(uri)
credential, machine = result.netloc.split('@')
username, password = credential.split(':')
host, port = machine.split(':')
path = result.path
print(prefix, 'SCHEME=', result.scheme)
print(prefix, 'USERNAME=', username)
print(prefix, 'PASSWORD=', password)
print(prefix, 'HOST=', host)
print(prefix, 'PORT=', port)
print(prefix, 'PATH=', path)
print(prefix, 'QUERY=', result.query)
print(prefix, 'FRAGMENT=', result.fragment)