diff --git a/images/ckan/2.9/patches/.gitkeep b/images/ckan/2.9/patches/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/images/ckan/2.9/setup/app/extra_scripts.sh b/images/ckan/2.9/setup/app/extra_scripts.sh index 80a70ef..3d10d33 100755 --- a/images/ckan/2.9/setup/app/extra_scripts.sh +++ b/images/ckan/2.9/setup/app/extra_scripts.sh @@ -1,4 +1,4 @@ #!/bin/bash # this is called before uwsgi is executed -# uset his to add extra scripts before ckan is started +# use this to add extra scripts before ckan is started diff --git a/images/ckan/2.9/setup/app/prerun.py b/images/ckan/2.9/setup/app/prerun.py index cd95b16..904b434 100644 --- a/images/ckan/2.9/setup/app/prerun.py +++ b/images/ckan/2.9/setup/app/prerun.py @@ -11,17 +11,19 @@ limitations under the License. """ -from multiprocessing import connection +import base64 +import json import os +import psycopg2 +import re import sys import subprocess -import psycopg2 -from sqlalchemy.engine.url import make_url +import time import urllib.request, urllib.error, urllib.parse, base64 -import re -import json -import time +from multiprocessing import connection +from sqlalchemy.engine.url import make_url + ckan_ini = os.environ.get('CKAN_INI', '/srv/app/production.ini') @@ -34,7 +36,7 @@ def check_db_connection(retry=None): if retry is None: retry = RETRY elif retry == 0: - print('[prerun] Giving up after 5 tries...') + print('[prerun] Giving up after {count} tries...'.format(count=RETRY)) sys.exit(1) conn_str = os.environ.get('CKAN_SQLALCHEMY_URL', '') @@ -44,14 +46,13 @@ def check_db_connection(retry=None): db_host = make_url(conn_str).host db_name = make_url(conn_str).database connection = psycopg2.connect(user=db_user, - host=db_host, - password=db_passwd, - database=db_name) + host=db_host, + password=db_passwd, + database=db_name) except psycopg2.Error as e: print((str(e))) print('[prerun] Unable to connect to the database...try again in a while.') - import time time.sleep(10) check_db_connection(retry = retry - 1) else: @@ -64,7 +65,7 @@ def check_solr_connection(retry=None): if retry is None: retry = RETRY elif retry == 0: - print('[prerun] Giving up after 5 tries...') + print('[prerun] Giving up after {count} tries...'.format(count=RETRY)) sys.exit(1) url = os.environ.get('CKAN_SOLR_URL', '') @@ -72,8 +73,6 @@ def check_solr_connection(retry=None): password = os.environ.get('CKAN_SOLR_PASSWORD', '') search_url = '{url}/schema/name?wt=json'.format(url=url) - - try: if not username: connection = urllib.request.urlopen(search_url) @@ -84,7 +83,6 @@ def check_solr_connection(retry=None): connection = urllib.request.urlopen(request) except urllib.error.URLError as e: print('[prerun] Unable to connect to solr...try again in a while.') - import time time.sleep(10) check_solr_connection(retry = retry - 1) else: @@ -113,7 +111,6 @@ def init_db(): if 'OperationalError' in str(e.output): print(e.output.decode('utf-8')) print('[prerun] Database not ready, waiting a bit before exit...') - import time time.sleep(5) sys.exit(1) else: @@ -137,9 +134,9 @@ def init_datastore(): db_host = make_url(conn_str).host db_name = make_url(conn_str).database connection = psycopg2.connect(user=db_user, - host=db_host, - password=db_passwd, - database=db_name) + host=db_host, + password=db_passwd, + database=db_name) cursor = connection.cursor() print('[prerun] Initializing datastore db - start') @@ -225,4 +222,5 @@ def create_sysadmin(): init_db() if os.environ.get('CKAN_DATASTORE_WRITE_URL'): init_datastore() - create_sysadmin() \ No newline at end of file + create_sysadmin() + diff --git a/images/ckan/2.9/setup/app/start_ckan.sh b/images/ckan/2.9/setup/app/start_ckan.sh index 99f09db..fef88d1 100755 --- a/images/ckan/2.9/setup/app/start_ckan.sh +++ b/images/ckan/2.9/setup/app/start_ckan.sh @@ -2,14 +2,14 @@ # Run any startup scripts provided by images extending this one if [[ -d "${APP_DIR}/docker-entrypoint.d" ]] then - for f in ${APP_DIR}/docker-entrypoint.d/*; do - case "$f" in - *.sh) echo "$0: Running init file $f"; . "$f" ;; - *.py) echo "$0: Running init file $f"; python "$f"; echo ;; - *) echo "$0: Ignoring $f (not an sh or py file)" ;; - esac - echo - done + for f in ${APP_DIR}/docker-entrypoint.d/*; do + case "$f" in + *.sh) echo "$0: Running init file $f"; . "$f" ;; + *.py) echo "$0: Running init file $f"; python "$f"; echo ;; + *) echo "$0: Ignoring $f (not an sh or py file)" ;; + esac + echo + done fi # Add session secret from chart @@ -24,12 +24,13 @@ fi if grep -E "beaker.session.secret ?= ?$" $APP_DIR/production.ini then - echo "Setting secrets in ini file" - ckan config-tool $APP_DIR/production.ini "beaker.session.secret=$(python3 -c 'import secrets; print(secrets.token_urlsafe())')" - ckan config-tool $APP_DIR/production.ini "WTF_CSRF_SECRET_KEY=$(python3 -c 'import secrets; print(secrets.token_urlsafe())')" - JWT_SECRET=$(python3 -c 'import secrets; print("string:" + secrets.token_urlsafe())') - ckan config-tool $APP_DIR/production.ini "api_token.jwt.encode.secret=$JWT_SECRET" - ckan config-tool $APP_DIR/production.ini "api_token.jwt.decode.secret=$JWT_SECRET" + echo "Setting secrets in ini file" + ckan config-tool $APP_DIR/production.ini "beaker.session.secret=$(python3 -c 'import secrets; print(secrets.token_urlsafe())')" + ckan config-tool $APP_DIR/production.ini "WTF_CSRF_SECRET_KEY=$(python3 -c 'import secrets; print(secrets.token_urlsafe())')" + + JWT_SECRET=$(python3 -c 'import secrets; print("string:" + secrets.token_urlsafe())') + ckan config-tool $APP_DIR/production.ini "api_token.jwt.encode.secret=$JWT_SECRET" + ckan config-tool $APP_DIR/production.ini "api_token.jwt.decode.secret=$JWT_SECRET" fi # Run the prerun script to init CKAN and create the default admin user @@ -41,14 +42,14 @@ if [ "$MAINTENANCE_MODE" = true ]; then PYTHONUNBUFFERED=1 python maintenance/se # Run any after prerun/init scripts provided by images extending this one if [[ -d "${APP_DIR}/docker-afterinit.d" ]] then - for f in ${APP_DIR}/docker-afterinit.d/*; do - case "$f" in - *.sh) echo "$0: Running after prerun init file $f"; . "$f" ;; - *.py) echo "$0: Running after prerun init file $f"; python "$f"; echo ;; - *) echo "$0: Ignoring $f (not an sh or py file)" ;; - esac - echo - done + for f in ${APP_DIR}/docker-afterinit.d/*; do + case "$f" in + *.sh) echo "$0: Running after prerun init file $f"; . "$f" ;; + *.py) echo "$0: Running after prerun init file $f"; python "$f"; echo ;; + *) echo "$0: Ignoring $f (not an sh or py file)" ;; + esac + echo + done fi # Check whether http basic auth password protection is enabled and enable basicauth routing on uwsgi respecfully