From 3c65fb1d080b1fd5bbd3e19e8f7f28ad002fb949 Mon Sep 17 00:00:00 2001 From: hkmshb Date: Tue, 14 Nov 2023 09:01:01 +0100 Subject: [PATCH 1/3] fix typos and drop .gitkeep file from ckan/2.9/patches --- images/ckan/2.9/patches/.gitkeep | 0 images/ckan/2.9/setup/app/extra_scripts.sh | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 images/ckan/2.9/patches/.gitkeep 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 From c5a612de6408b191a0489c8ee8be870f78cd5bd3 Mon Sep 17 00:00:00 2001 From: hkmshb Date: Tue, 14 Nov 2023 09:25:09 +0100 Subject: [PATCH 2/3] fix/reorder imports and adjust indents for some func calls --- images/ckan/2.9/setup/app/prerun.py | 38 ++++++++++++++--------------- 1 file changed, 18 insertions(+), 20 deletions(-) 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() + From ec3a89125336eed7c809bf0b87fc7efd5329cd56 Mon Sep 17 00:00:00 2001 From: hkmshb Date: Tue, 14 Nov 2023 09:28:14 +0100 Subject: [PATCH 3/3] fix inconsistent indentation in start_ckan.sh script --- images/ckan/2.9/setup/app/start_ckan.sh | 40 ++++++++++++------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/images/ckan/2.9/setup/app/start_ckan.sh b/images/ckan/2.9/setup/app/start_ckan.sh index 58dffd7..383c79b 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,10 +24,10 @@ 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 "api_token.jwt.encode.secret=$(python3 -c 'import secrets; print("string:" + secrets.token_urlsafe())')" - ckan config-tool $APP_DIR/production.ini "api_token.jwt.decode.secret=$(python3 -c 'import secrets; print("string:" + secrets.token_urlsafe())')" + 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 "api_token.jwt.encode.secret=$(python3 -c 'import secrets; print("string:" + secrets.token_urlsafe())')" + ckan config-tool $APP_DIR/production.ini "api_token.jwt.decode.secret=$(python3 -c 'import secrets; print("string:" + secrets.token_urlsafe())')" fi # Run the prerun script to init CKAN and create the default admin user @@ -39,14 +39,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