Merge pull request #10 from keitaroinc/datastore-set-permissions
Datastore creating at prerun with set permissions
This commit is contained in:
commit
e33f49843b
|
@ -107,7 +107,7 @@ RUN pip install -e /srv/app/src/ckan && \
|
||||||
RUN rm -rf /srv/app/wheels
|
RUN rm -rf /srv/app/wheels
|
||||||
|
|
||||||
# Create entrypoint directory for children image scripts
|
# Create entrypoint directory for children image scripts
|
||||||
ONBUILD RUN mkdir /docker-entrypoint.d
|
ONBUILD RUN mkdir docker-entrypoint.d
|
||||||
|
|
||||||
EXPOSE 5000
|
EXPOSE 5000
|
||||||
|
|
||||||
|
|
|
@ -66,12 +66,12 @@ def init_db():
|
||||||
print '[prerun] Start init_db...'
|
print '[prerun] Start init_db...'
|
||||||
|
|
||||||
db_command = ['paster', '--plugin=ckan', 'db', 'init', '-c', ckan_ini]
|
db_command = ['paster', '--plugin=ckan', 'db', 'init', '-c', ckan_ini]
|
||||||
|
|
||||||
print '[prerun] Initializing or upgrading db - start using paster db init'
|
print '[prerun] Initializing or upgrading db - start using paster db init'
|
||||||
try:
|
try:
|
||||||
# run init scripts
|
# run init scripts
|
||||||
subprocess.check_output(db_command, stderr=subprocess.STDOUT)
|
subprocess.check_output(db_command, stderr=subprocess.STDOUT)
|
||||||
|
|
||||||
print '[prerun] Initializing or upgrading db - end'
|
print '[prerun] Initializing or upgrading db - end'
|
||||||
except subprocess.CalledProcessError, e:
|
except subprocess.CalledProcessError, e:
|
||||||
if 'OperationalError' in e.output:
|
if 'OperationalError' in e.output:
|
||||||
|
@ -85,6 +85,55 @@ def init_db():
|
||||||
raise e
|
raise e
|
||||||
print '[prerun] Initializing or upgrading db - finish'
|
print '[prerun] Initializing or upgrading db - finish'
|
||||||
|
|
||||||
|
|
||||||
|
def init_datastore():
|
||||||
|
|
||||||
|
conn_str = os.environ.get('CKAN_DATASTORE_WRITE_URL')
|
||||||
|
if not conn_str:
|
||||||
|
print '[prerun] Skipping datastore initialization'
|
||||||
|
return
|
||||||
|
|
||||||
|
datastore_perms_command = ['paster', '--plugin=ckan', 'datastore',
|
||||||
|
'set-permissions', '-c', ckan_ini]
|
||||||
|
|
||||||
|
connection = psycopg2.connect(conn_str)
|
||||||
|
cursor = connection.cursor()
|
||||||
|
|
||||||
|
print '[prerun] Initializing datastore db - start'
|
||||||
|
try:
|
||||||
|
datastore_perms = subprocess.Popen(
|
||||||
|
datastore_perms_command,
|
||||||
|
stdout=subprocess.PIPE)
|
||||||
|
|
||||||
|
perms_sql = datastore_perms.stdout.read()
|
||||||
|
# Remove internal pg command as psycopg2 does not like it
|
||||||
|
perms_sql = re.sub('\\\\connect \"(.*)\"', '', perms_sql)
|
||||||
|
cursor.execute(perms_sql)
|
||||||
|
for notice in connection.notices:
|
||||||
|
print notice
|
||||||
|
|
||||||
|
connection.commit()
|
||||||
|
|
||||||
|
print '[prerun] Initializing datastore db - end'
|
||||||
|
print datastore_perms.stdout.read()
|
||||||
|
except psycopg2.Error as e:
|
||||||
|
print '[prerun] Could not initialize datastore'
|
||||||
|
print str(e)
|
||||||
|
|
||||||
|
except subprocess.CalledProcessError, e:
|
||||||
|
if 'OperationalError' in e.output:
|
||||||
|
print e.output
|
||||||
|
print '[prerun] Database not ready, waiting a bit before exit...'
|
||||||
|
time.sleep(5)
|
||||||
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
print e.output
|
||||||
|
raise e
|
||||||
|
finally:
|
||||||
|
cursor.close()
|
||||||
|
connection.close()
|
||||||
|
|
||||||
|
|
||||||
def create_sysadmin():
|
def create_sysadmin():
|
||||||
|
|
||||||
print '[prerun] Start create_sysadmin...'
|
print '[prerun] Start create_sysadmin...'
|
||||||
|
@ -131,5 +180,7 @@ if __name__ == '__main__':
|
||||||
check_db_connection()
|
check_db_connection()
|
||||||
check_solr_connection()
|
check_solr_connection()
|
||||||
init_db()
|
init_db()
|
||||||
|
if os.environ.get('CKAN_DATASTORE_WRITE_URL'):
|
||||||
|
init_datastore()
|
||||||
create_sysadmin()
|
create_sysadmin()
|
||||||
#time.sleep(60000) # don't end the prerun script to allow container dock and debug
|
#time.sleep(60000) # don't end the prerun script to allow container dock and debug
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
python prerun.py
|
python prerun.py
|
||||||
|
|
||||||
# Run any startup scripts provided by images extending this one
|
# Run any startup scripts provided by images extending this one
|
||||||
if [[ -d "/docker-entrypoint.d" ]]
|
if [[ -d "docker-entrypoint.d" ]]
|
||||||
then
|
then
|
||||||
for f in /docker-entrypoint.d/*; do
|
for f in /docker-entrypoint.d/*; do
|
||||||
case "$f" in
|
case "$f" in
|
||||||
|
|
Loading…
Reference in New Issue