created docker customization for ckan-bluecloud

This commit is contained in:
Francesco Mangiacrapa 2024-10-31 17:06:47 +01:00
parent 2ad9b5a09e
commit 5421bbab85
4 changed files with 309 additions and 36 deletions

View File

@ -1,42 +1,52 @@
ARG UBUNTU_VERSION=14.04
FROM ubuntu:$UBUNTU_VERSION
# CKAN user
RUN useradd -l -M -s /bin/bash -u 997 ckan
FROM harbor.d4science.org/external-services/ckan-legacy-269:latest
LABEL org.d4science.image.licenses="EUPL-1.2" \
org.d4science.image.source="https://code-repo.d4science.org/D4Science/ckan-2-6-legacy" \
org.d4science.image.source="https://code-repo.d4science.org/D4Science/ckan-2-6-bluecloud" \
org.d4science.image.vendor="D4Science <https://www.d4science.org>" \
org.d4science.image.authors="Andrea Dell'Amico <andrea.dellamico@isti.cnr.it>, Alfredo Oliviero <alfredo.oliviero@isti.cnr.it>"
org.d4science.image.authors="Francesco Mangiacrapa <francesco.mangiacrapa@isti.cnr.it>"
# Aggiorna pacchetti e installa i servizi necessari
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update \
&& apt-get dist-upgrade -y \
&& apt-get install -y python python-pip \
&& apt-get install -y supervisor redis-server apache2 libapache2-mod-wsgi libapache2-mod-rpaf libapache2-mod-xsendfile nginx-full memcached \
&& apt-get install -y libedit2 libpq5 postgresql-client \
&& apt-get clean
#Catalogue git repository
ARG CATALOGUE_REPOSITORY=https://code-repo.d4science.org/CKAN-Extensions/ckanext-d4science_theme.git
ARG CATALOGUE_DEFAULT_THEME_BRANCH_NAME=ckan-default
# Configura Supervisor
RUN mkdir -p /var/log/supervisor /var/log/ckan && chown ckan /var/log/ckan
#!!!! Attention !!!!! Change this parameter for any CKAN intance !!!!!
#Catalogue custom git repository name for the specific instance.
ARG CATALOGUE_CUSTOM_THEME_BRANCH_NAME=ckan-bluecloud.d4science.org
# Creazione del file di configurazione per Supervisor
COPY conf/supervisord.conf /etc/supervisor/supervisord.conf
COPY conf/supervisord-ckan-services.conf /etc/supervisor/conf.d/ckan-services.conf
COPY conf/supervisord-ckan-harvesting.conf /etc/supervisor/conf.d/ckan-harvesting.conf
# Services configuration
COPY conf/apache_ckan_virthost.conf /etc/apache2/sites-enabled/ckan.conf
COPY conf/apache_ckan_datapusher.conf /etc/apache2/sites-enabled/datapusher.conf
COPY conf/apache_ports.conf /etc/apache2/ports.conf
COPY conf/nginx_ckan_virtualhost.conf /etc/nginx/sites-enabled/ckan.conf
COPY conf/redis-server.conf /etc/redis/redis.conf
COPY conf/nginx.conf /etc/nginx/nginx.conf
RUN rm -f /etc/apache2/sites-enabled/000-default.conf /etc/apache2/sites-available/000-default.conf /etc/nginx/sites-enabled/default
ADD ckan-dist/ckan-2.69.tar.gz /
ADD ckan-dist/ckan-etc.tar.gz /
#Customize this argument according to CKAN instance
ARG CATALOGUE_CUSTOM_HOSTNAME=${CATALOGUE_CUSTOM_THEME_BRANCH_NAME}
# Definisce Supervisor come entrypoint
# CMD ["/usr/bin/supervisord", "-n", "-c /etc/supervisor/supervisord.conf"]
CMD ["/usr/bin/supervisord", "-n"]
#CKAN filesystem paths
ARG USR_LOCAL_BIN=/usr/local/bin
ARG SRV_CUSTOMIZATIONS=/srv/ckan_customisations
# Environment variables
#ENV with path to the CKAN CUSTOMIZATION FOR THE SPECIFIC INSTANCE
ENV CKAN_CUSTOMIZATION_THEME=${CATALOGUE_CUSTOM_THEME_BRANCH_NAME}
ARG E_USR_LOCAL_BIN=${USR_LOCAL_BIN}
ARG E_SRV_CUSTOMIZATIONS=${SRV_CUSTOMIZATIONS}
# Installa il client git (necessario solo se non è già presente nell'immagine base)
# rm -rf /var/lib/apt/lists/* pulisce la cache di apt, riducendo la dimensione dellimmagine finale.
RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
# cleanup
RUN rm -rf $E_USR_LOCAL_BIN/*
# Fai il clone del repository git di CKAN_DEFAULT_THEME direttamente nell'immagine Docker
RUN git clone -b $CATALOGUE_DEFAULT_THEME_BRANCH_NAME $CATALOGUE_REPOSITORY $E_SRV_CUSTOMIZATIONS/$CATALOGUE_DEFAULT_THEME_BRANCH_NAME
# Fai il clone del repository git del branch CKAN_CUSTOMIZATION_THEME direttamente nell'immagine Docker
RUN git clone -b $CKAN_CUSTOMIZATION_THEME $CATALOGUE_REPOSITORY $E_SRV_CUSTOMIZATIONS/$CATALOGUE_CUSTOM_THEME_BRANCH_NAME
# Copia dei file per la customizzazione del CKAN
COPY conf/d4s-ckan-customizer $E_USR_LOCAL_BIN/
# Crea il folder /scripts e copia il file_installer che rende operative le customizzazioni per il CKAN
RUN mkdir $E_SRV_CUSTOMIZATIONS/scripts
COPY conf/file_installer.sh $E_SRV_CUSTOMIZATIONS/scripts/
RUN chmod +x $E_SRV_CUSTOMIZATIONS/scripts/file_installer.sh
RUN chown -R ckan:ckan $E_SRV_CUSTOMIZATIONS/
ENTRYPOINT ["/srv/ckan_customisations/scripts/file_installer.sh"]
CMD ["/usr/bin/supervisord", "-n"]

View File

@ -1,3 +1,4 @@
# ckan-2-6-legacy
# ckan-2-6-bluecloud
Repository that holds a copy of our latest installation of CKAN 2.6, to make it installable inside a Docker environment.
Repository that holds a customization of CKAN 2.6 for ckan-bluecloud. It starts from the https://code-repo.d4science.org/D4Science/ckan-2-6-legacy
and to make it installable inside a Docker environment with the specific customization for ckan-bluecloud

38
conf/d4s-ckan-customizer Normal file
View File

@ -0,0 +1,38 @@
#!/bin/bash
RETVAL=
BASE_DIR=/srv/ckan_customisations
DATE=$( date )
CUSTOMIZER_LOG_FILE=/var/log/ckan/customiser.log
echo "$DATE" > /var/log/ckan/file_installer.log
logger "d4s-ckan-customizer: starting"
logger "d4s-ckan-customizer: update the svn repositories"
logger "d4s-ckan-customizer: update the svn scripts repository"
cd $BASE_DIR/scripts && svn update >> "$CUSTOMIZER_LOG_FILE" 2>&1
logger "d4s-ckan-customizer: update the svn ckan-default repository"
cd $BASE_DIR/ckan-default && svn update >> "$CUSTOMIZER_LOG_FILE" 2>&1
logger "d4s-ckan-customizer: update the svn $CATALOGUE_CUSTOM_THEME_BRANCH_NAME repository"
cd $BASE_DIR/$CATALOGUE_CUSTOM_THEME_BRANCH_NAME && svn update >> "$CUSTOMIZER_LOG_FILE" 2>&1
logger "d4s-ckan-customizer: install the custom files if the script is present"
if [ -x $BASE_DIR/scripts/file_installer ] ; then
echo "Install the d4s customisations" >> /var/log/ckan/file_installer.log
$BASE_DIR/scripts/file_installer >> /var/log/ckan/file_installer.log 2>&1
echo "Done"
logger "d4s-ckan-customizer: done"
else
logger "d4s-ckan-customizer: the file_installer script does not exist"
fi
echo "---------------" >> /var/log/ckan/file_installer.log
logger "d4s-ckan-customizer: reload apache"
sudo /etc/init.d/apache2 reload >/dev/null 2>&1
logger "d4s-ckan-customizer: run the f2ds harvester script"
/usr/lib/ckan/default/src/ckanext-dcat/ckanext/dcat/f2ds_harvester_run.sh >> "$CUSTOMIZER_LOG_FILE" 2>&1
logger "d4s-ckan-customizer: Done"

224
conf/file_installer.sh Normal file
View File

@ -0,0 +1,224 @@
#!/bin/bash
GLOBAL_BASE_DIR=ckan-default
CUSTOM_BASE_DIR=$CKAN_CUSTOMIZATION_THEME
BASE_DIRECTORY=/srv/ckan_customisations
GLOBAL_DIR=${BASE_DIRECTORY}/${GLOBAL_BASE_DIR}
CUSTOM_DIR=${BASE_DIRECTORY}/${CUSTOM_BASE_DIR}
GCUBE_LICENSE=gcube-data-catalogue-licenses.json
GCUBE_LICENSE_DEST=/etc/ckan/default/gcube-data-catalogue-licenses.json
CKAN_PYTHON_DIR=/usr/lib/ckan/default/lib/python2.7/site-packages
CKAN_APP_DIR=/usr/lib/ckan/default/src
install_gcube_license() {
echo -e "\n*** Install_gcube_license called"
if [ -f "${CUSTOM_DIR}/${GCUBE_LICENSE}" ] ; then
cp -f "${CUSTOM_DIR}/${GCUBE_LICENSE}" "${GCUBE_LICENSE_DEST}"
else
cp -f "${GLOBAL_DIR}/${GCUBE_LICENSE}" "${GCUBE_LICENSE_DEST}"
fi
}
GCUBE_LANG_NAME=en_gcube
GCUBE_LANG_DEST_DIR=${CKAN_APP_DIR}/ckan/ckan/i18n/${GCUBE_LANG_NAME}/LC_MESSAGES
GCUBE_I18N_DEST_DIR=${CKAN_APP_DIR}/ckan/ckan/lib
GCUBE_SOURCE_LANG_DIR=languages/default
GCUBE_INIT_LANG=1
install_gcube_lang() {
echo -e "\n*** Install_gcube_lang called"
if [ ! -d ${GCUBE_LANG_DEST_DIR} ] ; then
mkdir -p ${GCUBE_LANG_DEST_DIR}
GCUBE_INIT_LANG=0
fi
if [ -d "${CUSTOM_DIR}/${GCUBE_SOURCE_LANG_DIR}" ] ; then
cp -f "${CUSTOM_DIR}/${GCUBE_SOURCE_LANG_DIR}/${GCUBE_LANG_NAME}/LC_MESSAGES/ckan.po" "${GCUBE_LANG_DEST_DIR}"
cp -f "${CUSTOM_DIR}/${GCUBE_SOURCE_LANG_DIR}/i18n.py" "${GCUBE_I18N_DEST_DIR}/i18n.py"
else
cp -f "${GLOBAL_DIR}/${GCUBE_SOURCE_LANG_DIR}/${GCUBE_LANG_NAME}/LC_MESSAGES/ckan.po" "${GCUBE_LANG_DEST_DIR}"
cp -f "${GLOBAL_DIR}/${GCUBE_SOURCE_LANG_DIR}/i18n.py" "${GCUBE_I18N_DEST_DIR}/i18n.py"
fi
. /usr/lib/ckan/default/bin/activate
cd "${CKAN_APP_DIR}/ckan"
python setup.py compile_catalog --locale ${GCUBE_LANG_NAME}
# INSTALL ONLY DURING INIT
#if [ $GCUBE_INIT_LANG -eq 0 ] ; then
# . /usr/lib/ckan/default/bin/activate
# cd "${CKAN_APP_DIR}/ckan"
# python setup.py compile_catalog --locale ${GCUBE_LANG_NAME}
#fi
}
# D4Science theme. Many changes
GCUBE_D4S_THEME_NAME=ckanext-d4science_theme
GCUBE_D4S_THEME_DIR=${CKAN_APP_DIR}/${GCUBE_D4S_THEME_NAME}
checkout_ckan_theme() {
echo -e "\n*** Checkout_ckan_theme called"
pushd ${GCUBE_D4S_THEME_DIR}
svn update --force >/dev/null 2>&1
}
# D4Science theme. rsync from CKAN CUSTOM TEMPLATE to CKAN DEFAULT TEMPLATE
GCUBE_D4S_CUSTOM_THEME_SRC=${CUSTOM_DIR}/${GCUBE_D4S_THEME_NAME}/ckanext/d4science_theme/
#GCUBE_D4S_CUSTOM_THEME_SRC=${CUSTOM_DIR}/${GCUBE_D4S_THEME_NAME}/ckanext/d4science_theme/
GCUBE_D4S_DEFAULT_THEME_DEST=${GCUBE_D4S_THEME_DIR}/ckanext/d4science_theme/
install_theme_customisations() {
echo -e "\n*** Install theme customisations called"
if [ -d "${GCUBE_D4S_CUSTOM_THEME_SRC}" ] ; then
echo "CUSTOM THEME EXISTS AT: " "${GCUBE_D4S_CUSTOM_THEME_SRC}"
if [ -d ${GCUBE_D4S_DEFAULT_THEME_DEST} ] ; then
echo "DEFAULT THEME EXISTS AT: " ${GCUBE_D4S_DEFAULT_THEME_DEST}
rsync -av "${GCUBE_D4S_CUSTOM_THEME_SRC}" ${GCUBE_D4S_DEFAULT_THEME_DEST}
else
echo "DEFAULT THEME DOES NOT EXIST AT: " ${GCUBE_D4S_DEFAULT_THEME_DEST}
fi
else
echo "CUSTOM THEME DOES NOT EXIST AT: " "${GCUBE_D4S_CUSTOM_THEME_SRC}"
fi
}
# privatedatasets (plugin)
GCUBE_D4S_SNIPPETS_PKG_DIR=plugins/privatedatasets
GCUBE_D4S_SNIPPETS_PKG_ITEM=${GCUBE_D4S_SNIPPETS_PKG_DIR}/package_item.html
SNIPPETS_PKG_ITEM_DEST=${CKAN_PYTHON_DIR}/ckanext/privatedatasets/templates/snippets/package_item.html
GCUBE_D4S_SNIPPETS_PY_FILES="plugin.py auth.py"
install_privatedatasets_customisations() {
echo -e "\n*** Install_privatedatasets_customisations called"
if [ -z "$1" ] ; then
GCUBE_D4S_SNIPPETS_PKG_ITEM=${GCUBE_D4S_SNIPPETS_PKG_DIR}/package_item.html
echo "No package_item file passed as parameter, using default: ${GCUBE_D4S_SNIPPETS_PKG_ITEM}"
else
GCUBE_D4S_SNIPPETS_PKG_ITEM=$1
echo "Target package_item file passed as parameter using it: ${GCUBE_D4S_SNIPPETS_PKG_ITEM}"
fi
if [ -d ${CKAN_PYTHON_DIR}/ckanext/privatedatasets ] ; then
if [ -f "${CUSTOM_DIR}/${GCUBE_D4S_SNIPPETS_PKG_ITEM}" ] ; then
cp -f "${CUSTOM_DIR}/${GCUBE_D4S_SNIPPETS_PKG_ITEM}" "${SNIPPETS_PKG_ITEM_DEST}"
echo "${CUSTOM_DIR}/${GCUBE_D4S_SNIPPETS_PKG_ITEM} copied to: ${SNIPPETS_PKG_ITEM_DEST}"
else
cp -f ${GLOBAL_DIR}/${GCUBE_D4S_SNIPPETS_PKG_ITEM} ${SNIPPETS_PKG_ITEM_DEST}
echo "${GLOBAL_DIR}/${GCUBE_D4S_SNIPPETS_PKG_ITEM} copied to: ${SNIPPETS_PKG_ITEM_DEST}"
fi
for pyfile in ${GCUBE_D4S_SNIPPETS_PY_FILES} ; do
if [ -f "${CUSTOM_DIR}/${GCUBE_D4S_SNIPPETS_PKG_DIR}/${pyfile}" ] ; then
cp -f "${CUSTOM_DIR}/${GCUBE_D4S_SNIPPETS_PKG_DIR}/${pyfile}" "${CKAN_PYTHON_DIR}/ckanext/privatedatasets/${pyfile}"
else
cp -f "${GLOBAL_DIR}/${GCUBE_D4S_SNIPPETS_PKG_DIR}/${pyfile}" "${CKAN_PYTHON_DIR}/ckanext/privatedatasets/${pyfile}"
fi
done
else
echo "install_privatedatasets_customisations: the directory ${CKAN_PYTHON_DIR}/ckanext/privatedatasets does not exist. Doing nothing"
fi
}
# privatedatasets (plugin), see #21867
# install privatedatasets customisations with open access to resources
# param $1: the ckan hostname where install
install_privatedatasets_customisations_with_open_access_to_resources() {
echo -e "\n*** Install_privatedatasets_customisations_with_open_access_to_resources called"
hs=`hostname`
echo "read hostname: ${hs}"
if [ -z "$1" ] ; then
echo "WARN: no ckan hostname as input parameters.. Doing nothing"
else
if [ "$1" = "$hs" ]; then
GCUBE_D4S_SNIPPETS_PKG_ITEM=${GCUBE_D4S_SNIPPETS_PKG_DIR}/package_item_open_access_to_resources.html
echo "The input parameter is matching the ckan hostname $1, going to install ${GCUBE_D4S_SNIPPETS_PKG_ITEM}"
install_privatedatasets_customisations "${GCUBE_D4S_SNIPPETS_PKG_ITEM}"
else
echo "WARN: the ckan hostname $1 does not matching with ${hs}. Doing nothing"
fi
fi
}
# install_plugin_customisations
install_plugin_customisations() {
echo -e "\n*** Installing customisations for plugin: $1"
if [ -d "$1" ] ; then
if [ -d "$2" ] ; then
if [ -d "$3" ] ; then
echo "RSYNC FROM: $2 TO: $3"
rsync -av "$2" "$3"
else
echo "ERROR: the plugin destion directory does not exist at: $3"
fi
else
echo "ERROR: the plugin default directory does not exist at: $2"
fi
else
echo "WARNING: the directory $1 does not exist. Doing nothing"
fi
}
# make the input file executable
make_file_executable() {
if [ -f "$1" ]; then
echo "$1 exists making it executable"
chmod +x "$1"
fi
}
########## Main ##########
# The gcube license needs root. Do not use for the time being
#install_gcube_license
install_gcube_lang
checkout_ckan_theme
install_theme_customisations
install_privatedatasets_customisations
install_privatedatasets_customisations_with_open_access_to_resources "ckan-d-d4s"
install_privatedatasets_customisations_with_open_access_to_resources "ckan-openscience.int.d4science.net"
# ckanext-geonetwork
install_plugin_customisations "${CKAN_APP_DIR}/ckanext-geonetwork" "${GLOBAL_DIR}/plugins/ckanext-geonetwork/ckanext/geonetwork/" "${CKAN_APP_DIR}/ckanext-geonetwork/ckanext/geonetwork/"
# ckanext-googleanalytics
#install_plugin_customisations "${CKAN_APP_DIR}/ckanext-googleanalytics" "${GLOBAL_DIR}/plugins/ckanext-googleanalytics/ckanext/googleanalytics/" "${CKAN_APP_DIR}/ckanext-googleanalytics/ckanext/googleanalytics/"
# ckanext-harvest
install_plugin_customisations "${CKAN_APP_DIR}/ckanext-harvest" "${GLOBAL_DIR}/plugins/ckanext-harvest/ckanext/harvest/" "${CKAN_APP_DIR}/ckanext-harvest/ckanext/harvest/"
# ckanext-hierarchy
install_plugin_customisations "${CKAN_APP_DIR}/ckanext-hierarchy" "${GLOBAL_DIR}/plugins/ckanext-hierarchy/ckanext/hierarchy/" "${CKAN_APP_DIR}/ckanext-hierarchy/ckanext/hierarchy/"
# ckanext-oaipm
install_plugin_customisations "${CKAN_APP_DIR}/ckanext-oaipm" "${GLOBAL_DIR}/plugins/ckanext-oaipm/ckanext/oaipmh/" "${CKAN_APP_DIR}/ckanext-oaipm/ckanext/oaipmh/"
# ckanext-spatial
install_plugin_customisations "${CKAN_APP_DIR}/ckanext-spatial" "${GLOBAL_DIR}/plugins/ckanext-spatial/ckanext/spatial/" "${CKAN_APP_DIR}/ckanext-spatial/ckanext/spatial/"
# ckanext-dcat
install_plugin_customisations "${CKAN_APP_DIR}/ckanext-dcat" "${GLOBAL_DIR}/plugins/ckanext-dcat/ckanext/dcat/" "${CKAN_APP_DIR}/ckanext-dcat/ckanext/dcat/"
FILE="${CKAN_APP_DIR}/ckanext-dcat/ckanext/dcat/f2ds_harvester.py"
make_file_executable "$FILE"
FILE="${CKAN_APP_DIR}/ckanext-dcat/ckanext/dcat/f2ds_harvester_run.sh"
make_file_executable "$FILE"
# TESTING
# ckanext-spatial
#install_plugin_customisations "${CKAN_APP_DIR}/ckanext-spatial" "${GLOBAL_DIR}/plugins/ckanext-spatial/ckanext/spatial/" "/home/francesco-mangiacrapa/CKAN/ckanext-spatial/ckanext/spatial/"
# ckanext-hierarchy
#install_plugin_customisations "${CKAN_APP_DIR}/ckanext-hierarchy" "${GLOBAL_DIR}/plugins/ckanext-hierarchy/ckanext/hierarchy/" "/home/francesco-mangiacrapa/CKAN/ckanext-hierarchy/ckanext/hierarchy/"
# ckanext-googleanalytics
#install_plugin_customisations "${CKAN_APP_DIR}/ckanext-googleanalytics" "${GLOBAL_DIR}/plugins/ckanext-googleanalytics/ckanext/googleanalytics/" "/home/francesco-mangiacrapa/CKAN/ckanext-googleanalytics/ckanext/googleanalytics/"
#
echo "Finished installation of plugin customisations"
# Esegui il comando passato come argomento
# es. Avvia supervisord in foreground come: exec /usr/bin/supervisord -n
echo "\nExecuting the input command: "+$@
exec "$@"