+
+
From d185b3a9e5990676702e013af955123d9c425126 Mon Sep 17 00:00:00 2001
From: mjanez <96422458+mjanez@users.noreply.github.com>
Date: Wed, 19 Apr 2023 14:09:05 +0000
Subject: [PATCH 6/6] Update setup xloader and setup iepnb
---
README.md | 17 +++++++++-------
ckan/docker-entrypoint.d/01_setup_xloader.sh | 21 +++++++++++++++++---
ckan/docker-entrypoint.d/05_setup_iepnb.sh | 11 +++++-----
3 files changed, 33 insertions(+), 16 deletions(-)
diff --git a/README.md b/README.md
index 11a8816c..821ae414 100644
--- a/README.md
+++ b/README.md
@@ -85,7 +85,7 @@ Information about extensions installed in the `main` image. More info described
| Extension | [ckanext-resourcedictionary](https://github.com/OpenDataGIS/ckanext-resourcedictionary) | main | Completed | ✔️ | ✔️ | Stable installation. This extension extends the default CKAN Data Dictionary functionality by adding possibility to create data dictionary before actual data is uploaded to datastore. |
| Extension | [ckanext-pages](https://github.com/ckan/ckanext-pages) | 0.5.1 | Completed | ✔️ | ✔️ | Stable installation. This extension gives you an easy way to add simple pages to CKAN. |
| Extension | [ckanext-pdfview](https://github.com/ckan/ckanext-pdfview) | 0.0.8 | Completed | ✔️ | ✔️ | Stable installation. This extension provides a view plugin for PDF files using an html object tag. |
-| Extension | [ckanext-iepnb](https://github.com/OpenDataGIS/ckanext-iepnb) | 0.05 | Completed | ✔️ | ✔️ | Stable installation for 0.0.5 version, the modification of the Solr schema.xml with the new fields for faceted and failed python dependencies needs to be reviewed. |
+| Extension | [ckanext-iepnb](https://github.com/OpenDataGIS/ckanext-iepnb) | 0.1.2 | Completed | ✔️ | ✔️ | Stable installation for 0.1.2 version, the modification of the Solr schema.xml with the new fields for faceted and failed python dependencies needs to be reviewed. |
| Software | [ckan-pycsw](https://github.com/mjanez/ckan-pycsw) | main | Completed | ✔️ | ✔️ | Stable installation. PyCSW Endpoint of Open Data Portal with docker compose config. Harvest the CKAN catalogue in a CSW endpoint based on existing spatial datasets in the open data portal. |
@@ -194,7 +194,9 @@ Use this if you are a maintainer and will not be making code changes to CKAN or
> Please note that when accessing CKAN directly (via a browser) ie: not going through Apache/NGINX you will need to make sure you have "ckan" set up to be an alias to localhost in the local hosts file. Either that or you will need to change the `.env` entry for `CKAN_SITE_URL`
>**Warning**:
- > Using the default values on the `.env` file will get you a working CKAN instance. There is a sysadmin user created by default with the values defined in `CKAN_SYSADMIN_NAME` and `CKAN_SYSADMIN_PASSWORD`(`ckan_admin` and `test1234` by default). **This should be obviously changed before running this setup as a public CKAN instance.**
+ > Using the default values on the `.env` file will get you a working CKAN instance. There is a sysadmin user created by default with the values defined in `CKAN_SYSADMIN_NAME` and `CKAN_SYSADMIN_PASSWORD` (`ckan_admin` and `test1234` by default). All ennvars with `API_TOKEN` are automatically regenerated when CKAN is loaded, no editing is required.
+ >
+ >**This should be obviously changed before running this setup as a public CKAN instance.**
3. Build the images:
```bash
@@ -322,12 +324,13 @@ The new extension files and directories are created in the `/srv/app/src_extensi
## CKAN images
-![ckan images](https://user-images.githubusercontent.com/54408245/207079416-a01235af-2dea-4425-b6fd-f8c3687dd993.png)
+
+![ckan images](https://raw.githubusercontent.com/mjanez/ckan-docker/master/doc/img/ckan-docker-images-iepnb.png)
The Docker image config files used to build your CKAN project are located in the `ckan/` folder. There are two Docker files:
-* `Dockerfile`: this is based on `ckan/ckan-base:`, a base image located in the DockerHub repository, that has CKAN installed along with all its dependencies, properly configured and running on [uWSGI](https://uwsgi-docs.readthedocs.io/en/latest/) (production setup)
-* `Dockerfile.dev`: this is based on `ckan/ckan-base:-dev` also located located in the DockerHub repository, and extends `ckan/ckan-base:` to include:
+* `Dockerfile`: this is based on `ckan/ckan-base-spatial:`, a base image located in the DockerHub repository, that has CKAN installed along with all its dependencies, properly configured and running on [uWSGI](https://uwsgi-docs.readthedocs.io/en/latest/) (production setup)
+* `Dockerfile.dev`: this is based on `ckan/ckan-base-spatial:-dev` also located located in the DockerHub repository, and extends `ckan/ckan-base-spatial:` to include:
* Any extension cloned on the `src` folder will be installed in the CKAN container when booting up Docker Compose (`docker compose up`). This includes installing any requirements listed in a `requirements.txt` (or `pip-requirements.txt`) file and running `python setup.py develop`.
* CKAN is started running this: `/usr/bin/ckan -c /srv/app/ckan.ini run -H 0.0.0.0`.
@@ -336,7 +339,7 @@ The Docker image config files used to build your CKAN project are located in the
## CKAN images enhancement
### Extending the base images
-You can modify the docker files to build your own customized image tailored to your project, installing any extensions and extra requirements needed. For example here is where you would update to use a different CKAN base image ie: `ckan/ckan-base:`
+You can modify the docker files to build your own customized image tailored to your project, installing any extensions and extra requirements needed. For example here is where you would update to use a different CKAN base image ie: `ckan/ckan-base-spatial:`
To perform extra initialization steps you can add scripts to your custom images and copy them to the `/docker-entrypoint.d` folder (The folder should be created for you when you build the image). Any `*.sh` and `*.py` file in that folder will be executed just after the main initialization script ([`prerun.py`](https://github.com/ckan/ckan-docker-base/blob/main/ckan-2.9/base/setup/prerun.py)) is executed and just before the web server and supervisor processes are started.
@@ -362,7 +365,7 @@ ckan -c /srv/app/ckan.ini validation init-db
And then in our `Dockerfile.dev` file we install the extension and copy the initialization scripts:
```Dockerfile
-FROM ckan/ckan-base:2.9.8-dev
+FROM ckan/ckan-base-spatial:2.9.8
RUN pip install -e git+https://github.com/frictionlessdata/ckanext-validation.git#egg=ckanext-validation && \
pip install -r https://raw.githubusercontent.com/frictionlessdata/ckanext-validation/master/requirements.txt
diff --git a/ckan/docker-entrypoint.d/01_setup_xloader.sh b/ckan/docker-entrypoint.d/01_setup_xloader.sh
index 8aa25696..4f5e3e58 100644
--- a/ckan/docker-entrypoint.d/01_setup_xloader.sh
+++ b/ckan/docker-entrypoint.d/01_setup_xloader.sh
@@ -1,14 +1,29 @@
#!/bin/bash
+# Set the name of the token to revoke
+TOKEN_NAME="xloader"
+
+# Get the list of tokens and extract the IDs for tokens with the specified name
+TOKEN_IDS=$(ckan -c $CKAN_INI user token list ckan_admin | grep "$TOKEN_NAME" | awk -F'[][]' '{print $2}' | tr -d '[]')
+
+# Revoke each previous token of xloader
+for TOKEN_ID in $TOKEN_IDS
+do
+ ckan -c $CKAN_INI user token revoke $TOKEN_ID
+ if [ $? -eq 0 ]; then
+ echo "API Token $TOKEN_ID has been revoked"
+ fi
+done
+
# Add ckanext.xloader.api_token to the CKAN config file
echo "Loading ckanext-xloader settings in the CKAN config file"
ckan config-tool $CKAN_INI \
- "ckanext.xloader.api_token = xxx" \
- "ckanext.xloader.jobs_db.uri = $CKANEXT__XLOADER__JOBS__DB_URI"
+ "ckanext.xloader.api_token=xxx" \
+ "ckanext.xloader.jobs_db.uri=$CKANEXT__XLOADER__JOBS__DB_URI"
# Create ckanext-xloader API_TOKEN
echo "Set up ckanext.xloader.api_token in the CKAN config file"
-ckan config-tool $CKAN_INI "ckanext.xloader.api_token = $(ckan -c $CKAN_INI user token add ckan_admin xloader | tail -n 1 | tr -d '\t')"
+ckan config-tool $CKAN_INI "ckanext.xloader.api_token=$(ckan -c $CKAN_INI user token add ckan_admin xloader | tail -n 1 | tr -d '\t')"
#TODO: Setup worker background
#echo "Set up CKAN jobs worker"
diff --git a/ckan/docker-entrypoint.d/05_setup_iepnb.sh b/ckan/docker-entrypoint.d/05_setup_iepnb.sh
index 2a85a80a..b5f1233f 100644
--- a/ckan/docker-entrypoint.d/05_setup_iepnb.sh
+++ b/ckan/docker-entrypoint.d/05_setup_iepnb.sh
@@ -1,11 +1,10 @@
#!/bin/bash
# Update ckanext-iepnb settings
-echo "Set up ckanext-iepnb"
-
-#TODO: Version with solr
-#ckan -c $CKAN_INI search-index clear
+echo "Set up ckanext-iepnb. Clear index"
+ckan -c $CKAN_INI search-index clear
+echo "ckanext-iepnb. Load envvars"
ckan config-tool $CKAN_INI \
"iepnb.server=$CKANEXT__IEPNB_SERVER" \
"iepnb.path_menu =$CKANEXT__IEPNB_PATH_MENU" \
@@ -13,5 +12,5 @@ ckan config-tool $CKAN_INI \
"iepnb.popular_tags=$CKANEXT__IEPNB_POPULAR_TAGS" \
"iepnb.facet_list=$CKANEXT__IEPNB_FACET_LIST"
-#TODO: Version with solr
-#ckan -c $CKAN_INI search-index rebuild
\ No newline at end of file
+echo "ckanext-iepnb. Rebuild index"
+ckan -c $CKAN_INI search-index rebuild
\ No newline at end of file