Skip to content

Commit

Permalink
Merge pull request #5 from NuCivic/civic-3300_basic_ahoy_setup
Browse files Browse the repository at this point in the history
Ahoy + Docker setup
  • Loading branch information
jacintocapote authored Jul 15, 2016
2 parents c1640f0 + aa76d3c commit b58cfa9
Show file tree
Hide file tree
Showing 12 changed files with 190 additions and 19 deletions.
9 changes: 9 additions & 0 deletions .ahoy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ahoyapi: v1
usage: DKAN cli app for development using ahoy.
commands:
docker:
usage: A series of docker commands (experimental)
import: .ahoy/docker.ahoy.yml
api:
usage:
import: .ahoy/api.ahoy.yml
1 change: 1 addition & 0 deletions .ahoy/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.dkan
43 changes: 43 additions & 0 deletions .ahoy/api.ahoy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
ahoyapi: v1
version: 0.0.0
commands:
dkan:
usage: Sets DKAN URI environment variable
cmd: |
FILE=".ahoy/.dkan"
if [ -f $FILE ]; then
cat $FILE
exit 0
else
echo "DKAN uri not set. Type it followed by [ENTER]:"
read URI
echo "$URI" > .ahoy/.dkan
exit 0
fi
python:
usage:
cmd: |
FILE=".ahoy/.dkan"
if [ ! -f $FILE ]; then
ahoy api dkan
fi
DKAN_URI=`cat $FILE`
ahoy docker compose run -e DKAN_URI=$DKAN_URI pydkan ipython {{args}}
prompt:
usage: Steps in the pydkan container
cmd: |
FILE=".ahoy/.dkan"
if [ ! -f $FILE ]; then
ahoy api dkan
fi
DKAN_URI=`cat $FILE`
ahoy docker compose run -e DKAN_URI=$DKAN_URI pydkan bash
tests:
usage: Runs nosetests
cmd: |
FILE=".ahoy/.dkan"
if [ ! -f $FILE ]; then
ahoy api dkan
fi
DKAN_URI=`cat $FILE`
ahoy docker compose run -e DKAN_URI=$DKAN_URI pydkan nosetests --verbose
57 changes: 57 additions & 0 deletions .ahoy/docker.ahoy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
ahoyapi: v1
version: 0.0.0
commands:
env:
cmd: |
cat << EOF
# To initialize your environment to use docker.
# Run: eval \$(ahoy docker env)
# OR
# Add the following to your ~/.bashrc
which docker || (echo "you don't seem to have docker installed. Exiting."; exit 1)
which docker-machine || (echo "you don't seem to have docker-machine installed. Exiting."; exit 1)
which docker-compose || (echo "you don't seem to have docker-compose installed. Exiting."; exit 1)
echo "Setting up docker environment"
export AHOY_CMD_PROXY=DOCKER
docker-machine start default
$(docker-machine env default)
ahoy docker build
EOF
usage: Outputs the commands needed to setup a docker environment.
stop:
cmd: "ahoy docker compose stop"
usage: Stop the docker-compose containers (non-destructive).
ps:
cmd: "ahoy docker compose ps"
usage: List the running docker-compose containers.
ip:
cmd: "docker-machine ip default"
usage: Show the ip address f the default docker machine VM
reset:
cmd: "ahoy docker compose stop && ahoy docker compose rm && ahoy docker compose up -d"
usage: Destroy and then restart the docker compose containers.
destroy:
cmd: "ahoy docker compose stop && ahoy docker compose rm"
usage: Destroy all the docker compose containers. (use before deleting folder)
build:
usage: Rebuild containers images
cmd: |
ahoy docker compose build {{args}}
compose:
usage: Abstraction for docker-compose
cmd: |
docker-compose -f docker-compose.yml -p "${PWD##*/}" {{args}}
cleanup:
usage: Clean ups docker unused images and volumes. See http://blog.yohanliyanage.com/2015/05/docker-clean-up-after-yourself/.
cmd: |
EXITED=`docker ps -a -q -f status=exited`
DANGLING=`docker images -f "dangling=true" -q`
if [ ! -z "$EXITED" ]
then
docker rm -v $EXITED
fi
if [ ! -z "$DANGLING" ]
then
docker rmi $DANGLING
fi
docker run -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/docker:/var/lib/docker --rm martin/docker-cleanup-volumes
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM python:2.7
ENV PYTHONUNBUFFERED 1
RUN DEBIAN_FRONTEND=noninteractive apt-get update && DEBIAN_FRONTEND=noninteractive apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN mkdir /opt/pydkan
WORKDIR /opt/pydkan
ADD requirements.txt /opt/pydkan/
RUN pip install -r requirements.txt
RUN pip install ipython
ENV PYTHONPATH=${PYTHONPATH:-/opt/pydkan/}
67 changes: 64 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,66 @@
This is the very beggining of a python client to interface with the [dkan_dataset_rest_api](https://github.com/NuCivic/dkan_dataset/tree/7.x-1.x/modules/dkan_dataset_rest_api) web service.
# PyDKAN

### Usage
This is a python client to interface with the [dkan_dataset_rest_api](https://github.com/NuCivic/dkan_dataset/tree/7.x-1.x/modules/dkan_dataset_rest_api) web service.

look inside the examples folder
## Installation

### As a Library

```bash
# To install the latest of the latest
$ pip install git+git://github.com/NuCivic/pydkan.git@master#egg=pydkan
# To install a release
$ pip install git+git://github.com/NuCivic/[email protected]#egg=pydkan
```

### For development with docker and ahoy

+ Install docker
+ Install ahoy (See https://github.com/devinci-code/ahoy#installation)
+ Run the following:

```
$ ahoy docker build
```

That's it.

## Usage

### As a library

Check the examples folder, there are snippets for pretty much everything you can do with this library.

### Docker + Ahoy setup

#### Prompt into a container with the dev environment

```
ahoy api prompt
```

#### Prompt into an ipython console:

```
ahoy api python
```

#### Run a script

```
ahoy api python examples/list_nodes.py
```

#### Run the testsuite

````
ahoy api tests
````

#### Rebuild the image

From time to time you'll need to rebuild the docker image. For instance, if you add a requirement to the requirements.txt file and you'll need it installed. Yoy can do that by:

```
ahoy docker build --no-cache
```
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pydkan:
build: ./
volumes:
- ".:/opt/pydkan"
6 changes: 2 additions & 4 deletions examples/attach_file_to_node.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import sys
sys.path.append('..')

import os
import json
from dkan.client import DatasetAPI
Expand All @@ -15,7 +12,8 @@
nodes = api.node(params=payload).json()
resource = nodes[0]
print resource
csv = os.path.join('.', 'data', 'tension_sample_data.csv')
csv = os.path.join(os.path.dirname(os.path.abspath(__file__)), '.',
'data', 'tension_sample_data.csv')
# Attach the file to the resource node
r = api.attach_file_to_node(csv, resource['nid'], 'field_upload')
print r.status_code
Expand Down
3 changes: 0 additions & 3 deletions examples/create_node.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import sys
sys.path.append('..')

import os
import json
from dkan.client import DatasetAPI
Expand Down
3 changes: 0 additions & 3 deletions examples/delete_node.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import sys
sys.path.append('..')

import os
import json
from dkan.client import DatasetAPI
Expand Down
3 changes: 0 additions & 3 deletions examples/list_nodes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import sys
sys.path.append('..')

import os
import json
from dkan.client import DatasetAPI
Expand Down
3 changes: 0 additions & 3 deletions examples/update_node.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import sys
sys.path.append('..')

import os
import json
from dkan.client import DatasetAPI
Expand Down

0 comments on commit b58cfa9

Please sign in to comment.