Skip to content

Commit

Permalink
Fix local datastore bootstrap (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathansberry authored Jan 16, 2025
1 parent 4b6cdcc commit fdf59ef
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion roles/ckan/tasks/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
become: false
with_items:
- ckandb_job.yaml
when: (fjelltopp_env_type != 'local') or (ckan_datapusher_enable == 'true')
when: (fjelltopp_env_type != 'local')

- name: Deploy CKAN
kubernetes.core.k8s:
Expand Down
17 changes: 13 additions & 4 deletions roles/ckan/templates/ckan/ckan_bootstrap.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
#!/bin/sh
CONFIG=/etc/ckan/production.ini

{% if ckan_datapusher_enable == 'true' %}
echo "Making datastore user"
psql "${CKAN_SQLALCHEMY_URL}" -c "CREATE ROLE datastore NOSUPERUSER NOCREATEDB NOCREATEROLE LOGIN PASSWORD '{{ ckan_ds_rw_pass }}';"
echo "Making datastore_ro user"
psql "${CKAN_SQLALCHEMY_URL}" -c "CREATE ROLE datastore_ro NOSUPERUSER NOCREATEDB NOCREATEROLE LOGIN PASSWORD '{{ ckan_ds_ro_pass }}';"
echo "Making datastore db"
psql "${CKAN_SQLALCHEMY_URL}" -c "CREATE DATABASE datastore OWNER ckan ENCODING 'utf-8';"
echo "Setup datastore permissions"
ckan -c "$CONFIG" datastore set-permissions | psql "${CKAN_SQLALCHEMY_URL}"
{% endif %}

# we're making sure to run our custom entrypoint.
/usr/lib/ckan/ckan-entrypoint.sh
echo "DB init:"
ckan -c "$CONFIG" db init

echo "Add admin user:"
ckan -c "$CONFIG" user add admin email="admin@localhost" name="admin" fullname="Admin" password="fjelltopp" apikey="{{ ckan_admin_api_key }}" id="{{ ckan_admin_user_id }}"
echo "Set apikey:"
Expand All @@ -12,8 +23,6 @@ echo "Create API token:"
psql "${CKAN_SQLALCHEMY_URL}" -c "INSERT INTO api_token VALUES ('{{ ckan_admin_api_token_unencoded }}', 'Default Token', '{{ ckan_admin_user_id }}', now()) ON CONFLICT DO NOTHING;"
echo "make admin superuser"
ckan -c "$CONFIG" sysadmin add admin
echo "Set datastore permissions"
ckan -c "$CONFIG" datastore set-permissions | psql "${CKAN_SQLALCHEMY_URL}"
echo "Build search index"
ckan -c "$CONFIG" search-index rebuild
echo bootstrap finished

0 comments on commit fdf59ef

Please sign in to comment.