diff --git a/Dockerfile b/Dockerfile index e252851..893b6ad 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,6 +22,7 @@ WORKDIR etherpad-lite RUN bin/installDeps.sh && rm settings.json COPY entrypoint.sh /entrypoint.sh COPY parseurl.py /parseurl.py +RUN chmod +x /entrypoint.sh RUN sed -i 's/^node/exec\ node/' bin/run.sh diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..db26441 --- /dev/null +++ b/Makefile @@ -0,0 +1,15 @@ + +all: build run + +# --build-arg "BUNDLE_BITBUCKET__ORG=$(BUNDLE_BITBUCKET__ORG)" \ + +build: + docker build -t dt-service-pad . + +run: + docker run --rm -p 9001:9001 \ + -e DATABASE_URL="mysql://user:foo@databasehost/database?options" \ + -t dt-service-pad \ + # + + diff --git a/entrypoint.sh b/entrypoint.sh index 8e55490..faf31ba 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,26 +1,26 @@ #!/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' ) +chmod +x /parseurl.py +# /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 # 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} +# if [ "$ETHERPAD_DB_USERNAME" = 'root' ]; then +# : ${ETHERPAD_DB_PASSWORD:=$MYSQL_ENV_MYSQL_ROOT_PASSWORD} +# fi + +if [ -z "$ETHERPAD_DB_USERNAME" ]; then + echo >&2 'error: missing required ETHERPAD_DB_USERNAME environment variable' + echo >&2 ' Did you forget to -e ETHERPAD_DB_USERNAME=... ?' + exit 1 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 @@ -30,7 +30,7 @@ fi node -p "require('crypto').randomBytes(32).toString('hex')")} # Check if database already exists -RESULT=`mysql -u${ETHERPAD_DB_USER} -p${ETHERPAD_DB_PASSWORD} \ +RESULT=`mysql -u${ETHERPAD_DB_USERNAME} -p${ETHERPAD_DB_PASSWORD} \ -h${ETHERPAD_DB_HOST} --skip-column-names \ -e "SHOW DATABASES LIKE '${ETHERPAD_DB_NAME}'"` @@ -38,7 +38,7 @@ 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} \ + mysql -u${ETHERPAD_DB_USERNAME} -p${ETHERPAD_DB_PASSWORD} -h${ETHERPAD_DB_HOST} \ -e "create database ${ETHERPAD_DB_NAME}" fi @@ -52,7 +52,7 @@ if [ ! -f settings.json ]; then "sessionKey" : "${ETHERPAD_SESSION_KEY}", "dbType" : "mysql", "dbSettings" : { - "user" : "${ETHERPAD_DB_USER}", + "user" : "${ETHERPAD_DB_USERNAME}", "host" : "${ETHERPAD_DB_HOST}", "password": "${ETHERPAD_DB_PASSWORD}", "database": "${ETHERPAD_DB_NAME}" diff --git a/parseurl.py b/parseurl.py index f6c01af..2a23e8d 100755 --- a/parseurl.py +++ b/parseurl.py @@ -5,19 +5,59 @@ 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 os.environ.keys +uri_str = os.environ['DATABASE_URL'] +uri = urlparse(uri_str) -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) +db_netloc = uri.netloc + +db_credential = None +db_username = None +db_password = None +db_host = None +db_port = None + +if db_netloc.find("@") >= 0 : + tmp_arr = db_netloc.split('@') + db_credential = tmp_arr[0] + db_host = tmp_arr[1] + +if db_credential and db_credential.find(':') >= 0 : + tmp_arr = db_credential.split(':') + db_username = tmp_arr[0] + db_password = tmp_arr[1] + +if db_host and db_host.find(':') >= 0 : + tmp_arr = db_credential.split(':') + db_host = tmp_arr[0] + db_port = tmp_arr[1] + +db_path = uri.path +db_scheme = uri.scheme +db_query = uri.query +db_fragment = uri.fragment + +if db_scheme : + print(prefix + 'SCHEME=' + db_scheme) + +if db_username : + print(prefix + 'USERNAME=' + db_username) + +if db_password : + print(prefix + 'PASSWORD=' + db_password) + +if db_host : + print(prefix + 'HOST=' + db_host) + +if db_port : + print(prefix + 'PORT=' + db_port) + +if db_path : + print(prefix + 'PATH=' + db_path) + +if db_query : + print(prefix + 'QUERY=' + db_query) + +if db_fragment : + print(prefix + 'FRAGMENT=' + db_fragment)