From e7075b9c345802c46b817e65986435cfd4455987 Mon Sep 17 00:00:00 2001 From: Brett Date: Fri, 29 Oct 2021 13:55:58 +0200 Subject: [PATCH] commit ckan directory changes --- .gitkeep | 0 Dockerfile | 55 +++++++++++++++++++ Dockerfile.dev | 37 +++++++++++++ patches/00_patch_sql_url.patch | 11 ++++ .../01_patch_resource_replace_upload.patch | 11 ++++ .../02_patch_postgres_username_split.patch | 11 ++++ scripts/apply_ckan_patches.sh | 5 ++ 7 files changed, 130 insertions(+) create mode 100644 .gitkeep create mode 100644 Dockerfile create mode 100644 Dockerfile.dev create mode 100644 patches/00_patch_sql_url.patch create mode 100644 patches/01_patch_resource_replace_upload.patch create mode 100644 patches/02_patch_postgres_username_split.patch create mode 100755 scripts/apply_ckan_patches.sh diff --git a/.gitkeep b/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e13b160 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,55 @@ +FROM ckan/ckan-base:testing-only.2.9 + +LABEL maintainer="brett@kowh.ai" + +#RUN apk update \ +# && apk upgrade \ +# && apk add --no-cache libffi-dev \ +# libmagic + + +# Set up environment variables +ENV APP_DIR=/srv/app +ENV TZ=UTC +ENV CRYPTOGRAPHY_DONT_BUILD_RUST=1 + +RUN echo ${TZ} > /etc/timezone + +# Make sure both files are not exactly the same +RUN if ! [ /usr/share/zoneinfo/${TZ} -ef /etc/localtime ]; then \ + cp /usr/share/zoneinfo/${TZ} /etc/localtime ;\ + fi ; + +#RUN pip3 install -e 'git+https://github.com/DataShades/ckanext-xloader@py3#egg=ckanext-xloader' +#RUN pip3 install -r ${APP_DIR}/src/ckanext-xloader/requirements.txt +#RUN pip3 install -U requests[security] + +# Install any extensions needed by your CKAN instance +# (Make sure to add the plugins to CKAN__PLUGINS in the .env file) +# For instance: +#RUN pip install -e git+https://github.com/ckan/ckanext-pages.git#egg=ckanext-pages && \ +# pip install -e git+https://github.com/ckan/ckanext-dcat.git@v0.0.6#egg=ckanext-dcat && \ +# pip install -r https://raw.githubusercontent.com/ckan/ckanext-dcat/v0.0.6/requirements.txt + +# Install the extension(s) you wrote for your own project +# RUN pip install -e git+https://github.com/your-org/ckanext-your-extension.git@v1.0.0#egg=ckanext-your-extension + +# Apply any patches needed to CKAN core or any of the built extensions (not the +# runtime mounted ones) +# See https://github.com/okfn/docker-ckan#applying-patches + +#COPY patches ${APP_DIR}/patches + +# Copy patches and apply patches script +COPY ./patches ${SRC_DIR}/patches +COPY ./scripts/apply_ckan_patches.sh ${SRC_DIR}/apply_ckan_patches.sh +# Apply patches +#RUN ${SRC_DIR}/apply_ckan_patches.sh + +RUN for d in ${APP_DIR}/patches/*; do \ + if [ -d $d ]; then \ + for f in `ls $d/*.patch | sort -g`; do \ + cd $SRC_DIR/`basename "$d"` && echo "$0: Applying patch $f to $SRC_DIR/`basename $d`"; patch -p1 < "$f" ; \ + done ; \ + fi ; \ + done diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 0000000..6086f6e --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,37 @@ +FROM ckan/ckan-dev:testing-only.2.9 + +LABEL maintainer="brett@kowh.ai" + +# Set up environment variables +ENV APP_DIR=/srv/app +ENV TZ=UTC +RUN echo ${TZ} > /etc/timezone + +# Make sure both files are not exactly the same +RUN if ! [ /usr/share/zoneinfo/${TZ} -ef /etc/localtime ]; then \ + cp /usr/share/zoneinfo/${TZ} /etc/localtime ;\ + fi ; + +# Install any extensions needed by your CKAN instance +# (Make sure to add the plugins to CKAN__PLUGINS in the .env file) +# For instance: +#RUN pip install -e git+https://github.com/ckan/ckanext-pages.git#egg=ckanext-pages && \ +# pip install -e git+https://github.com/ckan/ckanext-dcat.git@v0.0.6#egg=ckanext-dcat && \ +# pip install -r https://raw.githubusercontent.com/ckan/ckanext-dcat/v0.0.6/requirements.txt + +# Clone the extension(s) your are writing for your own project in the `src` folder +# to get them mounted in this image at runtime + +# Apply any patches needed to CKAN core or any of the built extensions (not the +# runtime mounted ones) +# See https://github.com/okfn/docker-ckan#applying-patches + +COPY patches ${APP_DIR}/patches + +RUN for d in ${APP_DIR}/patches/*; do \ + if [ -d $d ]; then \ + for f in `ls $d/*.patch | sort -g`; do \ + cd $SRC_DIR/`basename "$d"` && echo "$0: Applying patch $f to $SRC_DIR/`basename $d`"; patch -p1 < "$f" ; \ + done ; \ + fi ; \ + done diff --git a/patches/00_patch_sql_url.patch b/patches/00_patch_sql_url.patch new file mode 100644 index 0000000..46a7135 --- /dev/null +++ b/patches/00_patch_sql_url.patch @@ -0,0 +1,11 @@ +--- ckan/ckan/model/__init__.py 2021-02-16 14:47:06.168327441 +0100 ++++ ckan/ckan/model/__init__.py 2021-02-16 14:48:00.740780218 +0100 +@@ -266,7 +266,7 @@ + self.reset_alembic_output() + alembic_config = AlembicConfig(self._alembic_ini) + alembic_config.set_main_option( +- "sqlalchemy.url", str(self.metadata.bind.url) ++ "sqlalchemy.url", str(self.metadata.bind.url).replace('%', '%%') + ) + try: + sqlalchemy_migrate_version = self.metadata.bind.execute( diff --git a/patches/01_patch_resource_replace_upload.patch b/patches/01_patch_resource_replace_upload.patch new file mode 100644 index 0000000..3f11fac --- /dev/null +++ b/patches/01_patch_resource_replace_upload.patch @@ -0,0 +1,11 @@ +--- ckan/ckan/logic/action/update.py 2021-02-17 16:46:55.673578728 +0100 ++++ ckan/ckan/logic/action/update-edit.py 2021-02-17 16:47:28.905879170 +0100 +@@ -929,7 +929,7 @@ + + ''' + model = context['model'] +- session = model.Session ++ session = model.meta.create_local_session() + context['session'] = session + + user = context['user'] diff --git a/patches/02_patch_postgres_username_split.patch b/patches/02_patch_postgres_username_split.patch new file mode 100644 index 0000000..780b432 --- /dev/null +++ b/patches/02_patch_postgres_username_split.patch @@ -0,0 +1,11 @@ +--- ckan/ckanext/datastore/backend/postgres.py 2021-02-18 11:01:56.692267462 +0100 ++++ ckan/ckanext/datastore/backend/postgres-patch.py 2021-02-18 13:45:16.033193435 +0100 +@@ -1690,7 +1690,7 @@ + read only user. + ''' + write_connection = self._get_write_engine().connect() +- read_connection_user = sa_url.make_url(self.read_url).username ++ read_connection_user = sa_url.make_url(self.read_url).username.split("@")[0] + + drop_foo_sql = u'DROP TABLE IF EXISTS _foo' + diff --git a/scripts/apply_ckan_patches.sh b/scripts/apply_ckan_patches.sh new file mode 100755 index 0000000..a7bceb9 --- /dev/null +++ b/scripts/apply_ckan_patches.sh @@ -0,0 +1,5 @@ +#!/bin/bash +shopt -s nullglob +for patch in patches/*.patch; do + /usr/bin/patch -p0 -i $patch +done