Repository storing the development environment for The AIDS Data Repository.
Setting up the ADX development environment locally will clone a collection of different Github repos set as submodules to the adx_develop repository. They’re located in adx_develop/submodules directory.
Python Docker Docker-compose
-
Create a directory to store the ADX development environment, then change directory into it e.g.
mkdir -p ~/fjelltopp/adx cd ~/fjelltopp/adx
-
Clone the
adx_developrepo from Github into the directorygit clone git@github.com:fjelltopp/adx_develop.git
-
Initialize git submodules
git submodule update --init # or adx init -
Add adr.local as localhost name to
/etc/hosts. After the addition the file should look something like127.0.0.1 localhost 127.0.0.1 adr.local
-
Add a symlink to the dev env script from your $PATH:
sudo ln -s `pwd`/adx_develop/adx /usr/local/bin/adxThis shorthand script can now be used from anywhere in your file system to issue a command to the adx development environment. Run
adx -hfor more information. -
Environment variables configuration: Clone the template
dev.envfile to.envwhere you can tweak the configuration:cp adx_develop/dev.env adx_develop/.env
Things you need to update manually are:
ADX_PATHto the path of the root directory containing adx_developFJELLTOPP_PASSWORD=fjellt0pp-he@lthfor demo data loading scriptsADR_CKAN_SAML_IDP_CERTto value from Fjelltopp development auth0 account advanced settings
-
Setup the ADX code base.
adx setup
This command will initialize all git submodules, will reset all submodules to the development branch and will pull latest changes
-
Build and run the docker images as docker containers.
adx up
-
You can view the start up logs of the ckan container using the command:
adx logs ckan
You should watch the logs and wait until all the ckan extensions have been properly installed before continuing.
-
Do the initial CKAN configuration with:
adx dbsetup
Which initializes the db tables for extensions and creates the admin user.
Admin user:
username: admin email: admin@fjelltopp.org password: fjellt0pp-he@lth
The db should persist in a docker volume, so these commands will only need to be run again if you delete corresponding docker volume.
-
Then restart the ckan container:
adx restart ckan
-
[Optional] Adding demo data to CKAN instance with:
adx demodata
Demo data accounts all have password: fjellt0pp-he@lth
-
CKAN should be available at http://adr.local/
New feature which require changes to docker images can create problems when switching from feature-branch work back to development (to work on important bug fixes, reviewing PRs etc.)
In .env you can change the value of:
IMAGE_TAG=development
CKAN_IMAGE_TAG=developmentto a custom value representing your feature branch, e.g. 'versioning' to be able to quickly switch between different ADR versions. That way after switching to a different git branch you won't have to rebuild all of the images. CKAN_IMAGE_TAG is used to test custom CKAN containers if any changes have been made to ./ckan/ directory.
The adx script comes with a convienience command forall that enables you to quickly replicate commands across multiple repos. The command can be used to reset your code base once everything you want to keep is committed and ideally pushed.
adx setup
# or the same using git command:
git submodule foreach "git reset --hard || :"
git submodule foreach "git checkout development|| :"
git submodule foreach "git pull || :"We're using rnwood/smtp4dev to "fake" an SMTP service, it's deployed as part of docker compose - smtp container. It catches all the emails sent to it, accepts any credentials. Emails can be viewed via a web console available at port 5555, so if your local environment uses "adr.local" as a host name you can access at http://adr.local:5555/.
CKAN tests can be run in the development environment, but some setup is required.
To create and setup the test databases:
adx testsetupTests should be run with the version of nosetests-2.7 installed in CKAN's virtual environment. There is an alias set up inside the docker container called "ckan-nosetests" that points to this executable.
adx test extension_namee.g.
adx test restrictedTo run specific test case you can you -k pytest arg:
adx test restricted -k test_regression_exampleTo run the ckan core tests:
docker exec -it ckan ckan-nosetests --ckan --with-pylons=/usr/lib/ckan/venv/src/ckan/test-core.ini ckan ckanextYou can debug the adx using the python debugger (pdb), or the improved interactive python debugger (ipdb). To do this set a break point as normal anywhere in the code:
import ipdb; ipdb.set_trace()Start the dev env in detached mode as normal:
adx upThen attach to ckan container:
docker attach ckanWhen your code hits the breakpoint it will open an interactive ipdb prompt. When you are finished you can detach from the container, without killing it, using the escape sequence: ctrl-p then ctrl-q.
See the pdb docs and the ipdb github for more on how to debug with pdb/ipdb.
To get more log output you can pick custom log level with -log, e.g.:
adx --log info demodataPlease have a look at: ADR Translations
SSH into the container:
adx bash ckanCreate your extension:
cd /usr/lib/adx
ckan generate extensionExit the docker container and run:
chmod -R 775 ckanext-hello_world
chown -R 1000:1000 ckanext-hello_worldUpdate the ckan config file:
- Open
adx_develop/ckan/adx_config.ini - Find
ckan.pluginsand addhello_worldto the beginning of the list
Add the entrypoint:
- Open
adx_develop/ckan/ckan-entrypoint-adx.sh - Towards the bottom, add:
ckan-pip install --no-deps -e /usr/lib/adx/ckanext-hello_world
Update the /adx_develop/ckan/Dockerfile with:
COPY ./ckanext-hello_world/requirements.txt /usr/lib/ckan/hello_world-requirements.txt
RUN ckan-pip install -r /usr/lib/ckan/hello_world-requirements.txtTest ckan builds:
adx build ckan
adx up
adx logs ckanNow let's make the extension do something
- Create an
index.htmlfile inckanext-hello_world/ckanext/hello_world/templates/home - Save
<h1>Hello World!</h1>to it - Run another
adx build ckan; adx upand your browser should display Hello World! - Read the docs for more info
Configure ADX_PATH env in your .bashrc, e.g.
export ADX_PATH=$HOME/fjelltopp/adrClone the following additional repos into your ADX_PATH:
git clone git@github.com:fjelltopp/adx_deploy.git
git clone git@github.com:fjelltopp/adx_manifest.gitNow you should be able to use the following command to draft PRs for prod deployment Note: This only works with google chrome.
adx deploy