# Setting up Ed Testing Image Locally Documentation on running the Ed Testing image locally: https://github.com/datopian/dx-helm-ed-dev/blob/master/ckan/Dockerfile The images used for the [testing site](https://github.com/datopian/dx-helm-ed-dev/blob/master/ckan/Dockerfile) and the one used for [local development](https://github.com/CivicActions/docker-ckan-ed/blob/master/ckan/Dockerfile.dev) are slightly different and sometimes it may be easier to run the testing image locally. This document outlines the steps in doing that. The downside to this approach is that whenever a change is made to the `ckanext-ed` extension, the running container would have to be manually restarted to have those changes propagated to the local development portal. Besides that, everything else works really fine. ## Initial setup steps The steps in setting up the testing environment are not much, and the only major differences are the CKAN images, that would be used. * **Clone the `https://github.com/datopian/dx-helm-ed-dev` repo** The first step is to clone the [`dx-helm-ed-dev repo`](https://github.com/datopian/dx-helm-rvr-dev) locally. * **Build a base image from the testing image** A base image would be built locally from the [Dockerfile](https://github.com/datopian/dx-helm-ed-dev/blob/master/ckan/Dockerfile). Right before building the image, comment change [this line](https://github.com/datopian/dx-helm-ed-dev/blob/2b159bfd29698a98fdd82bde1774d65730f02074/ckan/Dockerfile#L103) in the Dockerfile: ```sh= ONBUILD RUN mkdir /docker-entrypoint.d ``` to ```sh= RUN mkdir /docker-entrypoint.d ``` or the new image would fail with this error: `mkdir: can't create directory '/docker-entrypoint.d': File exists` To build the image, navigate to the directory where the repo was cloned and run: ```sh= docker build -t local/ckan:2.9.5-ed-testing-base ckan ``` to build the image. The name `local/ckan:2.9.5-ed-testing-base` is arbitrary and any image name can be used to build the image locally. For the rest of this document we would assume the name `local/ckan:2.9.5-ed-testing-base` was used. * **Build the final image** In the parent directory where the **[ckanext-ed](https://github.com/CivicActions/ckanext-ed)** was cloned, create a `Dockerfile` with this configuration. if a different name for the base image was used, replace line 1 with the image name. ```Dockerfile= FROM local/ckan:2.9.5-ed-testing-base RUN mkdir /ckanext-ed RUN rm -rf ${SRC_DIR}/ckanext-ed RUN mkdir ${SRC_DIR}/ckanext-ed COPY ckanext-ed/bin ${SRC_DIR}/ckanext-ed/bin COPY ckanext-ed/ckanext ${SRC_DIR}/ckanext-ed/ckanext COPY ckanext-ed/deploy ${SRC_DIR}/ckanext-ed/deploy COPY ckanext-ed/requirements.txt ${SRC_DIR}/ckanext-ed/requirements.txt COPY ckanext-ed/setup.py ${SRC_DIR}/ckanext-ed/setup.py COPY ckanext-ed/test.ini ${SRC_DIR}/ckanext-ed/test.ini COPY ckanext-ed/setup.cfg ${SRC_DIR}/ckanext-ed/setup.cfg COPY ckanext-ed/README.md ${SRC_DIR}/ckanext-ed/README.md RUN pip2 install -e file://${SRC_DIR}/ckanext-ed#egg=ckanext-ed # ENV CKAN__PLUGINS envvars ed edharvest eddatajson eddatajsonharvest ed_sources geo_view geojson_view pdf_view ed_hierarchy_display ed_hierarchy_form documentation ed_collections ed_data_explorers ed_format_translator ed_resource_approval datastore resource_proxy deadoralive pages ed_stats ckan_harvester datajson_harvest showcase xloader googleanalytics # RUN ckan config-tool ${CKAN_INI} "ckan.plugins = ${CKAN__PLUGINS}" ``` Build this image with: ```sh= docker build -t local/ckan:2.9.5-ed-dev . ``` Once again, the `local/ckan:2.9.5-ed-dev` name is arbitrary and can be replaced with anything else. * **Setup Docker Compose** We would still be using the [`docker-ckan-ed`](https://github.com/CivicActions/docker-ckan-ed) repo to run the image, just with a few changes. Clone https://github.com/CivicActions/docker-ckan-ed if you haven't already and then create this `docker-compose.yml` file: ```yaml= version: "3" services: ckan-dev: container_name: ckan image: local/ckan:2.9.5-ed-dev env_file: - .dev.env links: - db - solr - redis ports: - "0.0.0.0:5000:5000" volumes: - ckan_storage:/var/lib/ckan networks: - frontend - backend depends_on: - db #datapusher: # container_name: datapusher # build: # context: datapusher/ # ports: # - "8800:8800" # networks: # - frontend # - backend db: container_name: db env_file: - .dev.env build: context: postgresql/ environment: - PGDATA=/var/lib/postgresql/data/db volumes: - pg_data:/var/lib/postgresql/data networks: - backend #solr: # container_name: solr # build: # context: solr/ solr: container_name: solr image: solr:8.11.1 networks: - backend env_file: - ./.dev.env environment: - CKAN_VERSION=2.9.5 - CKAN_CORE_NAME=ckan volumes: - solr_data:/var/solr - ${PWD}/solr8/ckan_init_solr.sh:/docker-entrypoint-initdb.d/ckan_init_solr.sh redis: container_name: redis image: redis:alpine networks: - backend ``` This is similar to the [`docker-compose.dev.yml` file](https://github.com/CivicActions/docker-ckan-ed/blob/master/docker-compose.dev.yml) except that we are running the `local/ckan:2.9.5-ed-dev` image we built instead. * **Run** Run: ```sh= docker-compose up --build ``` to run the containers. ## Developing with the testing image To develop the testing image, make the changes to the local clone of the **[ckanext-ed](https://github.com/CivicActions/ckanext-ed)** extension. Then rebuild the `local/ckan:2.9.5-ed-dev` image. This should take a few seconds. Restart the `docker-compose` and the changes made would be running on the local ckan instance. ## Use This is especially useful when you have to work on multiple projects and run multiple ckan docker images and volumes for each of them. Every project can have their own `docker-compose.yml` file and their own local images that can be run whenever the project is to be worked on.