From 445d52555de0567d7b9f40e53ba2621ec2494598 Mon Sep 17 00:00:00 2001 From: Ian Ward Date: Mon, 22 Apr 2024 14:11:26 -0400 Subject: [PATCH 1/9] remove container names --- .env.example | 9 --------- docker-compose.yml | 6 ------ 2 files changed, 15 deletions(-) diff --git a/.env.example b/.env.example index 3508b6e..b5760c2 100644 --- a/.env.example +++ b/.env.example @@ -1,12 +1,3 @@ -# Container names -NGINX_CONTAINER_NAME=nginx -REDIS_CONTAINER_NAME=redis -POSTGRESQL_CONTAINER_NAME=db -SOLR_CONTAINER_NAME=solr -DATAPUSHER_CONTAINER_NAME=datapusher -CKAN_CONTAINER_NAME=ckan -WORKER_CONTAINER_NAME=ckan-worker - # Host Ports CKAN_PORT_HOST=5000 NGINX_PORT_HOST=81 diff --git a/docker-compose.yml b/docker-compose.yml index 0f5330f..4f004d7 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,7 +9,6 @@ volumes: services: nginx: - container_name: ${NGINX_CONTAINER_NAME} build: context: nginx/ dockerfile: Dockerfile @@ -23,7 +22,6 @@ services: - "0.0.0.0:${NGINX_SSLPORT_HOST}:${NGINX_SSLPORT}" ckan: - container_name: ${CKAN_CONTAINER_NAME} build: context: ckan/ dockerfile: Dockerfile @@ -50,7 +48,6 @@ services: test: ["CMD", "wget", "-qO", "/dev/null", "http://localhost:5000"] datapusher: - container_name: ${DATAPUSHER_CONTAINER_NAME} networks: - ckannet - dbnet @@ -60,7 +57,6 @@ services: test: ["CMD", "wget", "-qO", "/dev/null", "http://localhost:8800"] db: - container_name: ${POSTGRESQL_CONTAINER_NAME} build: context: postgresql/ networks: @@ -82,7 +78,6 @@ services: test: ["CMD", "pg_isready", "-U", "${POSTGRES_USER}", "-d", "${POSTGRES_DB}"] solr: - container_name: ${SOLR_CONTAINER_NAME} networks: - solrnet image: ckan/ckan-solr:${SOLR_IMAGE_VERSION} @@ -93,7 +88,6 @@ services: test: ["CMD", "wget", "-qO", "/dev/null", "http://localhost:8983/solr/"] redis: - container_name: ${REDIS_CONTAINER_NAME} image: redis:${REDIS_VERSION} networks: - redisnet From 32af5cfbf8d1c81fd7e309d158117445067a8f13 Mon Sep 17 00:00:00 2001 From: Ian Ward Date: Tue, 23 Apr 2024 16:29:18 -0400 Subject: [PATCH 2/9] fix readme toc, headings, replace one screenshot of text --- README.md | 76 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 42 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 5f689cc..79cdceb 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,25 @@ # Docker Compose setup for CKAN -* [Overview](#overview) -* [Installing Docker](#installing-docker) -* [docker compose vs docker-compose](#docker-compose-vs-docker-compose) -* [Install CKAN plus dependencies](#install-ckan-plus-dependencies) -* [Development mode](#development-mode) - * [Create an extension](#create-an-extension) - * [Running HTTPS on development mode](#running-https-on-development-mode) -* [CKAN images](#ckan-images) - * [Extending the base images](#extending-the-base-images) - * [Applying patches](#applying-patches) -* [Debugging with pdb](#pdb) -* [Datastore and Datapusher](#Datastore-and-datapusher) -* [NGINX](#nginx) -* [The ckanext-envvars extension](#envvars) -* [The CKAN_SITE_URL parameter](#CKAN_SITE_URL) -* [Changing the base image](#Changing-the-base-image) -* [Replacing DataPusher with XLoader](#Replacing-DataPusher-with-XLoader) +* [1. Overview](#1--overview) +* [2. Installing Docker](#2--installing-docker) +* [3. docker compose vs docker-compose](#3--docker-compose-vs-docker-compose) +* [4. Install (build and run) CKAN plus dependencies](#4--install-build-and-run-ckan-plus-dependencies) + * [Base mode](#base-mode) + * [Development mode](#development-mode) + * [Create an extension](#create-an-extension) + * [Running HTTPS on development mode](#running-https-on-development-mode) +* [5. CKAN images](#5--ckan-images) + * [Extending the base images](#extending-the-base-images) + * [Applying patches](#applying-patches) +* [6. Debugging with pdb](#6--debugging-with-pdb) +* [7. Datastore and Datapusher](#7--datastore-and-datapusher) +* [8. NGINX](#8--nginx) +* [9. ckanext-envvars](#9--ckanext-envvars) +* [10. CKAN_SITE_URL](#10--CKAN_SITE_URL) +* [11. Manage new users](#11-manage-new-users) +* [12. Changing the base image](#12--changing-the-base-image) +* [13. Replacing DataPusher with XLoader](#13--replacing-datapusher-with-xLoader) ## 1. Overview @@ -51,14 +53,14 @@ more information. ## 4. Install (build and run) CKAN plus dependencies -#### Base mode +### Base mode Use this if you are a maintainer and will not be making code changes to CKAN or to CKAN extensions Copy the included `.env.example` and rename it to `.env`. Modify it depending on your own needs. Please note that when accessing CKAN directly (via a browser) ie: not going through 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 +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` Using the default values on the `.env.example` 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. @@ -81,7 +83,7 @@ At the end of the container start sequence there should be 6 containers running After this step, CKAN should be running at `CKAN_SITE_URL`. -#### Development mode +### Development mode Use this mode if you are making code changes to CKAN and either creating new extensions or making code changes to existing extensions. This mode also uses the `.env` file for config options. @@ -95,10 +97,10 @@ To start the containers: docker compose -f docker-compose.dev.yml up -See [CKAN Images](#ckan-images) for more details of what happens when using development mode. +See [CKAN Images](#5--ckan-images) for more details of what happens when using development mode. -##### Create an extension +#### Create an extension You can use the ckan [extension](https://docs.ckan.org/en/latest/extensions/tutorial.html#creating-a-new-extension) instructions to create a CKAN extension, only executing the command inside the CKAN container and setting the mounted `src/` folder as output: @@ -109,7 +111,7 @@ You can use the ckan [extension](https://docs.ckan.org/en/latest/extensions/tuto The new extension files and directories are created in the `/srv/app/src_extensions/` folder in the running container. They will also exist in the local src/ directory as local `/src` directory is mounted as `/srv/app/src_extensions/` on the ckan container. You might need to change the owner of its folder to have the appropiate permissions. -##### Running HTTPS on development mode +#### Running HTTPS on development mode Sometimes is useful to run your local development instance under HTTPS, for instance if you are using authentication extensions like [ckanext-saml2auth](https://github.com/keitaroinc/ckanext-saml2auth). To enable it, set the following in your `.env` file: @@ -138,7 +140,7 @@ The Docker image config files used to build your CKAN project are located in the * Any custom changes to the scripts run during container start up can be made to scripts in the `setup/` directory. For instance if you wanted to change the port on which CKAN runs you would need to make changes to the Docker Compose yaml file, and the `start_ckan.sh.override` file. Then you would need to add the following line to the Dockerfile ie: `COPY setup/start_ckan.sh.override ${APP_DIR}/start_ckan.sh`. The `start_ckan.sh` file in the locally built image would override the `start_ckan.sh` file included in the base image -## 6. Extending the base images +### 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:` @@ -177,7 +179,7 @@ COPY docker-entrypoint.d/* /docker-entrypoint.d/ NB: There are a number of extension examples commented out in the Dockerfile.dev file -## 7. Applying patches +### Applying patches When building your project specific CKAN images (the ones defined in the `ckan/` folder), you can apply patches to CKAN core or any of the built extensions. To do so create a folder inside `ckan/patches` with the name of the @@ -201,22 +203,28 @@ ckan ``` -## 8. pdb +## 6. Debugging with pdb Add these lines to the `ckan-dev` service in the docker-compose.dev.yml file -![pdb](https://user-images.githubusercontent.com/54408245/179964232-9e98a451-5fe9-4842-ba9b-751bcc627730.png) +```yaml +ports: + - "0.0.0.0:${CKAN_PORT}:5000" + +stdin_open: true +tty: true +``` Debug with pdb (example) - Interact with `docker attach $(docker container ls -qf name=ckan)` command: `python -m pdb /usr/lib/ckan/venv/bin/ckan --config /srv/app/ckan.ini run --host 0.0.0.0 --passthrough-errors` -## 9. Datastore and datapusher +## 7. Datastore and datapusher The Datastore database and user is created as part of the entrypoint scripts for the db container. There is also a Datapusher container running the latest version of Datapusher. -## 10. NGINX +## 8. NGINX The base Docker Compose configuration uses an NGINX image as the front-end (ie: reverse proxy). It includes HTTPS running on port number 8443. A "self-signed" SSL certificate is generated as part of the ENTRYPOINT. The NGINX `server_name` directive and the `CN` field in the SSL certificate have been both set to 'localhost'. This should obviously not be used for production. @@ -224,7 +232,7 @@ Creating the SSL cert and key files as follows: `openssl req -new -newkey rsa:4096 -days 365 -nodes -x509 -subj "/C=DE/ST=Berlin/L=Berlin/O=None/CN=localhost" -keyout ckan-local.key -out ckan-local.crt` The `ckan-local.*` files will then need to be moved into the nginx/setup/ directory -## 11. envvars +## 9. ckanext-envvars The ckanext-envvars extension is used in the CKAN Docker base repo to build the base images. This extension checks for environmental variables conforming to an expected format and updates the corresponding CKAN config settings with its value. @@ -245,11 +253,11 @@ These parameters can be added to the `.env` file For more information please see [ckanext-envvars](https://github.com/okfn/ckanext-envvars) -## 12. CKAN_SITE_URL +## 10. CKAN_SITE_URL For convenience the CKAN_SITE_URL parameter should be set in the .env file. For development it can be set to http://localhost:5000 and non-development set to https://localhost:8443 -## 13. Manage new users +## 11. Manage new users 1. Create a new user from the Docker host, for example to create a new user called 'admin' @@ -267,12 +275,12 @@ For convenience the CKAN_SITE_URL parameter should be set in the .env file. For `ckan -c ckan.ini user remove admin` -## 14. Changing the base image +## 12. Changing the base image The base image used in the CKAN Dockerfile and Dockerfile.dev can be changed so a different DockerHub image is used eg: ckan/ckan-base:2.9.9 could be used instead of ckan/ckan-base:2.10.1 -## 15. Replacing DataPusher with XLoader +## 13. Replacing DataPusher with XLoader Check out the wiki page for this: https://github.com/ckan/ckan-docker/wiki/Replacing-DataPusher-with-XLoader From 5c550f4cd1503d2ff1221466169f8f0b24c47ef3 Mon Sep 17 00:00:00 2001 From: Ian Ward Date: Tue, 23 Apr 2024 16:34:00 -0400 Subject: [PATCH 3/9] now only one dash --- README.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 79cdceb..7eecac3 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,25 @@ # Docker Compose setup for CKAN -* [1. Overview](#1--overview) -* [2. Installing Docker](#2--installing-docker) -* [3. docker compose vs docker-compose](#3--docker-compose-vs-docker-compose) -* [4. Install (build and run) CKAN plus dependencies](#4--install-build-and-run-ckan-plus-dependencies) +* [1. Overview](#1-overview) +* [2. Installing Docker](#2-installing-docker) +* [3. docker compose vs docker-compose](#3-docker-compose-vs-docker-compose) +* [4. Install (build and run) CKAN plus dependencies](#4-install-build-and-run-ckan-plus-dependencies) * [Base mode](#base-mode) * [Development mode](#development-mode) * [Create an extension](#create-an-extension) * [Running HTTPS on development mode](#running-https-on-development-mode) -* [5. CKAN images](#5--ckan-images) +* [5. CKAN images](#5-ckan-images) * [Extending the base images](#extending-the-base-images) * [Applying patches](#applying-patches) -* [6. Debugging with pdb](#6--debugging-with-pdb) -* [7. Datastore and Datapusher](#7--datastore-and-datapusher) -* [8. NGINX](#8--nginx) -* [9. ckanext-envvars](#9--ckanext-envvars) -* [10. CKAN_SITE_URL](#10--CKAN_SITE_URL) +* [6. Debugging with pdb](#6-debugging-with-pdb) +* [7. Datastore and Datapusher](#7-datastore-and-datapusher) +* [8. NGINX](#8-nginx) +* [9. ckanext-envvars](#9-ckanext-envvars) +* [10. CKAN_SITE_URL](#10-CKAN_SITE_URL) * [11. Manage new users](#11-manage-new-users) -* [12. Changing the base image](#12--changing-the-base-image) -* [13. Replacing DataPusher with XLoader](#13--replacing-datapusher-with-xLoader) +* [12. Changing the base image](#12-changing-the-base-image) +* [13. Replacing DataPusher with XLoader](#13-replacing-datapusher-with-xLoader) ## 1. Overview From 72eade8ccad2eb2275af5f2bf52ed5ed74dc1b44 Mon Sep 17 00:00:00 2001 From: Ian Ward Date: Tue, 23 Apr 2024 16:40:11 -0400 Subject: [PATCH 4/9] link to base images repo --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7eecac3..da7b817 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ To start the containers: docker compose -f docker-compose.dev.yml up -See [CKAN Images](#5--ckan-images) for more details of what happens when using development mode. +See [CKAN images](#5-ckan-images) for more details of what happens when using development mode. #### Create an extension @@ -142,6 +142,8 @@ The Docker image config files used to build your CKAN project are located in the ### Extending the base images +The CKAN base images are built from https://github.com/ckan/ckan-docker-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:` 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. From f4e152855fc6f32e743457d5f9ff1c49be3ca083 Mon Sep 17 00:00:00 2001 From: Ian Ward Date: Tue, 23 Apr 2024 17:16:59 -0400 Subject: [PATCH 5/9] compose version is no longer used https://github.com/compose-spec/compose-spec/blob/master/spec.md#version-and-name-top-level-elements --- docker-compose.dev.yml | 2 -- docker-compose.yml | 3 --- 2 files changed, 5 deletions(-) diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index dc2ecdf..e41d0ee 100755 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -1,5 +1,3 @@ -version: "3" - volumes: ckan_storage: pg_data: diff --git a/docker-compose.yml b/docker-compose.yml index 4f004d7..d37c8ef 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,3 @@ -version: "3" - - volumes: ckan_storage: pg_data: From eee098b9280c97961f786da4e459c1ea323cb181 Mon Sep 17 00:00:00 2001 From: Ian Ward Date: Tue, 23 Apr 2024 17:25:17 -0400 Subject: [PATCH 6/9] default datatables plugin instead of recline --- .env.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.example b/.env.example index b5760c2..830cf94 100644 --- a/.env.example +++ b/.env.example @@ -69,7 +69,7 @@ NGINX_PORT=80 NGINX_SSLPORT=443 # Extensions -CKAN__PLUGINS="envvars image_view text_view recline_view datastore datapusher" +CKAN__PLUGINS="envvars image_view text_view datatables_view datastore datapusher" CKAN__HARVEST__MQ__TYPE=redis CKAN__HARVEST__MQ__HOSTNAME=redis CKAN__HARVEST__MQ__PORT=6379 From 726d586ffbd7c3ab5ccdde24a2b9abd7fad14753 Mon Sep 17 00:00:00 2001 From: Ian Ward Date: Tue, 23 Apr 2024 18:39:45 -0400 Subject: [PATCH 7/9] start dev ckan in parallel --- docker-compose.dev.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index dc2ecdf..7f526ed 100755 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -15,13 +15,6 @@ services: - TZ=${TZ} env_file: - .env - depends_on: - db: - condition: service_healthy - solr: - condition: service_healthy - redis: - condition: service_healthy ports: - "0.0.0.0:${CKAN_PORT_HOST}:${CKAN_PORT}" volumes: From fcd9648e699e88f62fed0204c646afc988c006d3 Mon Sep 17 00:00:00 2001 From: Ian Ward Date: Wed, 24 Apr 2024 16:59:01 -0400 Subject: [PATCH 8/9] volumes for installed files for faster startup --- docker-compose.dev.yml | 2 ++ docker-compose.yml | 1 + 2 files changed, 3 insertions(+) diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index dc2ecdf..7d3831a 100755 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -27,6 +27,8 @@ services: volumes: - ckan_storage:/var/lib/ckan - ./src:/srv/app/src_extensions + - /usr/lib/python3.10/site-packages + - /root/.vscode-server restart: unless-stopped healthcheck: test: ["CMD", "wget", "-qO", "/dev/null", "http://localhost:5000"] diff --git a/docker-compose.yml b/docker-compose.yml index 4f004d7..d241a83 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -43,6 +43,7 @@ services: condition: service_healthy volumes: - ckan_storage:/var/lib/ckan + - /usr/lib/python3.10/site-packages restart: unless-stopped healthcheck: test: ["CMD", "wget", "-qO", "/dev/null", "http://localhost:5000"] From 275a9374a7f152b79babe6b7f27709d10fac1d8a Mon Sep 17 00:00:00 2001 From: Ian Ward Date: Wed, 24 Apr 2024 17:34:38 -0400 Subject: [PATCH 9/9] document debugpy option --- README.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/README.md b/README.md index da7b817..7e4fde8 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ * [Development mode](#development-mode) * [Create an extension](#create-an-extension) * [Running HTTPS on development mode](#running-https-on-development-mode) + * [Remote Debugging with VS Code](#remote-debugging-with-vs-code) * [5. CKAN images](#5-ckan-images) * [Extending the base images](#extending-the-base-images) * [Applying patches](#applying-patches) @@ -115,15 +116,42 @@ The new extension files and directories are created in the `/srv/app/src_extensi Sometimes is useful to run your local development instance under HTTPS, for instance if you are using authentication extensions like [ckanext-saml2auth](https://github.com/keitaroinc/ckanext-saml2auth). To enable it, set the following in your `.env` file: +``` USE_HTTPS_FOR_DEV=true +``` and update the site URL setting: +``` CKAN_SITE_URL=https://localhost:5000 +``` After recreating the `ckan-dev` container, you should be able to access CKAN at https://localhost:5000 +#### Remote Debugging with VS Code + +[Visual Studio Code](https://code.visualstudio.com/) is a free IDE that includes remote +debugging for Python applications. To debug CKAN you must enable `debugpy` for your +development instance in your `.env` file: + +``` + USE_DEBUGPY_FOR_DEV=true +``` + +Then start the containers in [development mode](#development-mode) and launch VS Code. + +In VS Code: + +1. Install the "Dev Container" extension: press CTRL+SHIFT+X, type "dev container", click "install" +2. Click the "Open a Remote Window" button in the bottom-left of the VS Code window +3. Click "Attach to Running Container..." and select your ckan-dev container, e.g. "ckan-docker-ckan-dev-1" +4. Click the "Run and Debug" icon on the left panel then "create a launch.json", select "Python Debugger", "Remote Attach", host "localhost" and port "5678" +5. Press F5 or click the "Run" menu and "Start Debugging" + +You can now set breakpoints and remote debug your CKAN development instance. + + ## 5. CKAN images ![ckan images](https://user-images.githubusercontent.com/54408245/207079416-a01235af-2dea-4425-b6fd-f8c3687dd993.png)