## Creating First Ckan extension using docker-compose 1. ### Install ckan using docker compose i. clone okfn docker-ckan repository `git clone https://github.com/okfn/docker-ckan.git` ii. move into docker-ckan directory `cd docker-ckan` iii. copy env file `cp .env.example .env` iv. start ckan using docker-compose in development mode `docker-compose -f docker-compose.dev.yml up --build` v. Test that ckan is running successfully with the URL http://localhost:5000 2. ### Creating a ckan extension i. open another terminal and move into the okfn docker-ckan directory. ii. run the command to generate a ckan extension `docker-compose -f docker-compose.dev.yml exec ckan-dev /bin/bash -c "ckan generate extension --output-dir /srv/app/src_extensions"` iii. The command will present a few prompt will end up in the extension setup.py file **NB:** The first prompt is for the name of your ckan extension. CKAN extension names have to begin with `ckanext-` e.g `ckanext-helloword` 3. ### Creating our first plugin i. move into the src/ directory to see the created extension(ckanext-helloworld) and then locate `plugin.py` file inside the created extension(ckanext-helloworld) directory `cd src/` and then `cd ckanext-helloworld/ckanext/helloworld` ii. open the `plugin.py` file to create a simple ckan extension iii. Add the below code for simple ckan extension ``` import ckan.plugins as plugins import ckan.plugins.toolkit as toolkit from flask import Blueprint, render_template def hello_world(): '''A simple view function''' return "Hello World, this is my first ckan extension" class HellowordPlugin(plugins.SingletonPlugin): plugins.implements(plugins.IConfigurer) plugins.implements(plugins.IBlueprint) # IConfigurer def update_config(self, config_): toolkit.add_template_directory(config_, 'templates') toolkit.add_public_directory(config_, 'public') toolkit.add_resource('fanstatic', 'helloword_extension') #IBlueprint def get_blueprint(self): # Create Blueprint for plugin blueprint = Blueprint(self.name, self.__module__) blueprint.template_folder = 'templates' # Add plugin url rules to Blueprint object blueprint.add_url_rule( u'/hello_world', u'/hello_world', hello_world, methods=['GET'] ) return blueprint ``` 4. ### Adding our extension as a ckan plugin i. move back into docker-ckan directory `cd docker-ckan` ii. open the .env file iii. add our extension name to list of plugins in the .env file `CKAN__PLUGINS=envvars image_view text_view recline_view datastore datapusher helloworld` iv. Then restart docker-compose `docker-compose -f docker-compose.dev.yml up --build` v. Test and view your newly created extension with the URL http://localhost:5000/hello_world 5.