Skip to content

Commit da4651e

Browse files
feat: move readme from Jira to repo
1 parent 63b62e6 commit da4651e

2 files changed

Lines changed: 416 additions & 1 deletion

File tree

README.md

Lines changed: 292 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,292 @@
1-
Development environment for UNAIDS ADR. Setup instructions available here: https://fjelltopp.atlassian.net/wiki/spaces/ADR/pages/198377473/adx+develop+setup
1+
# adx_develop
2+
3+
Repository storing the development environment for The AIDS Data Repository.
4+
5+
## Linked Repositories
6+
7+
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.
8+
9+
## Requirements
10+
11+
Python Docker Docker-compose
12+
13+
## Setup
14+
15+
1. Create a directory to store the ADX development environment, then change directory into it e.g.
16+
17+
```shell
18+
mkdir -p ~/fjelltopp/adx
19+
cd ~/fjelltopp/adx
20+
```
21+
22+
2. Clone the `adx_develop` repo from Github into the directory
23+
24+
```shell
25+
git clone git@github.com:fjelltopp/adx_develop.git
26+
```
27+
28+
3. Initialize git submodules
29+
30+
```shell
31+
git submodule update --init
32+
# or
33+
adx init
34+
```
35+
36+
4. Add adr.local as localhost name to `/etc/hosts`. After the addition the file should look something like
37+
38+
```shell
39+
127.0.0.1 localhost
40+
127.0.0.1 adr.local
41+
```
42+
43+
5. Add a symlink to the dev env script from your $PATH:
44+
45+
```shell
46+
sudo ln -s `pwd`/adx_develop/adx /usr/local/bin/adx
47+
```
48+
49+
This shorthand script can now be used from anywhere in your file system to issue a command to the adx development environment. Run `adx -h` for more information.
50+
51+
6. Environment variables configuration: Clone the template `dev.env` file to `.env` where you can tweak the configuration:
52+
53+
```shell
54+
cp adx_develop/dev.env adx_develop/.env
55+
```
56+
57+
Things you need to update manually are:
58+
59+
- `ADX_PATH` to the path of the root directory containing adx_develop
60+
- `FJELLTOPP_PASSWORD=fjellt0pp-he@lth` for demo data loading scripts
61+
- `ADR_CKAN_SAML_IDP_CERT` to value from Fjelltopp development auth0 account [advanced settings](https://manage.auth0.com/dashboard/eu/hivtools/applications/lMiD8vQo1OZUPJEzd5hPvcxgTMkyY7YS/settings)
62+
63+
7. Setup the ADX code base.
64+
65+
```shell
66+
adx setup
67+
```
68+
69+
This command will initialize all git submodules, will reset all submodules to the development branch and will pull latest changes
70+
71+
8. Build and run the docker images as docker containers.
72+
73+
```shell
74+
adx up
75+
```
76+
77+
9. You can view the start up logs of the ckan container using the command:
78+
79+
```shell
80+
adx logs ckan
81+
```
82+
83+
You should watch the logs and wait until all the ckan extensions have been properly installed before continuing.
84+
85+
10. Do the initial CKAN configuration with:
86+
87+
```shell
88+
adx dbsetup
89+
```
90+
91+
Which initializes the db tables for extensions and creates the admin user.
92+
93+
Admin user:
94+
95+
```toml
96+
username: admin
97+
email: admin@fjelltopp.org
98+
password: fjellt0pp-he@lth
99+
```
100+
101+
The db should persist in a docker volume, so these commands will only need to be run again if you delete corresponding docker volume.
102+
103+
11. Then restart the ckan container:
104+
105+
```shell
106+
adx restart ckan
107+
```
108+
109+
12. [Optional] Adding demo data to CKAN instance with:
110+
111+
```shell
112+
adx demodata
113+
```
114+
115+
Demo data accounts all have password: fjellt0pp-he@lth
116+
117+
13. CKAN should be available at [http://adr.local/](http://adr.local/)
118+
119+
## Docker images for feature branches
120+
121+
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.)
122+
123+
In `.env` you can change the value of:
124+
125+
```env
126+
IMAGE_TAG=development
127+
CKAN_IMAGE_TAG=development
128+
```
129+
130+
to 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.
131+
132+
## Resetting the code base
133+
134+
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.
135+
136+
```shell
137+
adx setup
138+
# or the same using git command:
139+
git submodule foreach "git reset --hard || :"
140+
git submodule foreach "git checkout development|| :"
141+
git submodule foreach "git pull || :"
142+
```
143+
144+
## Using a fake SMTP server
145+
146+
We're using [rnwood/smtp4dev](https://github.com/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/](http://adr.local:5555/).
147+
148+
## Running CKAN tests locally
149+
150+
CKAN tests can be run in the development environment, but some setup is required.
151+
152+
To create and setup the test databases:
153+
154+
```shell
155+
adx testsetup
156+
```
157+
158+
Tests 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.
159+
160+
```shell
161+
adx test extension_name
162+
```
163+
164+
e.g.
165+
166+
```shell
167+
adx test restricted
168+
```
169+
170+
To run specific test case you can you -k pytest arg:
171+
172+
```shell
173+
adx test restricted -k test_regression_example
174+
```
175+
176+
To run the ckan core tests:
177+
178+
```shell
179+
docker exec -it ckan ckan-nosetests --ckan --with-pylons=/usr/lib/ckan/venv/src/ckan/test-core.ini ckan ckanext
180+
```
181+
182+
## Debugging with ipdb
183+
184+
You 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:
185+
186+
```python
187+
import ipdb; ipdb.set_trace()
188+
```
189+
190+
Start the dev env in detached mode as normal:
191+
192+
```shell
193+
adx up
194+
```
195+
196+
Then attach to ckan container:
197+
198+
```shell
199+
docker attach ckan
200+
```
201+
202+
When 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`.
203+
204+
See the [pdb docs](https://docs.python.org/3/library/pdb.html) and the [ipdb github](https://github.com/gotcha/ipdb) for more on how to debug with pdb/ipdb.
205+
206+
## Logs
207+
208+
To get more log output you can pick custom log level with -log, e.g.:
209+
210+
```shell
211+
adx --log info demodata
212+
```
213+
214+
## Translations
215+
216+
Please have a look at: [ADR Translations](./translations.md)
217+
218+
## Creating an extension
219+
220+
SSH into the container:
221+
222+
```shell
223+
adx bash ckan
224+
```
225+
226+
Create your extension:
227+
228+
```shell
229+
cd /usr/lib/adx
230+
ckan generate extension
231+
```
232+
233+
Exit the docker container and run:
234+
235+
```shell
236+
chmod -R 775 ckanext-hello_world
237+
chown -R 1000:1000 ckanext-hello_world
238+
```
239+
240+
Update the ckan config file:
241+
242+
- Open `adx_develop/ckan/adx_config.ini`
243+
- Find `ckan.plugins` and add `hello_world` to the beginning of the list
244+
245+
Add the entrypoint:
246+
247+
- Open `adx_develop/ckan/ckan-entrypoint-adx.sh`
248+
- Towards the bottom, add: `ckan-pip install --no-deps -e /usr/lib/adx/ckanext-hello_world`
249+
250+
Update the /adx_develop/ckan/Dockerfile with:
251+
252+
```shell
253+
COPY ./ckanext-hello_world/requirements.txt /usr/lib/ckan/hello_world-requirements.txt
254+
RUN ckan-pip install -r /usr/lib/ckan/hello_world-requirements.txt
255+
```
256+
257+
Test ckan builds:
258+
259+
```shell
260+
adx build ckan
261+
adx up
262+
adx logs ckan
263+
```
264+
265+
Now let's make the extension do something
266+
267+
- Create an `index.html` file in `ckanext-hello_world/ckanext/hello_world/templates/home`
268+
- Save `<h1>Hello World!</h1>` to it
269+
- Run another `adx build ckan; adx up` and your browser should display Hello World!
270+
- Read the [docs](https://docs.ckan.org/en/2.9/theming/templates.html#customizing-ckan-s-templates) for more info
271+
272+
## Setting up production deployments
273+
274+
Configure ADX_PATH env in your `.bashrc`, e.g.
275+
276+
```shell
277+
export ADX_PATH=$HOME/fjelltopp/adr
278+
```
279+
280+
Clone the following additional repos into your ADX_PATH:
281+
282+
```shell
283+
git clone git@github.com:fjelltopp/adx_deploy.git
284+
git clone git@github.com:fjelltopp/adx_manifest.git
285+
```
286+
287+
Now you should be able to use the following command to draft PRs for prod deployment
288+
Note: This only works with google chrome.
289+
290+
```shell
291+
adx deploy
292+
```

0 commit comments

Comments
 (0)